glsl: Add "built-in" functions to do int64_to_fp32(int64_t)
authorSagar Ghuge <sagar.ghuge@intel.com>
Thu, 6 Dec 2018 06:37:18 +0000 (22:37 -0800)
committerMatt Turner <mattst88@gmail.com>
Thu, 10 Jan 2019 00:42:40 +0000 (16:42 -0800)
Reviewed-by: Elie Tournier <tournier.elie@gmail.com>
Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
src/compiler/glsl/float64.glsl

index da805131dc3d84e4a86a96f294f0b5b339ff5a82..6a763ffdab04a6c447b7a61eaf07b47b051f7619 100644 (file)
@@ -1120,6 +1120,28 @@ __uint64_to_fp32(uint64_t __a)
    return __roundAndPackFloat32(0u, 0x9C - shiftCount, zFrac);
 }
 
+float
+__int64_to_fp32(int64_t __a)
+{
+   uint zFrac = 0u;
+   uint aSign = uint(__a < 0);
+   uint64_t absA = mix(uint64_t(__a), uint64_t(-__a), __a < 0);
+   uvec2 aFrac = unpackUint2x32(absA);
+   int shiftCount = __countLeadingZeros32(mix(aFrac.y, aFrac.x, aFrac.y == 0u));
+   shiftCount -= mix(40, 8, aFrac.y == 0u);
+
+   if (0 <= shiftCount) {
+      __shortShift64Left(aFrac.y, aFrac.x, shiftCount, aFrac.y, aFrac.x);
+      bool is_zero = (aFrac.y | aFrac.x) == 0u;
+      return mix(__packFloat32(aSign, 0x95 - shiftCount, aFrac.x), 0, absA == 0u);
+   }
+
+   shiftCount += 7;
+   __shift64RightJamming(aFrac.y, aFrac.x, -shiftCount, aFrac.y, aFrac.x);
+   zFrac = mix(aFrac.x<<shiftCount, aFrac.x, shiftCount < 0);
+   return __roundAndPackFloat32(aSign, 0x9C - shiftCount, zFrac);
+}
+
 /* Returns the result of converting the single-precision floating-point value
  * `a' to the double-precision floating-point format.
  */