public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* optimisation -O1 changes floating-point results
@ 2013-12-18 14:23 Diggory Hardy
  2013-12-18 15:03 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Diggory Hardy @ 2013-12-18 14:23 UTC (permalink / raw)
  To: gcc-help

Dear list,

I am using GCC to compile some modeling software (C++; 
http://code.google.com/p/openmalaria/). This uses quite a lot of "double"s and 
results can be quite sensitive to the exact outcomes of floating-point 
operations (this is due to stochastic influences, and only really a concern 
since we want to be able to reproduce results independent of the hardware/OS 
used).

Anyway, on 32-bit Linux (Ubuntu 12.04 with the default GCC 4.6.3) some of my 
test cases generated different results when optimisation is enabled. (This 
doesn't happen on 64-bit Linux (identical Ubuntu/GCC versions) or our Windows 
or Mac builds.)

On 32-bit linux results are as expected with no optimisation, but different 
when -O1 (or 2 or 3) is used, _however_, enabling all of the same optimisation 
flags (either as listed in the man page or as given by `gcc -O -Q --
help=optimizers`) (without listing -O) still produces different results.

Is this a known issue?

Is it the same with later GCC versions?

Is there a way I can turn on most optimisations while still getting exactly 
the same results as without optimisation?

Cheers,

Diggory Hardy

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

* Re: optimisation -O1 changes floating-point results
  2013-12-18 14:23 optimisation -O1 changes floating-point results Diggory Hardy
@ 2013-12-18 15:03 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2013-12-18 15:03 UTC (permalink / raw)
  To: Diggory Hardy, gcc-help

On 12/18/2013 03:23 PM, Diggory Hardy wrote:

> Is this a known issue?

Yes, it's the excess precision problem on i386:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323

> Is it the same with later GCC versions?

GCC 4.5 has some fixes.

> Is there a way I can turn on most optimisations while still getting exactly
> the same results as without optimisation?

You could compile with -mfpmath=sse -msse2, or you could set the 
floating point control word to restrict precision to 53 bits.  The 
latter will cover doubles only, the issue can still surface with floats.

-- 
Florian Weimer / Red Hat Product Security Team

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

end of thread, other threads:[~2013-12-18 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-18 14:23 optimisation -O1 changes floating-point results Diggory Hardy
2013-12-18 15:03 ` Florian Weimer

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