From 7673dcbd21150e67c5a36bdcc3eee419c025604b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 2 Mar 2020 18:38:11 -0800 Subject: [PATCH] soft-fp64/fsat: Correctly handle NaN MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit fsat is defined as min(max(a, 0.0), 1.0), and IEEE defines both min and max to return the non-NaN value when one value is NaN. Based on this, fsat should definitely return 0.0 for NaN. 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: 841666 -> 841647 (<.01%) instructions in affected programs: 122033 -> 122014 (-0.02%) helped: 7 HURT: 0 helped stats (abs) min: 1 max: 4 x̄: 2.71 x̃: 3 helped stats (rel) min: 0.01% max: 0.02% x̄: 0.02% x̃: 0.01% 95% mean confidence interval for instructions value: -3.74 -1.69 95% mean confidence interval for instructions %-change: -0.02% -0.01% Instructions are helped. total cycles in shared programs: 6927246 -> 6926904 (<.01%) cycles in affected programs: 1038987 -> 1038645 (-0.03%) helped: 7 HURT: 0 helped stats (abs) min: 18 max: 72 x̄: 48.86 x̃: 54 helped stats (rel) min: 0.03% max: 0.05% x̄: 0.03% x̃: 0.03% 95% mean confidence interval for cycles value: -67.38 -30.33 95% mean confidence interval for cycles %-change: -0.05% -0.02% Cycles are helped. Reviewed-by: Jason Ekstrand Reviewed-by: Matt Turner Fixes: a42163cbbc1 ("compiler: Add lowering support for 64-bit saturate operations to software") Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2585 Part-of: --- src/compiler/glsl/float64.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index 6dd85e5cc57..363248c9f59 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -258,10 +258,11 @@ __fge64(uint64_t a, uint64_t b) uint64_t __fsat64(uint64_t __a) { - if (__flt64(__a, 0ul)) + /* fsat(NaN) should be zero. */ + if (__is_nan(__a) || __flt64_nonnan(__a, 0ul)) return 0ul; - if (__fge64(__a, 0x3FF0000000000000ul /* 1.0 */)) + if (!__flt64_nonnan(__a, 0x3FF0000000000000ul /* 1.0 */)) return 0x3FF0000000000000ul; return __a; -- 2.30.2