summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/float64.glsl
diff options
context:
space:
mode:
authorElie Tournier <[email protected]>2017-08-11 14:09:01 +0100
committerMatt Turner <[email protected]>2019-01-09 16:42:40 -0800
commit48891ab441f5cbf593b043b0e3a4f9168c9cd479 (patch)
tree70719701bd06b9398c81aa55c98d944f224fbe76 /src/compiler/glsl/float64.glsl
parent2119094b1de33342de8c3b7284e6d5b98452d256 (diff)
glsl: Add "built-in" functions to do trunc(fp64)
v2: use mix. Signed-off-by: Elie Tournier <[email protected]>
Diffstat (limited to 'src/compiler/glsl/float64.glsl')
-rw-r--r--src/compiler/glsl/float64.glsl22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
index 7bfaa9cab47..88209fc99f0 100644
--- a/src/compiler/glsl/float64.glsl
+++ b/src/compiler/glsl/float64.glsl
@@ -1355,3 +1355,25 @@ __fsqrt64(uint64_t a)
__shift64ExtraRightJamming(zFrac0, zFrac1, 0u, 10, zFrac0, zFrac1, zFrac2);
return __roundAndPackFloat64(0u, zExp, zFrac0, zFrac1, zFrac2);
}
+
+uint64_t
+__ftrunc64(uint64_t __a)
+{
+ uvec2 a = unpackUint2x32(__a);
+ int aExp = __extractFloat64Exp(__a);
+ uint zLo;
+ uint zHi;
+
+ int unbiasedExp = aExp - 1023;
+ int fracBits = 52 - unbiasedExp;
+ uint maskLo = mix(~0u << fracBits, 0u, fracBits >= 32);
+ uint maskHi = mix(~0u << (fracBits - 32), ~0u, fracBits < 33);
+ zLo = maskLo & a.x;
+ zHi = maskHi & a.y;
+
+ zLo = mix(zLo, 0u, unbiasedExp < 0);
+ zHi = mix(zHi, 0u, unbiasedExp < 0);
+ zLo = mix(zLo, a.x, unbiasedExp > 52);
+ zHi = mix(zHi, a.y, unbiasedExp > 52);
+ return packUint2x32(uvec2(zLo, zHi));
+}