-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
bpo-42911: Addition chains #24206
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
bpo-42911: Addition chains #24206
Conversation
Here is the proof of concept power with addition chains, now on top of the master.
Here is the proof of concept power with addition chains, now on top of the master. Also, I speeded up _Py_bit_length as a side product of the 3.8 version
…o addition_chains
Seems to work under Python 3.10. That's a relief! |
So it coredumps with negative exponents. Must be refcount problem. Working on it. |
The changed is fixed in the 3.8 version and manually cherrypicked into the addition_chain branch.
Finally i figured out how to test this on my own machine. |
I found the refcount bug (Yay), and a few bugs that were slowing down things unnecessarily. (That's the disadvantage of using heuristics: it still works even if you do it wrong). |
…ry corner of the code. Then I documented the ideas in Misc/additionchains.txt (is this the right place)?
…see if there are errors
Found an embarrassing missing fix that I forgot. Let's see.
Forgot an import
Interesting. Now the test failed because apparently ** 1 must be an int. My routine optimizes this case and returns the original value. |
I trust myself too much. One more time and I am going to test locally first :-)
Finally! |
See file Misc/additionchain.txt for some timings I just made |
…NTS and NSMALLPOSINTS macros. Sorry about that; it reapplied them now.
Closing following discussion in the issue. |
I put the code that I can only test with 3.8 here, to see actually works in 3.10.
Short description: speeding up pow(int,int) especially for exponents with between 20 and 500 bits (until the fiveary method kicks in) , but is also saves time outside this range.
Speedup is between 2 % (for very high exponents) to 15% (for exponents of a few hundred bits).
And, I speeded up _Py_bit_length for generic processors just because I could :-)
https://bugs.python.org/issue42911