floating point inconsistency
Christoph Groth
cwg@falma.de
Tue Feb 16 08:35:00 GMT 2010
Thank you for your reply, Neil.
Neil Ferguson <nferguso@eso.org> writes:
> Christoph Groth wrote:
>
> <snipped inconsistent floating point results>
>
>> This is on a computer with an Intel Core 2 CPU (I tried several
>> different variants).
>>
>> If I take the second (-O1) binary and execute it on an Opteron it
>> produces the _first_ result. Thus, the same static binary produces
>> different results on different processors!
>
> This is a hardware-related effect - in a nutshell, it happens because
> Intel hardware can extend double-precision floating point operations
> to 80 bits internally, whereas AMD hardware usually enforces 64 bits
> at all times.
I am aware of the x87 80/64-bit rounding issue and the related
inconsistencies (I stumbled across them myself in due time). However,
here we're speaking of x86-64 CPUs on which gcc uses SSE for floating
point by default. Indeed, explicitly switching on SSE does not change
anything:
cwg@argo:~$ g++ -O0 -static -mfpmath=sse test.cc
cwg@argo:~$ ./a.out
0.000880416620183556821 0.000603184177834822054
0.000880416620183556821
0
cwg@argo:~$ g++ -O1 -static -mfpmath=sse test.cc
cwg@argo:~$ ./a.out
0.00088041662018355693 0.000603184177834822054
0.000880416620183556821
1.08420217248550443e-19
I assumed that no such rounding issues are supposed to happen on x86-64.
And I could live with them, if there would be not the problem of the
same static binary producing different results on core2 and opteron.
More information about the Gcc-help
mailing list