Hacker News new | past | comments | ask | show | jobs | submit login

> this is likely why the compiler doesn't generate SIMD instructions to compute the sum!

Isn't this the type of thing ffast-math is supposed to enable?






-ffast-math can be read as -fwrong-math if the accuracy if the answers matters. For some applications accuracy might not matter much. But the differences you get by pretending that floating point math is associative can be enormous, and scientific and engineering code is often carefully designed to take the likely scale of values into account, and rearranging it is not a good idea.

For code that's been explicitly manually optimized already, indeed you wouldn't want to turn on -ffast-math; and I'd hope anyone who has actually learned what benefits from manual optimization and how to properly do that would also at some point have read something about not coupling that with -ffast-math. But I really doubt such meaningfully-manually-optimized code is at all frequent, and where it isn't it's a rather simple improvement (potentially with using some subset flags to allow NaN or infinity if desired).

Assuming associativity is not anti-accuracy in general, it just gets in the way of certain clever algorithms.

Rearranging, like sorting before, is actually a good idea to minimize errors.

Fast math does a lot of risky things in addition to using basic math rules.

Maybe the “fun safe math” flag could be used?



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: