lists.zerezo.com
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
***BOGO*** Re: [Mingw-users] GCC 4.3.0 20080502 (alpha) Released - Please help us test it!
- Date: Sat, 10 May 2008 15:07:53 +0000 (UTC)
- From: Stéphane Larouche <stephane.larouche@xxxxxxxxxx>
- Subject: ***BOGO*** Re: [Mingw-users] GCC 4.3.0 20080502 (alpha) Released - Please help us test it!
Aaron W. LaFramboise <aaron77thyme@...> writes:
> This is a problem in general on i386 due to the way that relatively
> simple operations (such as assignment) can cause the fp size to change.
> This is a very difficult problem to solve, and is present in most
> compilers based on i386 chips. The best workaround is careful coding to
> avoid inadvertent sensitivity or instability.
This is no really a problem for me, for all practical purposes the result is the
same, the difference being very small. But it still puzzles me who thought
computers provided a single answer when given the same set of commands.
> > I will try to find some time during the weekend to generate a
> > minimal example that reproduces the problem.
>
> Please let me know how this goes for you.
The difference seems to be related, in part, to the use of complex numbers.
Here's some (quite stupid) code:
---------- Beginning of test.cpp ----------
#include <cstdio>
#include <cmath>
#include <ctime>
#include <complex>
using namespace std;
const complex<double> j = complex<double>(0.0, 1.0);
int main ()
{
long i, nb = 10000000;
complex<double> x, answer = 1.0;
clock_t start, end;
start = clock();
for(i = 0; i < nb; i++)
{
x = double(i)/double(nb) * M_PI - j * double(i)/double(nb) * M_PI;
answer *= sin(x)*sin(x) + cos(x)*cos(x);
}
end = clock();
printf("Answer: %.16f + %.16fj\n", real(answer), imag(answer));
printf("number of clock ticks: %i\n", end-start);
}
---------- End of test.cpp ----------
I compile it using:
g++ -c test.cpp
g++ -o test.exe test.o
The number of clock ticks is:
- GCC 3.4.5: 77481
- GCC 4.2.1-dw2: 85532
- GCC 4.3.0 alpha: 86995
If I add the -O3 flag, the number of clock ticks is:
- GCC 3.4.5: 75168
- GCC 4.2.1-dw2: 36792
- GCC 4.3.0 alpha: 42741
If I replace the complex<double> by double (and adjust the code consequently),
the number of clock ticks is, for all versions, approximately 17200 when using
no flags, and approximately 8600 when using the -O3 flag.
I'll continue investigating since this explains why 4.3.0 alpha is slower than
4.2.1, but not why it is slower than 3.4.5 when using the -O3 flag.
I hope this helps,
Stéphane
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users