aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorSagar Ghuge <[email protected]>2018-12-05 22:37:18 -0800
committerMatt Turner <[email protected]>2019-01-09 16:42:40 -0800
commitc9d333a6b76e27bda48efee35da53afba2dc191c (patch)
tree1590aaeb79a3643459564c327471efceebaaab0e /src/compiler
parentd5cf6e92b4f76e55b2b9013b1332ead34881858f (diff)
glsl: Add "built-in" functions to do int64_to_fp32(int64_t)
Reviewed-by: Elie Tournier <[email protected]> Signed-off-by: Sagar Ghuge <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/glsl/float64.glsl22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
index da805131dc3..6a763ffdab0 100644
--- a/src/compiler/glsl/float64.glsl
+++ b/src/compiler/glsl/float64.glsl
@@ -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.
*/