diff options
author | Sagar Ghuge <[email protected]> | 2018-12-11 13:39:32 -0800 |
---|---|---|
committer | Matt Turner <[email protected]> | 2019-01-09 16:42:40 -0800 |
commit | 2632c12477f8c9235d3604fb3dfa7f98e6f04619 (patch) | |
tree | a7baa5a7c2bc17fec136c496138d1990c240e059 /src/compiler | |
parent | 876a4b85fea3f5aff7ac13c895ab76292ef7ffd5 (diff) |
glsl: Add "built-in" functions to do fp32_to_uint64(fp32)
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.glsl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index 63bcd65213c..35a49651381 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -1030,6 +1030,35 @@ __fp64_to_int64(uint64_t a) } uint64_t +__fp32_to_uint64(float f) +{ + uint a = floatBitsToUint(f); + uint aFrac = a & 0x007FFFFFu; + int aExp = int((a>>23) & 0xFFu); + uint aSign = a>>31; + uint zFrac0 = 0u; + uint zFrac1 = 0u; + uint zFrac2 = 0u; + uint64_t default_nan = 0xFFFFFFFFFFFFFFFFUL; + int shiftCount = 0xBE - aExp; + + if (shiftCount <0) { + if (aExp == 0xFF) + return default_nan; + } + + aFrac = mix(aFrac, aFrac | 0x00800000u, aExp != 0); + __shortShift64Left(aFrac, 0, 40, zFrac0, zFrac1); + + if (shiftCount != 0) { + __shift64ExtraRightJamming(zFrac0, zFrac1, zFrac2, shiftCount, + zFrac0, zFrac1, zFrac2); + } + + return __roundAndPackUInt64(aSign, zFrac0, zFrac1, zFrac2); +} + +uint64_t __int64_to_fp64(int64_t a) { if (a==0) |