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; 116+ 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] 116+ messages in thread
* Re: GCC beaten by ICC in stupid trig test!
@ 2004-03-15 16:06 Robert Dewar
  2004-03-16  8:45 ` Per Abrahamsen
  2004-03-16 12:14 ` Scott Robert Ladd
  0 siblings, 2 replies; 116+ messages in thread
From: Robert Dewar @ 2004-03-15 16:06 UTC (permalink / raw)
  To: coyote, pinskia; +Cc: gcc

> 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.

optimziations like this are inappropriate in my view. We are dealing
with floating-point not real arithmetic.

Indeed if any programmer writes sin**2+cos**2, one can assume that the
intention is precisely to get the computed value that may not be 1.0. If
the programmer wants 1.0, they can write it explicitly!

^ permalink raw reply	[flat|nested] 116+ messages in thread
* Re: GCC beaten by ICC in stupid trig test!
@ 2004-03-24 19:04 Bradley Lucier
  2004-03-24 19:29 ` Joe Buck
  0 siblings, 1 reply; 116+ messages in thread
From: Bradley Lucier @ 2004-03-24 19:04 UTC (permalink / raw)
  To: joe.buck
  Cc: roger, gdr, gcc, abraham, Bradley Lucier, gcc-patches, toon,
	laurent, fjahanian

Re:

> On Tue, Mar 23, 2004 at 10:32:13PM -0500, Robert Dewar wrote:
> > For example, if -ffast-math is so sloppy as to consider
> > that (a+b)+c can be replaced by a+(b+c), then all bets are off.
>
> That's why -ffast-math doesn't do that; such a transformation would be
> massively brain-damaged.

Well, -ffast-math (or more specifically, -funsafe-math-optimizations) 
is about to do this, at least in some cases on tree-ssa, see

http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01891.html

If you think that this transformation shouldn't be done, then I guess 
now is the time to speak up.

Brad

^ permalink raw reply	[flat|nested] 116+ messages in thread
* Re: GCC beaten by ICC in stupid trig test!
@ 2004-03-25 16:51 Wolfgang Bangerth
  0 siblings, 0 replies; 116+ messages in thread
From: Wolfgang Bangerth @ 2004-03-25 16:51 UTC (permalink / raw)
  To: gcc
  Cc: Roger Sayle, Robert Dewar, Bradley Lucier, Toon Moene,
	Scott Robert Ladd, gcc, gcc-patches


Roger Sayle wrote:
> I've heard it argued that people who are serious about floating point
> don't use -ffast-math.  I consider myself serious, and make a very nice
> living from selling software to solve finite-difference Poison-Boltzmann
> electrostatic calculations on regular grids, and molecular minimizations
> using quasi-newtonian numerical optimizers.  Toon does numerical weather
> forecasting, and he seems happy with -ffast-math.  Laurent performs large
> scale Monte-Carlo simulations, and he also seems happy with it.

I would like to add to this one more voice. We distribute our finite element 
code for some 5 years now, with >200 downloads a month. We haven't, ever, 
heard someone complain that we include -ffast-math in our flags for optimized 
builds. I have also not ever heard someone in the finite element community 
think about the effects of correctly treating NaN etc (if your PDE simulator 
generates NaNs, then you have a bug), or worrying about the order of 
execution of a+b+c. In fact, I most often use parenthesis to make code more 
readable, and never to force the order of evaluation in a+b+c. If you start 
to worry whether a+b+c is different than a+c+b, then a simulator must be so 
instable that any prediction it gives must necessarily be almost useless.

Frankly, it makes me angry if people here keep repeating that "any 
self-respecting numerical programmer can't possibly use -ffast-math and must 
necessarily know and care which way a+b+c is evaluated". I claim that this 
is, in almost all cases, wrong. This view is anal, I can't track the order of 
evaluation of operands in a program or a quarter million LOC. Please stop 
asserting these things.

If it were for me, then we should make -ffast-math the default with -O2, and 
allow for reassociating arguments by default. If by things like fused 
multiply-add we can save another 10%, then that's almost one day off my 
week-long computations! Those few who do care about these things are free to 
use the respective flags.

W.

-------------------------------------------------------------------------
Wolfgang Bangerth              email:            bangerth@ices.utexas.edu
                               www: http://www.ices.utexas.edu/~bangerth/

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

end of thread, other threads:[~2004-03-27  0:40 UTC | newest]

Thread overview: 116+ 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 16:06 GCC beaten by ICC in stupid " Robert Dewar
2004-03-16  8:45 ` Per Abrahamsen
2004-03-17  0:09   ` Robert Dewar
2004-03-17  0:36     ` Scott Robert Ladd
2004-03-17  5:53     ` Gabriel Dos Reis
2004-03-17  7:21       ` Robert Dewar
2004-03-17  9:10         ` Gabriel Dos Reis
2004-03-21 16:55           ` Robert Dewar
2004-03-23 19:38       ` Joe Buck
2004-03-23 19:58         ` Gabriel Dos Reis
2004-03-23 20:49           ` Laurent GUERBY
2004-03-24  8:17             ` Toon Moene
2004-03-24 13:50               ` Robert Dewar
2004-03-24 18:25                 ` Paul Koning
2004-03-24 18:51                   ` Robert Dewar
2004-03-25 18:18                     ` Per Abrahamsen
2004-03-27  1:26                       ` Robert Dewar
2004-03-24 18:56                 ` Joe Buck
2004-03-24 19:10                   ` Robert Dewar
2004-03-24 19:14                     ` Richard Guenther
2004-03-24 19:39                       ` Paul Brook
2004-03-24 19:45                         ` Dave Korn
2004-03-24 20:57                           ` Paul Brook
2004-03-25  6:14                           ` Robert Dewar
2004-03-25 18:32                             ` Scott Robert Ladd
2004-03-27  1:28                               ` Robert Dewar
2004-03-17 14:51     ` Per Abrahamsen
2004-03-17 15:18       ` Gabriel Dos Reis
2004-03-17 16:05         ` Per Abrahamsen
2004-03-16 12:14 ` Scott Robert Ladd
2004-03-17  0:19   ` Robert Dewar
2004-03-24 19:04 Bradley Lucier
2004-03-24 19:29 ` Joe Buck
2004-03-24 19:43   ` Bradley Lucier
2004-03-24 19:50     ` Joe Buck
2004-03-24 23:48       ` Toon Moene
2004-03-25  0:02         ` Toon Moene
2004-03-25  0:11           ` Roger Sayle
2004-03-25  5:56             ` Scott Robert Ladd
2004-03-25  6:07             ` Bradley Lucier
2004-03-25  8:18             ` Robert Dewar
2004-03-25 16:15               ` Roger Sayle
2004-03-25 16:36                 ` David Edelsohn
2004-03-25 17:09                   ` Scott Robert Ladd
2004-03-25 17:47                     ` David Edelsohn
2004-03-25 18:03                       ` Scott Robert Ladd
2004-03-26  1:29                 ` Toon Moene
2004-03-27  0:23                 ` Daniel Egger
2004-03-27  0:50                 ` Laurent GUERBY
2004-03-27  0:55                   ` Joe Buck
2004-03-27  0:58                     ` Laurent GUERBY
2004-03-27  1:16                       ` Joe Buck
2004-03-25  5:36         ` Gabriel Dos Reis
2004-03-25  8:46           ` Robert Dewar
2004-03-25  5:34       ` Gabriel Dos Reis
2004-03-25  7:24       ` Robert Dewar
2004-03-25  8:28         ` Gabriel Dos Reis
2004-03-25 18:19       ` Per Abrahamsen
2004-03-24 20:14   ` Paul Koning
2004-03-24 21:00     ` Joe Buck
2004-03-24 22:20       ` Dale Johannesen
2004-03-24 21:07     ` Joseph S. Myers
2004-03-24 21:38       ` Joe Buck
2004-03-24 21:44       ` Joe Buck
2004-03-24 22:49         ` Joseph S. Myers
2004-03-24 22:19       ` Richard Guenther
2004-03-24 22:21         ` Dale Johannesen
2004-03-25  7:29     ` Robert Dewar
2004-03-25 16:51 Wolfgang Bangerth

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).