4 ms·
> 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?
by RobotToaster 2y ago
> 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?
- not2b 2y ago-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.
- Dylan16807 2y agoAssuming associativity is not anti-accuracy in general, it just gets in the way of certain clever algorithms.
- dzaima 2y agoFor 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).
- rurban 2y agoRearranging, like sorting before, is actually a good idea to minimize errors.
- Dylan16807 2y agoFast math does a lot of risky things in addition to using basic math rules.
- bee_rider 2y agoMaybe the “fun safe math” flag could be used?