Re:Optimizations Enabled by -ffast-Math
by billfruit on Wednesday October 20, 2021 @12:30PM
(#28932684)
Is it adviced to detect overflow and do something about it after an FP computation rather than adding pre-checks to try to avert the overflow?
[ Parent
| on HN ]
Re:Optimizations Enabled by -ffast-Math
by owlbite on Wednesday October 20, 2021 @12:44PM
(#28932861)
So it depends on how you want to detect overflow.
Trapping on math exceptions or otherwise pulling an emergency break doesn't really fit with modern hardware design if you want performance (for one thing, what do you do with the rest of your vector? do you just live with a pipeline flush?).
Adding targeted checks used sparingly can work, but probably requires a deeper understanding of the underlying numerical analysis of your problem. Generally just checking for NaN or Inf at the end is a better solution as these are in most cases absorbing states.
Re:Optimizations Enabled by -ffast-Math
by KarlKemp on Wednesday October 20, 2021 @02:07PM
(#28933890)
The only obvious way to test if some operation is going to produce some value(s) is to perform that operation. Yes, for, say, a single multiplication I can anticipate the necessary bounds for each input value. But even short sequences of operations would quickly devolve into labyrinthine nested switch statements.