Why is it mandatory to use -ffast-math with g++ to achieve the vectorization of loops using doubles? I don’t like -ffast-math because I don’t want to lose precision.
Why is it mandatory to use -ffast-math with g++ to achieve the vectorization of
Share
You don’t necessarily lose precision with
-ffast-math. It only affects the handling ofNaN,Infetc. and the order in which operations are performed.If you have a specific piece of code where you do not want GCC to reorder or simplify computations, you can mark variables as being used using an
asmstatement.For instance, the following code performs a rounding operation on
f. However, the twof += gandf -= goperations are likely to get optimised away by gcc:On x86_64, you can use this
asmstatement to instruct GCC not to perform that optimisation:You will need to adapt this for each architecture, unfortunately. On PowerPC, use
+finstead of+x.