[Bug libstdc++/77776] C++17 std::hypot implementation is poor
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Mar 6 12:35:42 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77776
--- Comment #21 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to g.peterhoff from comment #19)
> * You were probably wondering why I wrote "if (std::isinf(x) | std::isinf(y)
> | std::isinf(z))", for example. This is intentional. The problem is that gcc
> almost always produces branch code for logical operations, so *a lot* of
> conditional jumps. By using arithmetic operations, so instead of || && just
> | &, I can get it to generate only actually necessary conditional jumps or
> cmoves. branchfree code is always better.
In general the code is not equivalent if any of the subexpressions has side
effects, such as setting errno, raising an exception for a signalling nan etc.
but I don't think we care about that here.
More information about the Gcc-bugs
mailing list