On Tuesday, July 29, 2014 12:36:34 PM Petri Latvala wrote: > Sort expression operands when possible so that building expected IR > sexps doesn't need to know which ordering will be produced by an > optimization pass. > > Signed-off-by: Petri Latvala <petri.latv...@intel.com> > --- > src/glsl/tests/compare_ir | 4 ++-- > src/glsl/tests/sexps.py | 37 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 39 insertions(+), 2 deletions(-) > > diff --git a/src/glsl/tests/compare_ir b/src/glsl/tests/compare_ir > index a40fc81..0b63fab 100755 > --- a/src/glsl/tests/compare_ir > +++ b/src/glsl/tests/compare_ir > @@ -38,9 +38,9 @@ if len(sys.argv) != 3: > exit(1) > > with open(sys.argv[1]) as f: > - ir1 = sort_decls(parse_sexp(f.read())) > + ir1 = sort_decls(sort_commutatives(parse_sexp(f.read()))) > with open(sys.argv[2]) as f: > - ir2 = sort_decls(parse_sexp(f.read())) > + ir2 = sort_decls(sort_commutatives(parse_sexp(f.read()))) > > if ir1 == ir2: > exit(0) > diff --git a/src/glsl/tests/sexps.py b/src/glsl/tests/sexps.py > index a714af8..60c54bd 100644 > --- a/src/glsl/tests/sexps.py > +++ b/src/glsl/tests/sexps.py > @@ -101,3 +101,40 @@ def sort_decls(sexp): > other_code.append(s) > return sorted(decls) + other_code > > +commutatives = [ > + '+', > + '*', > + 'imul_high', > + 'carry', > + '==', > + '!=', > + 'all_equal', > + 'any_nequal', > + '&', > + '^', > + '|', > + '&&', > + '^^', > + '||', > + 'dot', > + 'min', > + 'max' > + ]
In python style constants go at the top of the file, and should be all caps. > + > +def sort_commutatives(sexp): > + """Sort operands of expressions that are commutative in sexp. > + > + This is used to work around the fact that optimization passes might > + reorder operands. > + """ > + if not isinstance(sexp, list): return sexp > + > + code = [] > + for s in sexp: > + sd = sort_commutatives(s) > + # An expression is [expression, type, operation, operand1, ...] > + if isinstance(sd, list) and len(sd) >= 3 and sd[0] == 'expression' > and sd[2] in commutatives: > + code.append(['expression', sd[1:2]] + sorted(sd[3:])) > + else: > + code.append(sd) > + return code > -- > 2.0.1 > > _______________________________________________ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev