Re:C and C++ Prioritize Performance over Correctness
by weinzierl on Friday August 18, 2023 @03:07PM
(#37180570)
Think about it like that. If you allow an exception you essentially create many branches with all their negative consequences. With the sticky bit you combine them to one branch (that is still expensive[1]).
Re:C and C++ Prioritize Performance over Correctness
by Findecanor on Friday August 18, 2023 @03:16PM
(#37180687)
> At that point overflow has already occured, so your program state is now nonsense, and you might as well just let it crash unhandled.
The trick is to check and clear the flag before any instruction that would have a side-effect, that depends on the arithmetic result.
IEEE 754-compliant floating point units have a similar behaviour with NaN that is a bit more versatile: an arithmetic instruction results in NaN if any operand is NaN, but an instruction with side-effect (compare, convert or store) will raise an exception if given a NaN.
If just having the ability for an exception to occur during an instruction causes overhead, that would be a big problem though.