Skip to content

Fix overflow_check#3591

Merged
scoder merged 10 commits intocython:masterfrom
gsnedders:overflow_fixes
May 18, 2020
Merged

Fix overflow_check#3591
scoder merged 10 commits intocython:masterfrom
gsnedders:overflow_fixes

Conversation

@gsnedders
Copy link
Contributor

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 enabling overflowcheck, with the non-__builtin_XXX_overflow code paths we gain 2%, and with them we gain 4% (and that's then only 1% behind overflowcheck=False).

gsnedders added 3 commits May 8, 2020 14:24
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
Copy link
Contributor

@scoder scoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@gsnedders gsnedders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

gsnedders added 7 commits May 13, 2020 23:03
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).
@gsnedders
Copy link
Contributor Author

@scoder ping

@scoder scoder added this to the 3.0 milestone May 18, 2020
@scoder
Copy link
Contributor

scoder commented May 18, 2020

Thanks!
I'll target this to 3.0 for now, mostly to give it some more testing. Wouldn't mind backporting it to 0.29.x at some point.

@scoder scoder merged commit 92a0b75 into cython:master May 18, 2020
scoder added a commit that referenced this pull request Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

overflow_check_* failures in tests

4 participants