Skip to content

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

Closed
wants to merge 18 commits into from
Closed

bpo-42911: Addition chains #24206

wants to merge 18 commits into from

Conversation

jneb
Copy link
Contributor

@jneb jneb commented Jan 13, 2021

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

jneb and others added 4 commits January 13, 2021 11:26
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
@jneb
Copy link
Contributor Author

jneb commented Jan 13, 2021

Seems to work under Python 3.10. That's a relief!

@jneb
Copy link
Contributor Author

jneb commented Jan 13, 2021

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.
@jneb
Copy link
Contributor Author

jneb commented Jan 13, 2021

Finally i figured out how to test this on my own machine.
One should learn to operate the fire extinguisher before lighting a fire...
So, I am now convinced I'll get it to work (eventually :-) )

@jneb
Copy link
Contributor Author

jneb commented Jan 14, 2021

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).
Ready to do some speed measurements and move those changes from my 38_fast_pow to the addition chain branch

Jurjen Bos and others added 4 commits January 14, 2021 16:58
…ry corner of the code.

Then I documented the ideas in Misc/additionchains.txt (is this the right place)?
Found an embarrassing missing fix that I forgot.
Let's see.
Forgot an import
@jneb
Copy link
Contributor Author

jneb commented Jan 14, 2021

Interesting. Now the test failed because apparently ** 1 must be an int. My routine optimizes this case and returns the original value.
I guess this had to be "fixed" even though I disagree :-)
Of course, adding zero to something also makes it an int. Interesting edge case.

jneb added 5 commits January 14, 2021 19:42
Don't use your phone for editing :-)
The old bug came back
I trust myself too much. One more time and I am going to test locally first :-)
@jneb
Copy link
Contributor Author

jneb commented Jan 14, 2021

Finally!
I'll put some speed measurement code and results (measured on 3.8 due to lack of resources) in the file additionchain.txt. If someone wants to verify the same is true on 3.10, please do.

@jneb
Copy link
Contributor Author

jneb commented Jan 15, 2021

See file Misc/additionchain.txt for some timings I just made

Jurjen Bos added 2 commits January 15, 2021 08:39
@mdickinson
Copy link
Member

Closing following discussion in the issue.

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.

4 participants