Merged
Conversation
Signed overflow is undefined behaviour in C and compilers can and do optimized on that basis.
Note this is primarily based on performance of compilers which do not support __builtin_add_overflow (i.e., not Clang >= 3.4 & gcc >= 5), mostly looking at several gcc 4 releases (used by older, supported, RHEL releases and Debian 8 "Jessie") and MSVC. Implementations of all of these functions using the builtins where available is forthcoming.
This is much quicker in general, as these all just then read the overflow flag from the status register
auvipy
approved these changes
May 8, 2020
da-woods
reviewed
May 8, 2020
scoder
reviewed
May 9, 2020
Contributor
scoder
left a comment
There was a problem hiding this comment.
Nice! I left some comments, mostly about readability. This code is so deeply technical that it's worth dropping a comment more here and there.
gsnedders
commented
May 12, 2020
Contributor
Author
gsnedders
left a comment
There was a problem hiding this comment.
I did write some comments, but wasn't sure quite how far to go given I'd spent long enough staring at the code, so did partly put this up as it was just to see where you wanted more! Looking at this code again (I wrote most of it a while ago) I can't say I disagree.
Reviewing this closely, the only way this can be correct for 64-bit ints and above is when we carefully manage floating point rounding mode, and that's vastly more pain (and the standard ways to change rounding mode inhibit compiler optimisations much more broadly).
Contributor
Author
|
@scoder ping |
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3588, and while we're at it improves all the (arithmetic) overflow detection code, including adding support for the gcc 5+/clang 3.4+
__builtin_XXX_overflow.Looking at
Demos/benchmarks/chaos.py(the only file in that directory significantly affected by enablingoverflowcheck, with the non-__builtin_XXX_overflowcode paths we gain 2%, and with them we gain 4% (and that's then only 1% behindoverflowcheck=False).