Re: Program that segfaults with -Ofast

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/01/18 14:09, Mason wrote:
> On 05/01/2018 12:58, Christer Solskogen wrote:
> 
>> I'm not sure why the developer chose -Ofast. It was not my decision.
> 
> When the dust settles, I think he should "revert" to -O3, or even to -O2.
> 

"-Ofast" is (as far as I can see from the docs) the same as "-O3
-ffast-math" (plus a few other options for Fortran).

Usually, -O3 should be used only after testing - compared to -O2, it can
make code significantly bigger and reduce speed because of that (more
cache misses, etc.).  Whether -O3 is faster or slower than -O2 will
depend on the code and the target system.

However, -ffast-math is fine for most code.  It tells the compiler that
you don't need bit-perfect IEEE floating point compatibility - that your
real number mathematics is with normal numbers, not infinities, NaNs,
etc., and that you are happy with "obvious" optimisations.  It lets the
compiler treat floating point as distributive, commutative and
associative just like normal mathematics.  It lets the compiler change
"x / 3.0" into "x * 0.33333333333333".  On most systems, it will
significantly speed up floating point calculations - on some (like
embedded systems with no or limited hardware floating point) it will
/massively/ speed up floating point calculations.

If you are the kind of person that likes to read Annex F of the C
standards, and #include's <fenv.h> in your code, then you don't want
-ffast-math.  For the rest of us, -ffast-math is definitely a flag you
want enabled.

And unless the documentation of -Ofast is missing important details,
-Ofast is therefore fine whenever -O3 is fine.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux