Can any one help in making me understand what does -ffast-math option does when compiled with gcc. I see a difference of 20 sec in my programs execution time when executed with -O3 and -ffast-math compared to only use of -O3
Asked
Active
Viewed 6,815 times
1 Answers
16
Why not read the gcc man page, it's your friend as well as mine. Here's what it told me:
Sets -fno-math-errno, -funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and -fcx-limited-range.
So it doesn't do anything interesting by itself, but is just a shorthand to several more interesting compiler options. What do the individual flags do?
fno-math-errno
makes single-instruction math operations not setERRNO
funsafe-math-optimizations
allows math optimizations that assume valid arguments and can violate ANSI and IEEE standards (caution, not actually fun and safe)ffinite-math-only
, likewise, allows math optimizations that assume that any floating point values are neither infinite norNaN
fno-rounding-math
andfno-signaling-nans
are actually on by default. Their oppositesfrounding-math
andfsignaling-nans
disable some potentially unsafe/unportable optimizations.fcx-limited-range
allows the compiler to not do certain complex number arithmetic checks. Not likely to impact your program unless you're actually working with complex numbers!
In short, it allows the compiler to optimize your program at the cost of losing standard compliance and some safety.

kviiri
- 3,282
- 1
- 21
- 30