diff options
author | Elie Tournier <[email protected]> | 2017-08-09 17:39:23 +0100 |
---|---|---|
committer | Matt Turner <[email protected]> | 2019-01-09 16:42:40 -0800 |
commit | f499942b31aece4e2eefcef7c5b94dea5601055b (patch) | |
tree | 67155fff66ebdd9eeb131630bdec293f00818008 /src/compiler | |
parent | 773190f2816b77f815b7503ccd984daa81480bec (diff) |
glsl: Add "built-in" functions to do int_to_fp64(int)
v2: use mix
Signed-off-by: Elie Tournier <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/glsl/float64.glsl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index 72fbefd2eff..ee87632afe3 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -921,3 +921,26 @@ __fp64_to_int(uint64_t a) int nan = mix(0x7FFFFFFF, 0x80000000, bool(aSign)); return mix(z, nan, bool(aSign ^ uint(z < 0)) && bool(z)); } + +/* Returns the result of converting the 32-bit two's complement integer `a' + * to the double-precision floating-point format. The conversion is performed + * according to the IEEE Standard for Floating-Point Arithmetic. + */ +uint64_t +__int_to_fp64(int a) +{ + uint zFrac0 = 0u; + uint zFrac1 = 0u; + if (a==0) + return __packFloat64(0u, 0, 0u, 0u); + uint zSign = uint(a < 0); + uint absA = mix(uint(a), uint(-a), a < 0); + int shiftCount = __countLeadingZeros32(absA) - 11; + if (0 <= shiftCount) { + zFrac0 = absA << shiftCount; + zFrac1 = 0u; + } else { + __shift64Right(absA, 0u, -shiftCount, zFrac0, zFrac1); + } + return __packFloat64(zSign, 0x412 - shiftCount, zFrac0, zFrac1); +} |