-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-44376 - reduce pow() overhead for small exponents #26662
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
Conversation
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
Reduce pow() overhead for small exponents. Incidentally fixed a refcount oversight for negative exponents.
It's annoying, but I don't want to fight about it ;-)
Wow - that appeared to do the trick! Thank you 😄. |
mdickinson
reviewed
Jun 11, 2021
instead of left-to-right. This cuts the time for exponent 2 by another 10%. Does that slow things for, e.g., an exponent like 1 << 20? Sure, by a little. But that exponent will go on to do 20 squarings, and the extra native 32-bit shift- and-tests in the loop are insignificant in comparison. For a tiny exponent (like 2), the loop's shift-and-tests can consume a significant part of the total time. Also reverted the change I made to repair refcounting in modular inverse code. Mark will make the change in a distinct PR, and backport it. Without this change, the "negative refcount" glitch stopped showing up in this PR's code after I changed it to never return `a` directly.
until the exponent is at least 4. Saves approaching another 10% for exponent 2.
insteads works OK, but was always a conceptual mess.
mdickinson
approved these changes
Jun 12, 2021
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.
LGTM
Close to another 10% saved for exponent 2.
jdevries3133
pushed a commit
to jdevries3133/cpython
that referenced
this pull request
Jun 19, 2021
Greatly reduce pow() overhead for small exponents.
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.
BPO-44376
Reduce pow() overhead for small exponents.
Incidentally fixed a refcount oversight for
negative exponents.
https://bugs.python.org/issue44376