trying to simplify an algorithm

Hui Zhou zhouhui at wam.umd.edu
Mon Feb 28 08:57:08 PST 2005


On Mon, Feb 28, 2005 at 10:49:58AM -0500, Hui Zhou wrote:
>On Mon, Feb 28, 2005 at 09:40:20AM +0000, Johan V. wrote:
>>>>return ( a+b+c == 180 ) * (a>0) * (b>0) * (c>0) *
>>>>       ( 1 + (a==b) + (a==c) + (b==c) );

>Frankly I am not sure whether gcc will optimize away those 
>multiplications and summations. I will appreciate it if you will find 
>out and let me know.

I tried with gcc -O3. It seems gcc does the optimization I described 
above, but it still end up with more conditional jumps and an extra 
imul and a few incl than an straight forward if version.

It does a pretty good job, but we are asking too much :)

Cheers,
-- 
Hui Zhou



More information about the lfs-chat mailing list