From: Sagar Ghuge Date: Tue, 11 Dec 2018 21:39:32 +0000 (-0800) Subject: glsl: Add "built-in" functions to do fp32_to_uint64(fp32) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2632c12477f8c9235d3604fb3dfa7f98e6f04619;p=mesa.git glsl: Add "built-in" functions to do fp32_to_uint64(fp32) Reviewed-by: Elie Tournier Signed-off-by: Sagar Ghuge --- 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 @@ -1029,6 +1029,35 @@ __fp64_to_int64(uint64_t a) return __roundAndPackInt64(aSign, aFracHi, aFracLo, zFrac2); } +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) {