public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC viciously beaten by ICC in trig test!
@ 2004-03-14 23:40 Scott Robert Ladd
  2004-03-14 23:49 ` Gabriel Dos Reis
                   ` (3 more replies)
  0 siblings, 4 replies; 74+ messages in thread
From: Scott Robert Ladd @ 2004-03-14 23:40 UTC (permalink / raw)
  To: gcc

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;
     }

Using both GCC 3.3.3 and Intel C++ 8.0, I compiled the above with these 
command lines:

     gcc -o sincosg -lm -std=gnu99 -O3 -march=pentium4 \
            -mfpmath=387 -ffast-math -fomit-frame-pointer sincos.c

     icc -o sincosi -lm -O3 -xN -tpp7 -ipo sincos.c

Both programs produce the correct result. The run times, measured with 
the time command, were:

     0.2s  ICC
    12.8s  GCC (!!!!!)

Very ugly, from the perspective of GCC. I also compiled with 
recently-acquired-from-CVS builds of 3.4.0 and tree-ssa, for good 
measure and with no improvement in performance.

This is a killer issue on certain applications that I run, in which 
trigonometric functions play a crucial role.

Examining the generated assembler source shows that Intel eliminates the 
  function call to "doit()" entirely, replacing it with inline code that 
calls internal functions such as vmldSin2 and vmldCos2, while it's 
actual compilation of doit() uses the SSE2 sincos instruction, whereas 
GCC generates calls to the 387 instructions fsin and fcos.

I have found taht ICC wins any contest in which trigonometric functions 
play a significant role; even in the most complex code (which can not be 
inlined), ICC wins by a factor of 3 to 1 in computational speed.

Can GCC generate faster code for trigonometric code? Options that I 
tried (with no useful effect) include:

     -mfpmath=sse
     -mfpmath=387
     -mfpmath=387,sse
     -msse	(implied by -march=pentium4, but tested anyway)
     -msse2	(implied by -march=pentium4, but tested anyway)

I look forward to illumination (or at least some bright ideas!)

..Scott

-- 
Scott Robert Ladd
Coyote Gulch Productions (http://www.coyotegulch.com)
Software Invention for High-Performance Computing

^ permalink raw reply	[flat|nested] 74+ messages in thread
* Re: GCC viciously beaten by ICC in trig test!
@ 2004-03-15  3:19 Stephan T. Lavavej
  2004-03-15  3:29 ` Gabriel Dos Reis
  2004-03-15 17:42 ` Joe Buck
  0 siblings, 2 replies; 74+ messages in thread
From: Stephan T. Lavavej @ 2004-03-15  3:19 UTC (permalink / raw)
  To: GCC

[Scott Robert Ladd]
> Sometimes, I wonder if GCC should ship its own Standard C
> library, just as it ships a Standard C++ template library.
> However, I suspect the suggesting such a move might be a bit
> controversial... ;)

Why doesn't it?

On MinGW, you can't use %lld with printf(), because MSVCRT doesn't
understand it properly.  If GCC provided its own Standard C library, that'd
be awesome.

Stephan T. Lavavej
http://nuwen.net



^ permalink raw reply	[flat|nested] 74+ messages in thread
* Re: GCC viciously beaten by ICC in trig test!
@ 2004-03-17  0:31 Stephan T. Lavavej
  2004-03-17  3:30 ` Ian Lance Taylor
  0 siblings, 1 reply; 74+ messages in thread
From: Stephan T. Lavavej @ 2004-03-17  0:31 UTC (permalink / raw)
  To: GCC

[Scott Robert Ladd]
> Sometimes, I wonder if GCC should ship its own Standard C
> library, just as it ships a Standard C++ template library.
> However, I suspect the suggesting such a move might be a bit
> controversial... ;)

[Stephan T. Lavavej]
> Why doesn't it?

[Gabriel Dos Reis]
> This is a tricky issue. Some standards (e.g. POSIX) make
> conflicting requirements to that of ISO C standard,

[Kai Henningsen]
> Actually, POSIX takes great pains to *NOT* do that.

[Gabriel Dos Reis]
> and as a matter of fact demand that the C standard headers be
> modified.

[Kai Henningsen]
> Actually, POSIX says that any differences are dependant on
> prior definition of a preprocessor symbol in the
> implementation namespace. I believe this strategy was chosen
> with advice from the C standards committee.

[Gabriel Dos Reis]
> If GCC/gcc had to come with its own C headers, then it would
> have to implement those standards too -- in order to comply
> with user expectations.
> That is a mess and GCC has better not drive into that.

[Kai Henningsen]
> Actually, it seems that would be vastly cleaner than the
> contortions libstdc++ goes through. (And it would many such
> contortions unnecessary, as libstdc++ could count on support
> from libc.)

Great!

> The *real* problem is that available infrastructure between
> different OSes can differ just as much as different CPUs do,
> meaning you need a libc backend like you need the gcc
> backend. That is nontrivial.

Well, of course there would have to be vastly different implementations for
Windows versus GNU/Linux versus whatever other horrible operating systems
gcc runs on.  But gcc already uses the "separate implementation for
everything" approach with different processors.

If gcc were unified with a C library, it seems like things would be a lot
simpler, not only for libstdc++ and the rest of the compiler, but for users
with lousy C libraries supplied by their vendors.

[Kai Henningsen]
> really, binutils belongs with gcc more than glibc does.

And why isn't binutils part of gcc, for that matter?

Stephan T. Lavavej
http://nuwen.net



^ permalink raw reply	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2004-03-17  3:00 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-14 23:40 GCC viciously beaten by ICC in trig test! Scott Robert Ladd
2004-03-14 23:49 ` Gabriel Dos Reis
2004-03-15  1:47   ` Scott Robert Ladd
2004-03-15  0:11 ` Paolo Carlini
2004-03-15  1:47   ` Scott Robert Ladd
2004-03-15  2:07     ` Daniel Berlin
2004-03-15  2:30       ` Scott Robert Ladd
2004-03-15  2:31         ` Daniel Berlin
2004-03-15  2:38           ` Scott Robert Ladd
2004-03-15 10:00             ` Sebastian Pop
2004-03-15  0:12 ` GCC beaten by ICC in stupid " Andrew Pinski
2004-03-15  0:32   ` Paolo Carlini
2004-03-15  1:31   ` Scott Robert Ladd
2004-03-15  2:36   ` Scott Robert Ladd
2004-03-15 11:25   ` Paolo Carlini
2004-03-15 11:31     ` Paolo Carlini
2004-03-15 13:29     ` Zdenek Dvorak
2004-03-15 13:42       ` Paolo Carlini
2004-03-15 13:51         ` Zdenek Dvorak
2004-03-15 13:55           ` Paolo Carlini
2004-03-15 14:00             ` Zdenek Dvorak
2004-03-15 14:05           ` Joseph S. Myers
2004-03-15 14:13             ` Paolo Carlini
2004-03-15 14:18               ` Zdenek Dvorak
2004-03-15 14:29                 ` Segher Boessenkool
2004-03-15 14:28               ` Joseph S. Myers
2004-03-15  1:55 ` GCC viciously beaten by ICC in " Roger Sayle
2004-03-15  2:22   ` Dan Nicolaescu
2004-03-15 12:05     ` Stelios Xanthakis
2004-03-15 18:22       ` Dan Nicolaescu
2004-03-15  2:41   ` Kaveh R. Ghazi
2004-03-15  6:06     ` Andreas Jaeger
2004-03-15  8:57       ` Gabriel Dos Reis
2004-03-15  2:41   ` Scott Robert Ladd
2004-03-15  3:05     ` Gabriel Dos Reis
2004-03-15 14:47       ` Segher Boessenkool
2004-03-15 17:44         ` Geert Bosch
2004-03-15 17:46           ` Geert Bosch
2004-03-15  3:01   ` Gabriel Dos Reis
2004-03-15  4:06     ` Scott Robert Ladd
2004-03-15  5:15   ` James Morrison
2004-03-15  8:20     ` Jakub Jelinek
2004-03-15 18:13       ` Joe Buck
2004-03-16 13:31         ` Jakub Jelinek
2004-03-15  7:42   ` Ranjit Mathew
2004-03-15 19:00   ` Toon Moene
2004-03-15 19:44     ` Laurent GUERBY
2004-03-15  3:19 Stephan T. Lavavej
2004-03-15  3:29 ` Gabriel Dos Reis
2004-03-15 12:40   ` Scott Robert Ladd
2004-03-15 12:53     ` Gabriel Dos Reis
2004-03-15 13:37       ` Scott Robert Ladd
2004-03-15 15:11     ` Ian Lance Taylor
2004-03-15 16:25       ` Stephan T. Lavavej
2004-03-15 16:40         ` Jakub Jelinek
2004-03-15 16:46         ` Ian Lance Taylor
2004-03-15 16:56           ` Paolo Carlini
2004-03-15 17:10             ` Gabriel Dos Reis
2004-03-15 17:15               ` Paolo Carlini
2004-03-15 17:58                 ` Gabriel Dos Reis
2004-03-15 16:59           ` Gabriel Dos Reis
2004-03-15 17:28             ` Ian Lance Taylor
2004-03-15 17:47               ` Gabriel Dos Reis
2004-03-15 17:52               ` Joe Buck
2004-03-15 17:53               ` Phil Edwards
2004-03-15 17:45     ` Joe Buck
2004-03-15 19:50       ` Scott Robert Ladd
2004-03-16  1:00     ` Zack Weinberg
2004-03-17  0:07       ` Kai Henningsen
2004-03-16 23:12   ` Kai Henningsen
2004-03-17  3:00     ` Ian Lance Taylor
2004-03-15 17:42 ` Joe Buck
2004-03-17  0:31 Stephan T. Lavavej
2004-03-17  3:30 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).