Repository navigation
gh-160872: Keep PyLong "x_divrem" inner loop carry in 64 bits - #161156
Open
XiaohongGong wants to merge 2 commits into
Open
XiaohongGong wants to merge 2 commits into
XiaohongGong wants to merge 2 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
eendebakpt
approved these changes
Nov 2, 2026
Author
|
Hi @eendebakpt , thanks a lot for your review! About integrating this PR, do I need to waiting for others to review? If not, could anyone please help merge this PR? |
Contributor
|
Nothing more required, just some patience. I will give other devs some time to have a look as well, if no further comments I will merge. |
Author
Good to know this. Thanks a lot for your inputs and help! |
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.
zhi, the loop-carried borrow in Knuth Algorithm D, was stored as ansdigit (32-bit int)and then widened to 64-biystwodigitson the next iteration. That extra conversion sat on the critical chain which is strong latency bounded:Store
zhias stwodigits instead to save the type conversions. In addition, the compiler can then computevk[i] - q*w0[i]at firstand only then add the carried borrow, so this computation no longer depends on
zhi:The loop-carried chain shrinks to two instructions. Knuth invariants are unchanged, so quotients and remainders are the same.
Below is the performance data from a micro python benchmark and the
pidigitson my AArch64 and X86 machines respecitively. I didn't observe obvious performance regressions for other pyperformance benchmarks with this change.AArch64 (NVIDIA Grace,Neoverse V):
X86_64 (Intel Xeon Gold 6444Y):
Micro-benchmark:
Fixes gh-160872.
Co-authored-by: Kyrylo Tkachov ktkachov@nvidia.com