diff options
author | Sagar Ghuge <[email protected]> | 2018-12-07 15:07:57 -0800 |
---|---|---|
committer | Matt Turner <[email protected]> | 2019-01-09 16:42:40 -0800 |
commit | 5a674fd7896f30d44d9300406b8732081d1584b6 (patch) | |
tree | 010ab61c3dc04000a01905c2aadd46fbb0861c42 /src/compiler/glsl/float64.glsl | |
parent | 5a87441807cbb6238c513f2d4c74e464c1a310ca (diff) |
glsl: Add "built-in" functions to do fp64_to_uint64(fp64)
Reviewed-by: Elie Tournier <[email protected]>
Signed-off-by: Sagar Ghuge <[email protected]>
Diffstat (limited to 'src/compiler/glsl/float64.glsl')
-rw-r--r-- | src/compiler/glsl/float64.glsl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index c6ba37221af..cf069fe6588 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -938,6 +938,33 @@ __uint64_to_fp64(uint64_t a) } uint64_t +__fp64_to_uint64(uint64_t a) +{ + uint aFracLo = __extractFloat64FracLo(a); + uint aFracHi = __extractFloat64FracHi(a); + int aExp = __extractFloat64Exp(a); + uint aSign = __extractFloat64Sign(a); + uint zFrac2 = 0u; + uint64_t default_nan = 0xFFFFFFFFFFFFFFFFUL; + + aFracHi = mix(aFracHi, aFracHi | 0x00100000u, aExp != 0); + int shiftCount = 0x433 - aExp; + + if ( shiftCount <= 0 ) { + if (shiftCount < -11 && aExp == 0x7FF) { + if ((aFracHi | aFracLo) != 0u) + return __propagateFloat64NaN(a, a); + return mix(default_nan, a, aSign == 0u); + } + __shortShift64Left(aFracHi, aFracLo, -shiftCount, aFracHi, aFracLo); + } else { + __shift64ExtraRightJamming(aFracHi, aFracLo, zFrac2, shiftCount, + aFracHi, aFracLo, zFrac2); + } + return __roundAndPackUInt64(aSign, aFracHi, aFracLo, zFrac2); +} + +uint64_t __int64_to_fp64(int64_t a) { if (a==0) |