<p dir="ltr">12. aug. 2016 04.02 skrev "Timothy Arceri" <<a href="mailto:timothy.arceri@collabora.com">timothy.arceri@collabora.com</a>>:<br>
><br>
> On Thu, 2016-08-11 at 20:54 +0200, Thomas Helland wrote:<br>
> > 2016-08-11 18:19 GMT+02:00 Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>:<br>
> > ><br>
> > > ping<br>
> > ><br>
> > > On 07/19/2016 10:37 PM, Ian Romanick wrote:<br>
> > > ><br>
> > > > From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> > > ><br>
> > > > Some shaders include code that looks like:<br>
> > > ><br>
> > > >    uniform int i;<br>
> > > >    uniform vec4 bones[...];<br>
> > > ><br>
> > > >    foo(bones[i * 3], bones[i * 3 + 1], bones[i * 3 + 2]);<br>
> > > ><br>
> > > > CSE would do some work on this:<br>
> > > ><br>
> > > >    x = i * 3<br>
> > > >    foo(bones[x], bones[x + 1], bones[x + 2]);<br>
> > > ><br>
> > > > The compiler may then add '<< 4 + base' to the index<br>
> > > > calculations.<br>
> > > > This results in expressions like<br>
> > > ><br>
> > > >    x = i * 3<br>
> > > >    foo(bones[x << 4], bones[(x + 1) << 4], bones[(x + 2) << 4]);<br>
> > > ><br>
> ><br>
> > This may just be me being dense, but why is the compiler adding the<br>
> > shift?<br>
> > It seems like this would be "un-optimizing" and so it shouldn't be<br>
> > added?<br>
> ><br>
> > This patch is also a good argument for adding a constant<br>
> > reassociation pass.<br>
> > At least the (a * #b) << #c    --->    a * (#b << #c) would be caught<br>
> > by that.<br>
> ><br>
> > I was confused whether the optimization was preserving signed-ness<br>
> > correctly<br>
> > but after a couple rounds with myself I believe it is correct.<br>
> ><br>
> > The change looks good and is:<br>
> ><br>
> > Reviewed-by: Thomas Helland <<a href="mailto:thomashelland90@gmail.com">thomashelland90@gmail.com</a>><br>
> ><br>
> > (Oh, and yes, I'm back to hobby mesa development after finally<br>
> > securing a new job and a new apartment)<br>
><br>
> Congrats and welcome back. <br>
><br>
> I did send you an email but just in case you missed it I've picked up<br>
> on your loop unrolling work.</p>
<p dir="ltr">Thanks!</p>
<p dir="ltr">Yeah, I noticed that one. At least I believe I did. I think I might have also replied with some hints and suggestions? At least I meant to. My Gmail doesn't seem perfectly stable; somehow this thread didn't get pushed up in my inbox when it got more replies, so I might have missed something. If so, make sure to ping me! I should probably find out what's up with that mail thing though.</p>
<p dir="ltr">><br>
> ><br>
> > ><br>
> > > ><br>
> > > > Just rearranging the math to produce (i * 48) + 16 saves an<br>
> > > > instruction, and it allows CSE to do more work.<br>
> > > ><br>
> > > >    x = i * 48;<br>
> > > >    foo(bones[x], bones[x + 16], bones[x + 32]);<br>
> > > ><br>
> > > > So, ~6 instructions becomes ~3.<br>
> > > ><br>
> > > > Some individual shader-db results look pretty bad.  However, I<br>
> > > > have a<br>
> > > > really, really hard time believing the change in estimated cycles<br>
> > > > in,<br>
> > > > for example, 3dmmes-taiji/51.shader_test after looking that<br>
> > > > change in<br>
> > > > the generated code.<br>
> > > ><br>
> > > > G45<br>
> > > > total instructions in shared programs: 4020840 -> 4010070 (-<br>
> > > > 0.27%)<br>
> > > > instructions in affected programs: 177460 -> 166690 (-6.07%)<br>
> > > > helped: 894<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > total cycles in shared programs: 98829000 -> 98784990 (-0.04%)<br>
> > > > cycles in affected programs: 3936648 -> 3892638 (-1.12%)<br>
> > > > helped: 894<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > Ironlake<br>
> > > > total instructions in shared programs: 6418887 -> 6408117 (-<br>
> > > > 0.17%)<br>
> > > > instructions in affected programs: 177460 -> 166690 (-6.07%)<br>
> > > > helped: 894<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > total cycles in shared programs: 143504542 -> 143460532 (-0.03%)<br>
> > > > cycles in affected programs: 3936648 -> 3892638 (-1.12%)<br>
> > > > helped: 894<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > Sandy Bridge<br>
> > > > total instructions in shared programs: 8357887 -> 8339251 (-<br>
> > > > 0.22%)<br>
> > > > instructions in affected programs: 432715 -> 414079 (-4.31%)<br>
> > > > helped: 2795<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > total cycles in shared programs: 118284184 -> 118207412 (-0.06%)<br>
> > > > cycles in affected programs: 6114626 -> 6037854 (-1.26%)<br>
> > > > helped: 2478<br>
> > > > HURT: 317<br>
> > > ><br>
> > > > Ivy Bridge<br>
> > > > total instructions in shared programs: 7669390 -> 7653822 (-<br>
> > > > 0.20%)<br>
> > > > instructions in affected programs: 388234 -> 372666 (-4.01%)<br>
> > > > helped: 2795<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > total cycles in shared programs: 68381982 -> 68263684 (-0.17%)<br>
> > > > cycles in affected programs: 1972658 -> 1854360 (-6.00%)<br>
> > > > helped: 2458<br>
> > > > HURT: 307<br>
> > > ><br>
> > > > Haswell<br>
> > > > total instructions in shared programs: 7082636 -> 7067068 (-<br>
> > > > 0.22%)<br>
> > > > instructions in affected programs: 388234 -> 372666 (-4.01%)<br>
> > > > helped: 2795<br>
> > > > HURT: 0<br>
> > > ><br>
> > > > total cycles in shared programs: 68282020 -> 68164158 (-0.17%)<br>
> > > > cycles in affected programs: 1891820 -> 1773958 (-6.23%)<br>
> > > > helped: 2459<br>
> > > > HURT: 261<br>
> > > ><br>
> > > > Broadwell<br>
> > > > total instructions in shared programs: 9002466 -> 8985875 (-<br>
> > > > 0.18%)<br>
> > > > instructions in affected programs: 658784 -> 642193 (-2.52%)<br>
> > > > helped: 2795<br>
> > > > HURT: 5<br>
> > > ><br>
> > > > total cycles in shared programs: 78503092 -> 78450404 (-0.07%)<br>
> > > > cycles in affected programs: 2873304 -> 2820616 (-1.83%)<br>
> > > > helped: 2275<br>
> > > > HURT: 415<br>
> > > ><br>
> > > > Skylake<br>
> > > > total instructions in shared programs: 9156978 -> 9140387 (-<br>
> > > > 0.18%)<br>
> > > > instructions in affected programs: 682625 -> 666034 (-2.43%)<br>
> > > > helped: 2795<br>
> > > > HURT: 5<br>
> > > ><br>
> > > > total cycles in shared programs: 75591392 -> 75550574 (-0.05%)<br>
> > > > cycles in affected programs: 3192120 -> 3151302 (-1.28%)<br>
> > > > helped: 2271<br>
> > > > HURT: 425<br>
> > > ><br>
> > > > Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> > > > ---<br>
> > > >  src/compiler/nir/nir_opt_algebraic.py | 11 +++++++++++<br>
> > > >  1 file changed, 11 insertions(+)<br>
> > > ><br>
> > > > diff --git a/src/compiler/nir/nir_opt_algebraic.py<br>
> > > > b/src/compiler/nir/nir_opt_algebraic.py<br>
> > > > index 0f0896b..37cb700 100644<br>
> > > > --- a/src/compiler/nir/nir_opt_algebraic.py<br>
> > > > +++ b/src/compiler/nir/nir_opt_algebraic.py<br>
> > > > @@ -119,6 +119,17 @@ optimizations = [<br>
> > > >     (('~fadd@64', a, ('fmul',         c , ('fadd', b, ('fneg',<br>
> > > > a)))), ('flrp', a, b, c), '!options->lower_flrp64'),<br>
> > > >     (('ffma', a, b, c), ('fadd', ('fmul', a, b), c), 'options-<br>
> > > > >lower_ffma'),<br>
> > > >     (('~fadd', ('fmul', a, b), c), ('ffma', a, b, c), 'options-<br>
> > > > >fuse_ffma'),<br>
> > > > +<br>
> > > > +   # (a * #b + #c) << #d<br>
> > > > +   # ((a * #b) << #d) + (#c << #d)<br>
> > > > +   # (a * (#b << #d)) + (#c << #d)<br>
> > > > +   (('ishl', ('iadd', ('imul', a, '#b'), '#c'), '#d'),<br>
> > > > +    ('iadd', ('imul', a, ('ishl', b, d)), ('ishl', c, d))),<br>
> > > > +<br>
> > > > +   # (a * #b) << #c<br>
> > > > +   # a * (#b << #c)<br>
> > > > +   (('ishl', ('imul', a, '#b'), '#c'), ('imul', a, ('ishl', b,<br>
> > > > c))),<br>
> > > > +<br>
> > > >     # Comparison simplifications<br>
> > > >     (('~inot', ('flt', a, b)), ('fge', a, b)),<br>
> > > >     (('~inot', ('fge', a, b)), ('flt', a, b)),<br>
> > > ><br>
> > ><br>
> > > _______________________________________________<br>
> > > mesa-dev mailing list<br>
> > ><a href="mailto:mesa-dev@lists.freedesktop.org"> mesa-dev@lists.freedesktop.org</a><br>
> > ><a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev"> https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> > _______________________________________________<br>
> > mesa-dev mailing list<br>
> ><a href="mailto:mesa-dev@lists.freedesktop.org"> mesa-dev@lists.freedesktop.org</a><br>
> ><a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev"> https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>