From 2632c12477f8c9235d3604fb3dfa7f98e6f04619 Mon Sep 17 00:00:00 2001 From: Sagar Ghuge Date: Tue, 11 Dec 2018 13:39:32 -0800 Subject: [PATCH] glsl: Add "built-in" functions to do fp32_to_uint64(fp32) Reviewed-by: Elie Tournier Signed-off-by: Sagar Ghuge --- src/compiler/glsl/float64.glsl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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) { -- 2.30.2