-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-46055: Streamline inner loop for right shifts #30243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
056495d
bpo-46055: Streamline inner loop for right shifts
mdickinson d0f1958
Move declarations to top of function; rename high to lobits
mdickinson f92f3f8
Now even faster!
mdickinson 76e9a48
Remove unnecessary parentheses
mdickinson 76dc476
Cosmetic changes to align the inner loop with that of long_lshift1
mdickinson 08bb0bb
Merge remote-tracking branch 'upstream/main' into faster-rshift
mdickinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code also fixes a really subtle portability issue in this code. Here the result of
a->ob_digit[j+1] * 2**hishift
may not be representable in the target type. Normally that wouldn't matter, becausea->ob_digit[j+1]
has typedigit
, which is an unsigned type, so the C standards tell us that any out-of-range value wraps in the normal way. But integer promotions could result in the left-hand operand to the shift actually being of typeint
(a signed type), and then an out-of-range shift result gives undefined behaviour according to the standard (C99 §6.5.7p4). We don't run into this in practice because under any likely combination of integer type bit widths (e.g., 16-bitdigit
, 32-bitint
), ifdigit
is small enough to be promoted toint
, thenint
is likely big enough to hold the shift result. But the C standard does allow potentially problematic bit widths (e.g.,digit
could be 16 bits andint
24 bits).Not a real issue, since it's unlikely we'd ever meet this in practice, but it's nice not to have to worry about it. With the new code, the result of the shift is guaranteed to be representable in the target type (that type being either
twodigits
, or something larger in the case that there are integer promotions going on).