From cbf090b809bd8e74c0def50551b580585092d664 Mon Sep 17 00:00:00 2001 From: Elie Tournier Date: Wed, 9 Aug 2017 11:41:13 +0100 Subject: [PATCH] glsl: Add "built-in" functions to do uint_to_fp64(uint) Signed-off-by: Elie Tournier --- src/compiler/glsl/float64.glsl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index f7952413fad..232bf18b4d3 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -858,3 +858,25 @@ __fp64_to_uint(uint64_t a) return mix(z, expt, (aSign != 0u) && (z != 0u)); } + +uint64_t +__uint_to_fp64(uint a) +{ + if (a == 0u) + return 0ul; + + int shiftDist = __countLeadingZeros32(a) + 21; + + uint aHigh = 0u; + uint aLow = 0u; + int negCount = (- shiftDist) & 31; + + aHigh = mix(0u, a<< shiftDist - 32, shiftDist < 64); + aLow = 0u; + aHigh = mix(aHigh, 0u, shiftDist == 0); + aLow = mix(aLow, a, shiftDist ==0); + aHigh = mix(aHigh, a >> negCount, shiftDist < 32); + aLow = mix(aLow, a << shiftDist, shiftDist < 32); + + return __packFloat64(0u, 0x432 - shiftDist, aHigh, aLow); +}