This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC viciously beaten by ICC in trig test!

On Sun, 14 Mar 2004, Scott Robert Ladd wrote:
> Consider the following program, compiled and run on a Pentium 4
> (Northwood) system:
>      #include <math.h>

For a number of benchmarks, just this first line of source code above
is enough to loose the race for GCC against Intel when compiling on Linux.

Consider the following:

	#include <math.h>

	double doit(double a)
	  return sin(a) * sin(a);

Compiling with gcc -O2 -ffast-math on Linux generates x86 code that's
significantly slower than Intel's compiler output.  However, commenting
out the "#include <math.h>" corrects the situation and GCC can then
generate *exactly* the same sequence as icc.

The issue is that glibc's headers provide inline implementations for sin
and cos, and thereby override all of GCC's internal builtin processing.
Once this is done, there's nothing tree-ssa, the middle-end or the i386
can do to improve the code.  If GCC is to have a hope of using "sincos"
or SSE2 specific instruction sequences, the "best intentions" of glibc's
headers (will) have to be neutralized first.  Perhaps fixincludes :>

For the interested with "#include <math.h>" GCC 3.3.3 generates

foo:    fldl    4(%esp)
        fld     %st(0)
        fxch    %st(1)
        fmulp   %st, %st(1)

without it, the same "-O2 -ffast-math -fomit-frame-pointer" options'
output is identical to the output from Intel v7.0 (and presumably later).

foo:    fldl    4(%esp)
        fmul    %st(0), %st

Just another data point.  Avoiding <math.h> may improve your performance
and influence the results of your "command line option" experiments.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]