Why is mandatory to use -ffast-math
with g++ to achieve vectorization of loop using doubles? I don't like ffast-math because I don't want to loose precision.
views:
193answers:
1Very likely because vectorization means that you may have different results, or may mean that you miss floating point signals/exceptions.
If you're compiling for 32 bit x86 then gcc and g++ default to using the x87 for floating point math, on 64 bit they default to sse, however the x87 can and will produce different values for the same computation so it's unlikely g++ will consider vectorizing if it can't guarantee that you will get the same results unless you use -ffast-math or some of the flags it turns on.
Basically it comes down to the floating point environment for vectorized code may not be the same as the one for non vectorized code, sometimes in ways that are important, if the differences don't matter to you, something like
-fno-math-errno -fno-trapping-math -fno-signaling-nans -fno-rounding-math
but first look up those options and make sure that they won't affect your program's correctness. -ffinite-math-only
may help also