gccgcc4fast-math

What exactly -ffast-math option does while compiling with gcc


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


Solution

  • 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?

    In short, it allows the compiler to optimize your program at the cost of losing standard compliance and some safety.