Floating point performance issue

Ico gcc@zevv.nl
Tue Dec 20 10:20:00 GMT 2011

* On Tue Dec 20 11:05:17 +0100 2011, Marcin Mirosław wrote:
> W dniu 20.12.2011 10:52, Ico pisze:

> > I am able to reproduce this on multiple i686 boxes using various gcc versions
> > (4.4, 4.6). Compiling on x86_64 does not show this behaviour.
> > 
> > Is anybody able to reproduce this issue, and how can this be explained ?
> I can reproduce such situation too. I can only guess this happens
> because on i686 default is mfpmath=387, on x86_64 default is
> mfpmath=sse. If you compile your code using "-O3 -mfpmath=sse
> -march=native <or something what else what have support for sse>" then
> booth times will be almost equal.

Thanks for testing this.

Still, I'm not sure if sse is part of the problem and/or solution.

I have been reducing the program to see what the smallest code is that still
shows this behaviour. Latest version is below. 

$ gcc -msse -mfpmath=sse -O3 -march=native test.c 
$ time ./a.out 0.9

real	0m2.653s
user	0m2.648s
sys	0m0.002s
$ time ./a.out 0.001

real	0m0.144s
user	0m0.140s
sys	0m0.002s

/* gcc -msse -mfpmath=sse -O3 -march=native test.c  */

#include <stdlib.h>

#define S 20000000
int main(int argc, char **argv)
        int j;
        double a = 0;
        double b = 1;
        double f = atof(argv[1]);

        for(j=0; j<S; j++) {
                a = b * f;
                b = a * f;

        return a;

More information about the Gcc-help mailing list