Den 15/07/2008 kl. 16.49 skrev Martin Geisler: > Janus Dam Nielsen <[EMAIL PROTECTED]> writes: > >> Hi again, >> >> Heres the fruit of half a days work :) >> >> Analyzing the expression: >> sint n = (a * y + (1 - a) * x); >> >> Yields the following results: >> >> Final result: >> ((a * y )+ ((1 - a )* x )) cost: 30 >> (((a * y )+ x )- (x * a )) cost: 30 >> (((a * y )+ x )- (a * x )) cost: 30 >> (((a * y )- (a * x ))+ x ) cost: 30 >> (((y * a )+ x )- (a * x )) cost: 30 >> (((y * a )+ x )- (x * a )) cost: 30 >> ((a * y )+ (x - (x * a ))) cost: 30 >> (((y * a )- (a * x ))+ x ) cost: 30 >> (((y * a )- (x * a ))+ x ) cost: 30 >> (((a * y )- (x * a ))+ x ) cost: 30 >> ((a * (y - x ))+ x ) cost: 20 >> >> And lo and behold the last line reveals that the expression >> a * (y - x )+ x >> has the lowest cost. > > That is very cool! :-) Yes and fun.
>> From the output above it seems that you have taught your analyzer > about the distributive law, that + and * are commutative. I think I have taught it most of what there is to know about commutativity for + and * and that * is distributive. I know of some corner cases that are not covered, but it is a matter of implementing them - I hope. > What about a - a == 0, and that 0 * a == 0? I don't know if those > rules will help -- they might just blow up the search space... :-) Thanks for the idea. The analyzer already knows that x * 1 == x but it is only used in the left-to-right direction. There might be some weird case where rewriting x to x * 1 might reveal more opportunities for optimizations. But until I see a concrete case I will leave it out. Similar for x -x == 0, x + 0 == x, x - 0 == x, and x * 0 == 0 I can add the rewrite from left to right. -- Janus _______________________________________________ viff-devel mailing list (http://viff.dk/) [email protected] http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk
