soft-fp64/fadd: Move common code out of both branches of an if-statement
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 4 Mar 2020 20:39:36 +0000 (12:39 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 18 Mar 2020 20:36:29 +0000 (20:36 +0000)
The previous two commits were just setting the scene for this change.

The mix(..., __propagateFloat64NaN(a, b), propagate) statements are not
identical in the two halves, but they are equivalent.  The first clause
of the mix in the else-branch is trivally ±Inf.  The first clause in the
then-branch __packFloat64(aSign, aExp, aFracHi, aFracLo).  The
preceeding conditions prove that aExp=0x7ff, aFracHi=0, and aFracLo=0.

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: 819560 -> 787258 (-3.94%)
instructions in affected programs: 757737 -> 725435 (-4.26%)
helped: 74
HURT: 0
helped stats (abs) min: 43 max: 3545 x̄: 436.51 x̃: 296
helped stats (rel) min: 3.54% max: 6.16% x̄: 4.52% x̃: 4.36%
95% mean confidence interval for instructions value: -548.42 -324.61
95% mean confidence interval for instructions %-change: -4.68% -4.37%
Instructions are helped.

total cycles in shared programs: 6817254 -> 6483227 (-4.90%)
cycles in affected programs: 6385272 -> 6051245 (-5.23%)
helped: 74
HURT: 0
helped stats (abs) min: 430 max: 33271 x̄: 4513.88 x̃: 3047
helped stats (rel) min: 4.28% max: 7.45% x̄: 5.48% x̃: 5.31%
95% mean confidence interval for cycles value: -5610.46 -3417.30
95% mean confidence interval for cycles %-change: -5.65% -5.32%
Cycles are helped.

total spills in shared programs: 591 -> 553 (-6.43%)
spills in affected programs: 591 -> 553 (-6.43%)
helped: 1
HURT: 0

total fills in shared programs: 1353 -> 1307 (-3.40%)
fills in affected programs: 1353 -> 1307 (-3.40%)
helped: 1
HURT: 0

Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4142>

src/compiler/glsl/float64.glsl

index 06f47902745de250e39a7bd88b64011083fdac10..d079207a774472cf06138e9276f0fd98f3a60ec8 100644 (file)
@@ -708,34 +708,23 @@ __fadd64(uint64_t a, uint64_t b)
          __shift64ExtraRightJamming(
             zFrac0, zFrac1, zFrac2, 1, zFrac0, zFrac1, zFrac2);
       } else {
-         if (0 < expDiff) {
-            if (aExp == 0x7FF) {
-               bool propagate = (aFracHi | aFracLo) != 0u;
-               return mix(a, __propagateFloat64NaN(a, b), propagate);
-            }
-
-            expDiff = mix(abs(expDiff), abs(expDiff) - 1, bExp == 0);
-            bFracHi = mix(bFracHi | 0x00100000u, bFracHi, bExp == 0);
-            __shift64ExtraRightJamming(
-               bFracHi, bFracLo, 0u, expDiff, bFracHi, bFracLo, zFrac2);
-            zExp = aExp;
-         } else {
+         if (expDiff < 0) {
             EXCHANGE(aFracHi, bFracHi);
             EXCHANGE(aFracLo, bFracLo);
             EXCHANGE(aExp, bExp);
+         }
 
-            if (aExp == 0x7FF) {
-               bool propagate = (aFracHi | aFracLo) != 0u;
-               return mix(__packFloat64(aSign, 0x7ff, 0u, 0u), __propagateFloat64NaN(a, b), propagate);
-            }
-
-            expDiff = mix(abs(expDiff), abs(expDiff) - 1, bExp == 0);
-            bFracHi = mix(bFracHi | 0x00100000u, bFracHi, bExp == 0);
-            __shift64ExtraRightJamming(
-               bFracHi, bFracLo, 0u, expDiff, bFracHi, bFracLo, zFrac2);
-            zExp = aExp;
+         if (aExp == 0x7FF) {
+            bool propagate = (aFracHi | aFracLo) != 0u;
+            return mix(__packFloat64(aSign, 0x7ff, 0u, 0u), __propagateFloat64NaN(a, b), propagate);
          }
 
+         expDiff = mix(abs(expDiff), abs(expDiff) - 1, bExp == 0);
+         bFracHi = mix(bFracHi | 0x00100000u, bFracHi, bExp == 0);
+         __shift64ExtraRightJamming(
+            bFracHi, bFracLo, 0u, expDiff, bFracHi, bFracLo, zFrac2);
+         zExp = aExp;
+
          aFracHi |= 0x00100000u;
          __add64(aFracHi, aFracLo, bFracHi, bFracLo, zFrac0, zFrac1);
          --zExp;