diff --git a/src/rewriter.fs b/src/rewriter.fs index 784ee658..f97e791a 100644 --- a/src/rewriter.fs +++ b/src/rewriter.fs @@ -211,14 +211,14 @@ module private RewriterImpl = // a=a; -> a | FunCall(Op "=", [Var x; Var y]) when x.Name = y.Name -> Var y - // Match: x = x + ... + // x=x+... -> x+=... | FunCall(Op "=", [Var x; FunCall(Op op, [Var y; e])]) when x.Name = y.Name && augmentableOperators.Contains op -> FunCall(Op (op + "="), [Var x; e]) - // Match: x = ... + x - // works only if the operator is commutative - | FunCall(Op "=", [Var x; FunCall(Op ("+"|"*"|"&"|"^"|"|" as op), [e; Var y])]) + // x=...+x -> x+=... + // Works only if the operator is commutative. * is not commutative with vectors and matrices. + | FunCall(Op "=", [Var x; FunCall(Op ("+"|"&"|"^"|"|" as op), [e; Var y])]) when x.Name = y.Name -> FunCall(Op (op + "="), [Var x; e]) @@ -370,12 +370,12 @@ module private RewriterImpl = List.collect replacements stmts - // Squeeze declarations: "float a=2.; float b;" => "float a=2.,b;" + // Squeeze declarations: "float a=2.; float b;" -> "float a=2.,b;" let rec squeezeConsecutiveDeclarations = function | []-> [] | Decl(ty1, li1) :: Decl(ty2, li2) :: l when ty1 = ty2 -> squeezeConsecutiveDeclarations (Decl(ty1, li1 @ li2) :: l) - // int a=2; for (int b=3; ...) -> int a=2, b=3; for (; ...) + // int a=2; for (int b=3; ...) -> int a=2, b=3; for (; ...) | Decl(ty1, li1) :: ForD((ty2, li2), cond, inc, body) :: l when ty1 = ty2 -> squeezeConsecutiveDeclarations (Decl(ty1, li1 @ li2) :: ForE(None, cond, inc, body) :: l) | e::l -> e :: squeezeConsecutiveDeclarations l diff --git a/tests/compression_results.log b/tests/compression_results.log index eab6dafa..f11da94f 100644 --- a/tests/compression_results.log +++ b/tests/compression_results.log @@ -1,19 +1,19 @@ clod.frag... 8836 => 1515.830 -mouton/mouton.vert... 16951 => 2447.462 -audio-flight-v2.frag 4509 => 881.311 +mouton/mouton.vert... 16952 => 2447.464 +audio-flight-v2.frag 4510 => 881.310 buoy.frag 4051 => 607.428 controllable-machinery.frag 7703 => 1216.907 ed-209.frag 7697 => 1340.743 elevated.hlsl 3400 => 602.269 endeavour.frag 2584 => 532.679 -from-the-seas-to-the-stars.frag 14250 => 2308.842 +from-the-seas-to-the-stars.frag 14251 => 2308.886 frozen-wasteland.frag 4566 => 806.475 kinder_painter.frag 2847 => 442.771 leizex.frag 2270 => 510.375 lunaquatic.frag 5234 => 1043.382 mandelbulb.frag 2342 => 537.655 -ohanami.frag 3255 => 723.732 -orchard.frag 5505 => 1027.273 +ohanami.frag 3256 => 723.324 +orchard.frag 5506 => 1027.274 oscars_chair.frag 4651 => 986.364 robin.frag 6254 => 1047.419 slisesix.frag 4549 => 913.642 @@ -21,4 +21,4 @@ terrarium.frag 3593 => 741.557 the_real_party_is_in_your_pocket.frag 12087 => 1780.714 valley_ball.glsl 4307 => 881.820 yx_long_way_from_home.frag 2942 => 598.650 -Total: 134383 => 23495.298 +Total: 134388 => 23494.936 diff --git a/tests/real/audio-flight-v2.frag.expected b/tests/real/audio-flight-v2.frag.expected index b31e758a..a957f514 100644 --- a/tests/real/audio-flight-v2.frag.expected +++ b/tests/real/audio-flight-v2.frag.expected @@ -188,7 +188,7 @@ vec2 marcher(vec3 ro,vec3 rd) } vec3 normal(vec3 p,float t) { - t*=MINDIST; + t=MINDIST*t; vec2 h=vec2(1,-1)*.5773; return normalize(h.xyy*map(p+h.xyy*t,0.).x+h.yyx*map(p+h.yyx*t,0.).x+h.yxy*map(p+h.yxy*t,0.).x+h.xxx*map(p+h.xxx*t,0.).x); } diff --git a/tests/real/from-the-seas-to-the-stars.frag.expected b/tests/real/from-the-seas-to-the-stars.frag.expected index b14b9181..878c3be9 100644 --- a/tests/real/from-the-seas-to-the-stars.frag.expected +++ b/tests/real/from-the-seas-to-the-stars.frag.expected @@ -760,7 +760,7 @@ void main() p.y+=.5; vec3 r=normalize(camtarget-campos),s=normalize(cross(vec3(0,1,0),r)),t=cross(s,r); p-=campos; - p*=transpose(mat3(s,-t,r)); + p=transpose(mat3(s,-t,r))*p; p.xy*=rotmat(sin(time/2)*.05*cameraroll+cameraroll2); p.y+=(fbm(vec2(time/16))-.5)*.1*cameraroll; p.x+=(fbm(vec2(time/14+10))-.5)*.1*cameraroll; diff --git a/tests/real/mouton/mouton.expected b/tests/real/mouton/mouton.expected index 9ec33b5d..e11e09be 100644 --- a/tests/real/mouton/mouton.expected +++ b/tests/real/mouton/mouton.expected @@ -767,7 +767,7 @@ const char *mouton_frag = "b=mix(b,mix(mix(vec3(1,.5,0),vec3(.8,.5,1),(cos(Y*5.+t*5.)*.5+.5)*a.y),vec3(1),smoothstep(-Y,Y,q)),a.x);" "}" "l=vec2(abs(f.x*5.-.35)-1.8,f.y*5.-1.4);" - "l*=E(t*5.);" + "l=E(t*5.)*l;" "G=(1.4+.2*sin(t*20.))*smoothstep(.5,1.,a.x);" "O=J(l,G);" "P=mix(vec3(1,.6,0),vec3(1,.2,0),smoothstep(-.1,.6,J(l,G*.5)))*1.3;" diff --git a/tests/real/ohanami.frag.expected b/tests/real/ohanami.frag.expected index fe9932c5..f9e105cb 100644 --- a/tests/real/ohanami.frag.expected +++ b/tests/real/ohanami.frag.expected @@ -58,7 +58,7 @@ void main() if(ti==10) ro.y+=2; vec3 w=normalize(vec3(0,1.3,0)-ro),u=normalize(cross(w,vec3(0,1,0))); - rd*=mat3(u,normalize(cross(w,-u)),w); + rd=mat3(u,normalize(cross(w,-u)),w)*rd; gl_FragColor.xyz=vec3(.8,.8,1)/6; float t=0.,d=0.; for(int i=0;i<100;++i) diff --git a/tests/real/orchard.frag.expected b/tests/real/orchard.frag.expected index 82471925..3f51992c 100644 --- a/tests/real/orchard.frag.expected +++ b/tests/real/orchard.frag.expected @@ -279,7 +279,7 @@ void mainImage(out vec4 fragColour,vec2 fragCoord) #endif vec3 seedDir=normalize(vec3(0,0,1)); - seedDir*=viewMat(uv.y+sin(time*.5)*.4,uv.x+time*.5); + seedDir=viewMat(uv.y+sin(time*.5)*.4,uv.x+time*.5)*seedDir; vec3 rd=seedDir,col=vec3(0),sky=mix(vec3(FOG_COLOUR),vec3(0,.4,.6),abs(rd.y)); float alpha=marchScene(camera,rd,fragCoord); vec4 mat; diff --git a/tests/unit/inline.no.expected b/tests/unit/inline.no.expected index 6400c5ce..64dfc981 100644 --- a/tests/unit/inline.no.expected +++ b/tests/unit/inline.no.expected @@ -4,7 +4,7 @@ float result; void main() { float x=.5; - x*=.6*x; + x=.6*x*x; result=x; } int arithmetic()