From 617a69107ee58e23ace06093bc49fa2c86b7dd4b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 4 Mar 2020 14:21:02 -0800 Subject: [PATCH] soft-fp64/ffloor: Simplify the >= 0 comparison MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Results on the 308 shaders extracted from the fp64 portion of the OpenGL CTS: Tiger Lake and Ice Lake had similar results. (Tiger Lake shown) total instructions in shared programs: 797951 -> 797779 (-0.02%) instructions in affected programs: 126482 -> 126310 (-0.14%) helped: 15 HURT: 0 helped stats (abs) min: 1 max: 20 x̄: 11.47 x̃: 10 helped stats (rel) min: <.01% max: 0.60% x̄: 0.28% x̃: 0.29% 95% mean confidence interval for instructions value: -14.79 -8.14 95% mean confidence interval for instructions %-change: -0.40% -0.16% Instructions are helped. total cycles in shared programs: 6601437 -> 6601355 (<.01%) cycles in affected programs: 1089336 -> 1089254 (<.01%) helped: 15 HURT: 0 helped stats (abs) min: 2 max: 12 x̄: 5.47 x̃: 6 helped stats (rel) min: <.01% max: 0.04% x̄: 0.01% x̃: 0.01% 95% mean confidence interval for cycles value: -7.06 -3.87 95% mean confidence interval for cycles %-change: -0.02% <.01% Cycles are helped. Reviewed-by: Matt Turner Part-of: --- src/compiler/glsl/float64.glsl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index 5b0a9dc0c28..67e0e657c55 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -1714,7 +1714,19 @@ __ftrunc64(uint64_t __a) uint64_t __ffloor64(uint64_t a) { - bool is_positive = __fge64(a, 0ul); + /* The big assumtion is that when 'a' is NaN, __ftrunc(a) returns a. Based + * on that assumption, NaN values that don't have the sign bit will safely + * return NaN (identity). This is guarded by RELAXED_NAN_PROPAGATION + * because otherwise the NaN should have the "signal" bit set. The + * __fadd64 will ensure that occurs. + */ + bool is_positive = +#if defined RELAXED_NAN_PROPAGATION + int(unpackUint2x32(a).y) >= 0 +#else + __fge64(a, 0ul) +#endif + ; uint64_t tr = __ftrunc64(a); if (is_positive || __feq64(tr, a)) { -- 2.30.2