4 ms·
This transformation is only legal if order of summation doesn't matter. So the compiler can do it for ints, but not floats.
by im3w1l 2y ago
This transformation is only legal if order of summation doesn't matter. So the compiler can do it for ints, but not floats.
- vlovich123 2y agoApplying std::reduce to floats would be a similarly bad idea for having the compiler do it, except people will write it without thinking. Of course, people always struggle with writing correct floating point so I doubt it makes things better or worse, but it’s conceptually the library equivalent of -fast-math (which coincidentally would also auto-vectorize the loop but can impact more than just that).
- im3w1l 2y agoUsing fast math in one particular expression is way different and less risky than doing it globally.