GCC beaten by ICC in stupid trig test!
Scott Robert Ladd
coyote@coyotegulch.com
Mon Mar 15 01:31:00 GMT 2004
Andrew Pinski wrote:
>
> On Mar 14, 2004, at 15:39, Scott Robert Ladd wrote:
>
>> Hello,
>>
>> Consider the following program, compiled and run on a Pentium 4
>> (Northwood) system:
>>
>> #include <math.h>
>> #include <stdio.h>
>>
>> double doit(double a)
>> {
>> double s = sin(a);
>> double c = cos(a);
>>
>> // should always be 1
>> return s * s + c * c;
>> }
>>
>> int main(void)
>> {
>> double a = 1.0, r = 0.0;
>>
>> for (int i = 0; i < 100000000; ++i)
>> r += doit(a);
>>
>> printf("r = %f\n",r);
>> return 0;
>> }
>>
>
> The point here if you know that it is 1.0 then just return 1.0 instead
> of trying to play tricks with trig functions.
Don't be so damned insulting.
This is a simple example program meant tio demonstrate a problem in GCC
code generation. You know -- providing a simple piece of code that
focuses on the problem, rather than presenting a thousand-line program.
The reason doit returns 1 is so that the optimizers don't eliminate the
code entirely. If doit() merely computes sin and cos, and returns
nothing, it is compiled to nothing. Thus the return value to force code
generation. By using the sine/cosine relationship, to prove that the
function correctly computed the two values.
--
Scott Robert Ladd
Coyote Gulch Productions (http://www.coyotegulch.com)
Software Invention for High-Performance Computing
More information about the Gcc
mailing list