Related articles |
---|
Common subexpression analysis mernst@theory.lcs.mit.edu (1992-06-03) |
Re: Common subexpression analysis msharp@cs.ulowell.edu (1992-06-04) |
Re: Common subexpression analysis preston@dawn.cs.rice.edu (1992-06-04) |
Common subexpression analysis (summary) mernst@theory.lcs.mit.edu (1992-06-26) |
Re: Common subexpression analysis (summary) Bruce.Hoult@bbs.actrix.gen.nz (1992-07-13) |
Re: Common subexpression analysis f88ho@efd.lth.se (1992-07-14) |
Newsgroups: | comp.compilers |
From: | f88ho@efd.lth.se (Hans Olsson) |
Organization: | Lund Institute of Technology, Sweden |
Date: | Tue, 14 Jul 1992 08:53:59 GMT |
References: | 92-06-135 92-07-028 |
Keywords: | optimize |
Bruce.Hoult@bbs.actrix.gen.nz writes:
[Original article deleted]
>Why didn't you do strength reduction while you were at it?
>
> r2 = r*r;
> x2 = x*x;
> y2 = y*y;
> while (y >= 0)
> if (x2 + y2 > r2)
> --y, y2 -= y+y-1;
> else
> ++x, x2 += x+x+1;
Or somewhat better:
..
if (x2+y2 > r2)
y2-=y, --y, y2-=y;
else
x2+=x, ++x, x2+=x;
Or even better:
goto L0;
L2:
if (x2+y2>r2) goto L3;
x2+=x;
x++;
x2+=x;
goto L2;
L3:
y2-=y;
--y;
y2-=y;
L0:
if (y>=0) goto L2;
(I hope I got it right. The basic idea is that it's a waste of time
to test if y>=0 if y hasn't changed).
>
>
>... or even go whole hog and do...
>
> t = x*x + y*y - r*r;
> x2 = x+x+1;
> y2 = y+y-1;
> while (y2 >= 0)
Should read:
while (y2 >= -1)
> if (t > 0)
> y2 -= 2, t -= y2;
> else
> x2 += 2, t += x2;
>
>
>I'll bet if there are any compilers that can do this, they're probably
>for FORTRAN :-)
Probably true.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.