From 325a21f5ebca90ccac9a7c3c571ed0513c4ec3d2 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 2 Mar 2020 16:43:11 -0800 Subject: soft-fp64: Simplify __countLeadingZeros32 function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit findMSB returns -1 for an input of zero, so 31 - findMSB(a) is sufficient on its own. There's only one user of findMSB in shader-db, and it does not match this pattern. TODO: Add a pattern in the backend code generator that emits 31 - nir_op_ufind_msb(a) as if it were nir_op_uclz. That should save a couple instructions. 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: 859509 -> 848109 (-1.33%) instructions in affected programs: 841058 -> 829658 (-1.36%) helped: 97 HURT: 0 helped stats (abs) min: 3 max: 1161 x̄: 117.53 x̃: 72 helped stats (rel) min: 0.98% max: 6.74% x̄: 1.70% x̃: 1.35% 95% mean confidence interval for instructions value: -147.21 -87.84 95% mean confidence interval for instructions %-change: -1.94% -1.46% Instructions are helped. total cycles in shared programs: 7072275 -> 6969145 (-1.46%) cycles in affected programs: 6955767 -> 6852637 (-1.48%) helped: 97 HURT: 0 helped stats (abs) min: 32 max: 10900 x̄: 1063.20 x̃: 560 helped stats (rel) min: 1.18% max: 7.58% x̄: 1.84% x̃: 1.45% 95% mean confidence interval for cycles value: -1339.43 -786.96 95% mean confidence interval for cycles %-change: -2.11% -1.57% Cycles are helped. Reviewed-by: Jason Ekstrand Reviewed-by: Matt Turner Part-of: --- src/compiler/glsl/float64.glsl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl index 9834241872c..f5dee00ae2b 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -537,9 +537,7 @@ __roundAndPackInt64(uint zSign, uint zFrac0, uint zFrac1, uint zFrac2) int __countLeadingZeros32(uint a) { - int shiftCount; - shiftCount = mix(31 - findMSB(a), 32, a == 0u); - return shiftCount; + return 31 - findMSB(a); } /* Takes an abstract floating-point value having sign `zSign', exponent `zExp', -- cgit v1.2.3