Re: Idiotic benchmark

From: Anatoly Vorobey (avorobey_at_nonexisting.hamakor.org.il)
Date: Mon 08 Aug 2005 - 21:48:40 IDT


On Mon, Aug 08, 2005 at 09:30:18PM +0300, Shachar Shemesh wrote:
> Actually, something extremely weird it going on here. The result change,
> considerably, when I compile with or without "no-math-errno":

Yeah. The no-math-errno thing seems to trigger quite a few FPU-related
optimizations.

> >sun_at_sunlap:/tmp$ gcc -O2 -fno-math-errno -o test -lm test.c && time ./test
> >nan
> >
> >real 0m7.521s
> >user 0m7.517s
> >sys 0m0.003s
>
> Why did the answer turn into "nan"?

Because the variable q is garbage when the loop starts, and ends up
being either garbage or overflown. Without -fno-math-errno, it's
initialised to 0 before the loop begins. If you declare it with
double q = 0;, you will get a meaningful answer in the -fno-math-errno
case as well.

The compiler isn't at fault here because it doesn't have to initialize it
for you.

-- 
avva
"There's nothing simply good, nor ill alone" -- John Donne
=================================================================
To unsubscribe, send mail to linux-il-request_at_linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request_at_linux.org.il


This archive was generated by hypermail 2.1.7 : Mon 08 Aug 2005 - 22:06:22 IDT