Skip to content

bpo-45569: Change PYLONG_BITS_IN_DIGIT default to 30 #30497

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 8 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ General Options

Define the size in bits of Python :class:`int` digits: 15 or 30 bits.

By default, the number of bits is selected depending on ``sizeof(void*)``:
30 bits if ``void*`` size is 64-bit or larger, 15 bits otherwise.
By default, the digit size is 30.

Define the ``PYLONG_BITS_IN_DIGIT`` to ``15`` or ``30``.

Expand Down
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,16 @@ Build Changes
like Pyodide.
(Contributed by Christian Heimes and Ethan Smith in :issue:`40280`.)

* CPython will now use 30-bit digits by default for the Python :class:`int`
implementation. Previously, the default was to use 30-bit digits on platforms
with ``SIZEOF_VOID_P >= 8``, and 15-bit digits otherwise. It's still possible
to explicitly request use of 15-bit digits via either the
``--enable-big-digits`` option to the configure script or (for Windows) the
``PYLONG_BITS_IN_DIGIT`` variable in ``PC/pyconfig.h``, but this option may
be removed at some point in the future. (Contributed by Mark Dickinson in
:issue:`45569`.)


C API Changes
=============

Expand Down
16 changes: 4 additions & 12 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,12 @@ Used in: Py_SAFE_DOWNCAST
#define PY_INT32_T int32_t
#define PY_INT64_T int64_t

/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
the necessary integer types are available, and we're on a 64-bit platform
(as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits.

From pyodide: WASM has 32 bit pointers but has native 64 bit arithmetic
so it is more efficient to use 30 bit digits.
/* PYLONG_BITS_IN_DIGIT describes the number of bits per "digit" (limb) in the
* PyLongObject implementation (longintrepr.h). It's currently either 30 or 15,
* defaulting to 30. The 15-bit digit option may be removed in the future.
*/

#ifndef PYLONG_BITS_IN_DIGIT
#if SIZEOF_VOID_P >= 8 || defined(__wasm__)
# define PYLONG_BITS_IN_DIGIT 30
#else
# define PYLONG_BITS_IN_DIGIT 15
#endif
#define PYLONG_BITS_IN_DIGIT 30
#endif

/* uintptr_t is the C9X name for an unsigned integral type such that a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The build now defaults to using 30-bit digits for Python integers. Previously
either 15-bit or 30-bit digits would be selected, depending on the platform.
15-bit digits may still be selected using the ``--enable-big-digits=15`` option
to the ``configure`` script, or by defining ``PYLONG_BITS_IN_DIGIT`` in
``pyconfig.h``.
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

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

pyconfig.h is auto-generated and not user-editable. I suggest to remove the qualifier.

Suggested change
to the ``configure`` script, or by defining ``PYLONG_BITS_IN_DIGIT`` in
``pyconfig.h``.
to the ``configure`` script, or by defining ``PYLONG_BITS_IN_DIGIT``.

Copy link
Member Author

Choose a reason for hiding this comment

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

True; I was thinking of the Windows setup. Maybe replacing pyconfig.h with PC/pyconfig.h would be enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

OTOH, probably not worth worrying about explicitly specifying how to change things for Windows here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Clarified (I hope).

2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ Optional Features:
Doc/library/socket.rst (default is yes if supported)
--enable-big-digits[=15|30]
use big digits (30 or 15 bits) for Python longs
(default is system-dependent)]
(default is 30)]
--disable-test-modules don't build nor install test modules

Optional Packages:
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5039,7 +5039,7 @@ AC_CHECK_DECLS([RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL, RTLD_NODELETE, RTL
# determine what size digit to use for Python's longs
AC_MSG_CHECKING([digit size for Python's longs])
AC_ARG_ENABLE(big-digits,
AS_HELP_STRING([--enable-big-digits@<:@=15|30@:>@],[use big digits (30 or 15 bits) for Python longs (default is system-dependent)]]),
Copy link
Member

Choose a reason for hiding this comment

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

You have to update configure, too. It's a trivial change, so manually editing is easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I've spent the last hour trying to get autoreconf to not generate spurious changes. :-( I'll go for the manual edit option.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I've spent the last hour trying to get autoreconf to not generate spurious changes. :-( I'll go for the manual edit option.

I have you covered: https://quay.io/repository/tiran/cpython_autoconf

AS_HELP_STRING([--enable-big-digits@<:@=15|30@:>@],[use big digits (30 or 15 bits) for Python longs (default is 30)]]),
[case $enable_big_digits in
yes)
enable_big_digits=30 ;;
Expand Down