glsl: Add "built-in" functions to do uint64_to_fp64(uint64_t)
authorSagar Ghuge <sagar.ghuge@intel.com>
Fri, 30 Nov 2018 19:50:44 +0000 (11:50 -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 1808fec07277290ed3d78fd33cf881a34cf88f6f..ac6d6221a64cb41318155c2ddf08dcc9f98c980e 100644 (file)
@@ -887,6 +887,24 @@ __uint_to_fp64(uint a)
    return __packFloat64(0u, 0x432 - shiftDist, aHigh, aLow);
 }
 
+uint64_t
+__uint64_to_fp64(uint64_t a)
+{
+   if (a == 0u)
+      return 0ul;
+
+   uvec2 aFrac = unpackUint2x32(a);
+   uint aFracLo = __extractFloat64FracLo(a);
+   uint aFracHi = __extractFloat64FracHi(a);
+
+   if ((aFracHi & 0x80000000u) != 0u) {
+      __shift64RightJamming(aFracHi, aFracLo, 1, aFracHi, aFracLo);
+      return __roundAndPackFloat64(0, 0x433, aFracHi, aFracLo, 0u);
+   } else {
+      return __normalizeRoundAndPackFloat64(0, 0x432, aFrac.y, aFrac.x);
+   }
+}
+
 /* Returns the result of converting the double-precision floating-point value
  * `a' to the 32-bit two's complement integer format.  The conversion is
  * performed according to the IEEE Standard for Floating-Point Arithmetic---