diff --git a/src/rewriter.fs b/src/rewriter.fs index 45076426..925ed260 100644 --- a/src/rewriter.fs +++ b/src/rewriter.fs @@ -202,12 +202,12 @@ module private RewriterImpl = // Swap operands to get rid of parentheses // x*(y*z) -> y*z*x - | FunCall(Op "*", [NoParen x; FunCall(Op "*", [y; z])]) -> + | FunCall(Op "*", [NoParen x; FunCall(Op "*", [y; z])]) when isPure x && isPure y && isPure z -> FunCall(Op "*", [FunCall(Op "*", [y; z]); x]) |> env.fExpr env - // x+(y+z) -> y+z+x - // x+(y-z) -> y-z+a + // x+(y+z) -> x+y+z + // x+(y-z) -> x+y-z | FunCall(Op "+", [NoParen x; FunCall(Op ("+"|"-") as op, [y; z])]) -> - FunCall(Op "+", [FunCall(op, [y; z]); x]) |> env.fExpr env + FunCall(op, [FunCall(Op "+", [x; y]); z]) |> env.fExpr env // x-(y+z) -> x-y-z | FunCall(Op "-", [x; FunCall(Op "+", [y; z])]) -> FunCall(Op "-", [FunCall(Op "-", [x; y]); z]) |> env.fExpr env diff --git a/tests/compression_results.log b/tests/compression_results.log index 91f29169..b64d3285 100644 --- a/tests/compression_results.log +++ b/tests/compression_results.log @@ -7,12 +7,12 @@ ed-209.frag 7672 => 1338.529 elevated.hlsl 3401 => 602.542 endeavour.frag 2568 => 529.992 from-the-seas-to-the-stars.frag 14211 => 2282.423 -frozen-wasteland.frag 4513 => 804.591 +frozen-wasteland.frag 4515 => 804.953 kinder_painter.frag 2832 => 442.132 leizex.frag 2252 => 506.309 lunaquatic.frag 5222 => 1043.256 mandelbulb.frag 2317 => 532.741 -ohanami.frag 3246 => 711.753 +ohanami.frag 3246 => 712.723 orchard.frag 5394 => 1003.067 oscars_chair.frag 4648 => 986.069 robin.frag 6196 => 1039.087 @@ -21,4 +21,4 @@ terrarium.frag 3575 => 747.116 the_real_party_is_in_your_pocket.frag 11986 => 1774.550 valley_ball.glsl 4307 => 881.820 yx_long_way_from_home.frag 2936 => 598.845 -Total: 133422 => 23299.280 +Total: 133424 => 23300.612 diff --git a/tests/real/frozen-wasteland.frag.expected b/tests/real/frozen-wasteland.frag.expected index 264e87fe..898ee16d 100644 --- a/tests/real/frozen-wasteland.frag.expected +++ b/tests/real/frozen-wasteland.frag.expected @@ -148,7 +148,7 @@ float map(vec3 p) { p.y+=height(p.zx); float d=smin(smin(p.y+.5,vine(p+vec3(.8,0,0),30.,3.3)),vine(p.zyx+vec3(0,0,17),33.,1.4)); - d+=p.y*1.2*Noise3d(p*.05); + d+=Noise3d(p*.05)*(p.y*1.2); p.xz*=.3; return d+Noise3d(p*.3); } diff --git a/tests/real/monjori.frag.expected b/tests/real/monjori.frag.expected index a3ae2f3e..74f2b894 100644 --- a/tests/real/monjori.frag.expected +++ b/tests/real/monjori.frag.expected @@ -18,7 +18,7 @@ void main() i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*.025*6.)*(r+h/3.); h=sin(f*.025)*144.-sin(e*.025)*212.*p.x; h=(h+(f-e)*q+sin(r-(a+h)/7.)*10.+i/4.)*.025; - i=mod((cos(h*2.3*sin(a/350.-q))*184.*sin(q-(r*4.3+a/12.)*.025)+tan(r*.025+h)*184.*cos(r*.025+h)+i)/5.6,256.)/64.; + i=mod((i+cos(h*2.3*sin(a/350.-q))*184.*sin(q-(r*4.3+a/12.)*.025)+tan(r*.025+h)*184.*cos(r*.025+h))/5.6,256.)/64.; if(i<0.) i+=4.; if(i>=2.) diff --git a/tests/real/ohanami.frag.expected b/tests/real/ohanami.frag.expected index 2f206ceb..f82496bd 100644 --- a/tests/real/ohanami.frag.expected +++ b/tests/real/ohanami.frag.expected @@ -46,7 +46,7 @@ void main() if(gl_TexCoord[0].w>.5) { ti=max(0,time)/3.; - ti=floor(ti)+clamp(fract(ti)*2,0,1)+noise(floor(gl_FragCoord.xy)); + ti=noise(floor(gl_FragCoord.xy))+floor(ti)+clamp(fract(ti)*2,0,1); ti=floor(ti); float zoom=1.5; vec2 filmoffset=vec2(0); diff --git a/tests/unit/arg-inlining.expected b/tests/unit/arg-inlining.expected index 2d956099..1997a0ff 100644 --- a/tests/unit/arg-inlining.expected +++ b/tests/unit/arg-inlining.expected @@ -76,7 +76,7 @@ float f() s+=s+noinline_canInlineWhenArgIsInlinable5(); s+=s+noinline_canInlineWhenArgIsInlinable6(); s+=s+noinline_cannotInlineWhenArgIsNotInlinable(s); - return s+noinline_cannotInlineWhenArgIsNotInlinable(acos(s))+s; + return s+s+noinline_cannotInlineWhenArgIsNotInlinable(acos(s)); } void main() { diff --git a/tests/unit/operators.expected b/tests/unit/operators.expected index 549ea972..b08c6386 100644 --- a/tests/unit/operators.expected +++ b/tests/unit/operators.expected @@ -16,7 +16,7 @@ "}" "int no_parens(int a,int b,int c)" "{" - "return b+c+a+a+b*c;" + "return a+b+c+a+b*c;" "}" "int no_parens2(int a,int b,int c)" "{" @@ -47,7 +47,12 @@ "g/=-g+g;" "g-=-g--- --g;" "g*=g+g;" - "return--g-++g+g;" + "return g+--g-++g;" + "}" + "float swap_op_order(float g)" + "{" + "float a=g*(g--*g--),b=(g+2.)*(g+3.)*g;" + "return a*b*g;" "}", #endif diff --git a/tests/unit/operators.frag b/tests/unit/operators.frag index 900429f4..a251eef3 100644 --- a/tests/unit/operators.frag +++ b/tests/unit/operators.frag @@ -61,3 +61,10 @@ float cool_ops(float g) f += --f + (- +(++f)); return f; } + +float swap_op_order(float g) +{ + float a = g*((g--)*(g--)); + float b = g*((g+2.)*(g+3.)); + return a*b*g; +} diff --git a/tests/unit/shadowing.frag.expected b/tests/unit/shadowing.frag.expected index 77cee670..afe6f3c4 100644 --- a/tests/unit/shadowing.frag.expected +++ b/tests/unit/shadowing.frag.expected @@ -1,7 +1,7 @@ float f(float g) { g=0.; - return g+++ ++g+g; + return g+g+++ ++g; } float g(float f) { diff --git a/tests/unit/simplify.expected b/tests/unit/simplify.expected index 4b22de83..274b226e 100644 --- a/tests/unit/simplify.expected +++ b/tests/unit/simplify.expected @@ -12,7 +12,7 @@ float baz(float a) { a=a+4.+sin(a); a=a+5.+sin(a); - return-a-a+a; + return a-a-a; } out vec3 outputvar; void notMain(float x)