compiler performance
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Wed Feb 11 22:47:00 GMT 2004
> also, his trig loop looks like this:
>
> while (i < trigMax)
> {
> sine = sin(i);
> cosine = cos(i);
> tangent = tan(i);
> logarithm = log10(i);
> squareRoot = sqrt(i);
> i++;
> }
>
> an optimizer might know that these functions don't have any
> side-effects, so most of the computations can be eliminated, and
> then the whole loop can be eliminated. I'm guessing the abnormally
> fast timings he got from the Microsoft compilers is because they
> eliminated most of that loop, but it could easily be something else
> I don't know about.
GCC 3.3.x knows some of these trig functions don't have side effects.
In GCC 3.4 all the math functions (including the C99 ones) are
appropriately marked. So GCC 3.4 could possibly zap most (all?) of
the loop too, (but I haven't checked.)
However for maximum benefit (regardless of gcc version) you really
need to use -ffast-math. E.g. if a math function (like sqrt) can
write to `errno' that is considered a side-effect unless you instruct
gcc to ignore that. (See gcc/builtins.def for details.)
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu
More information about the Gcc
mailing list