From f998ce41115a3c2bd87182885026a784aa6cd089 Mon Sep 17 00:00:00 2001 From: Sagar Ghuge Date: Tue, 11 Dec 2018 12:58:36 -0800 Subject: [PATCH] glsl: Add "built-in" functions to do fp32_to_int64(fp32) Reviewed-by: Elie Tournier Signed-off-by: Sagar Ghuge --- src/compiler/glsl/float64.glsl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index 35a4965..415dde3 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -1058,6 +1058,37 @@ __fp32_to_uint64(float f) return __roundAndPackUInt64(aSign, zFrac0, zFrac1, zFrac2); } +int64_t +__fp32_to_int64(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; + int64_t default_NegNaN = -0x7FFFFFFFFFFFFFFEL; + int64_t default_PosNaN = 0xFFFFFFFFFFFFFFFFL; + int shiftCount = 0xBE - aExp; + + if (shiftCount <0) { + if (aExp == 0xFF && aFrac != 0u) + return default_NegNaN; + return mix(default_NegNaN, default_PosNaN, aSign == 0u); + } + + 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 __roundAndPackInt64(aSign, zFrac0, zFrac1, zFrac2); +} + uint64_t __int64_to_fp64(int64_t a) { -- 2.7.4