summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSagar Ghuge <[email protected]>2018-12-07 15:05:39 -0800
committerMatt Turner <[email protected]>2019-01-09 16:42:40 -0800
commit5a87441807cbb6238c513f2d4c74e464c1a310ca (patch)
tree26584f321a54d5f8646522c4048d8fbd55a2e1e2 /src
parentc9d333a6b76e27bda48efee35da53afba2dc191c (diff)
glsl: Add utility function to round and pack uint64_t value
Reviewed-by: Elie Tournier <[email protected]> Signed-off-by: Sagar Ghuge <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl/float64.glsl32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
index 6a763ffdab0..c6ba37221af 100644
--- a/src/compiler/glsl/float64.glsl
+++ b/src/compiler/glsl/float64.glsl
@@ -451,6 +451,38 @@ __roundAndPackFloat64(uint zSign,
return __packFloat64(zSign, zExp, zFrac0, zFrac1);
}
+uint64_t
+__roundAndPackUInt64(uint zSign, uint zFrac0, uint zFrac1, uint zFrac2)
+{
+ bool roundNearestEven;
+ bool increment;
+ uint64_t default_nan = 0xFFFFFFFFFFFFFFFFUL;
+
+ roundNearestEven = FLOAT_ROUNDING_MODE == FLOAT_ROUND_NEAREST_EVEN;
+
+ if (zFrac2 >= 0x80000000u)
+ increment = false;
+
+ if (!roundNearestEven) {
+ if (zSign != 0u) {
+ if ((FLOAT_ROUNDING_MODE == FLOAT_ROUND_DOWN) && (zFrac2 != 0u)) {
+ increment = false;
+ }
+ } else {
+ increment = (FLOAT_ROUNDING_MODE == FLOAT_ROUND_UP) &&
+ (zFrac2 != 0u);
+ }
+ }
+
+ if (increment) {
+ __add64(zFrac0, zFrac1, 0u, 1u, zFrac0, zFrac1);
+ if ((zFrac0 | zFrac1) != 0u)
+ zFrac1 &= ~(1u) + uint(zFrac2 == 0u) & uint(roundNearestEven);
+ }
+ return mix(packUint2x32(uvec2(zFrac1, zFrac0)), default_nan,
+ (zSign !=0u && (zFrac0 | zFrac1) != 0u));
+}
+
/* Returns the number of leading 0 bits before the most-significant 1 bit of
* `a'. If `a' is zero, 32 is returned.
*/