Skip to content

gh-121485: Always use 64-bit integers for integers bits count #121486

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 13 commits into from
Aug 30, 2024

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 8, 2024

Use 64-bit integers instead of platform specific size_t or Py_ssize_t to represent the number of bits in Python integer.

Use 64-bit integers instead of platform specific size_t or Py_ssize_t
to represent the number of bits in Python integer.
@serhiy-storchaka serhiy-storchaka marked this pull request as ready for review July 8, 2024 13:42
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely +1 for the idea. I'm afraid I won't have bandwidth for a detailed code review in the near future.

@serhiy-storchaka
Copy link
Member Author

And what do you think about imposing a hard limit on Python integers, so integers larger than $2^{2^{63}-1}-1$ or $2^{2^{64}-1}-1$ could not even be created? Then the number of bits can always be expressed as a 64-bit integer, error checks after _PyLong_NumBits and _PyLong_Frexp can be removed, and the code for shift operations and int.bit_count() significantly simplified.

@serhiy-storchaka
Copy link
Member Author

I can update this PR for the later idea or implement it in a separate issue.

@mdickinson
Copy link
Member

And what do you think about imposing a hard limit on Python integers ...

That sounds totally reasonable to me (presumably as a CPython detail, rather than an aspect of Python-the-language). Any future computing landscape that makes operating on ints of that size remotely feasible is going to look very different from today's landscape.

@rhettinger rhettinger removed their request for review July 15, 2024 03:18
@serhiy-storchaka
Copy link
Member Author

Thanks, @gpshead.

@serhiy-storchaka serhiy-storchaka merged commit 32c7dbb into python:main Aug 30, 2024
37 checks passed
@serhiy-storchaka serhiy-storchaka deleted the int64-bits branch August 30, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants