aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSagar Ghuge <[email protected]>2018-12-11 12:58:36 -0800
committerMatt Turner <[email protected]>2019-01-09 16:42:40 -0800
commitf998ce41115a3c2bd87182885026a784aa6cd089 (patch)
treebef3865508ac4da62d2b37fdba28b304a0c041da /src
parent2632c12477f8c9235d3604fb3dfa7f98e6f04619 (diff)
glsl: Add "built-in" functions to do fp32_to_int64(fp32)
Reviewed-by: Elie Tournier <[email protected]> Signed-off-by: Sagar Ghuge <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl/float64.glsl31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
index 35a49651381..415dde3907c 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)
{