From 76924d1b4fd84acaa3a56ba60a74b717bc890f0c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 9 Jan 2022 11:25:42 +0000 Subject: [PATCH 1/7] Change PYLONG_BITS_IN_DIGIT default to 30 --- Include/pyport.h | 17 +++++------------ .../2022-01-09-11-24-54.bpo-45569.zCIENy.rst | 5 +++++ 2 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2022-01-09-11-24-54.bpo-45569.zCIENy.rst diff --git a/Include/pyport.h b/Include/pyport.h index 81b1bde841e083..3f77548384f6a5 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -85,20 +85,13 @@ 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 PyLong 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 diff --git a/Misc/NEWS.d/next/Build/2022-01-09-11-24-54.bpo-45569.zCIENy.rst b/Misc/NEWS.d/next/Build/2022-01-09-11-24-54.bpo-45569.zCIENy.rst new file mode 100644 index 00000000000000..69716cd9af5b2d --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-01-09-11-24-54.bpo-45569.zCIENy.rst @@ -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``. From 515c0e8d1c5afcd2907c0a5ced1a7868bbde3dff Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 9 Jan 2022 11:31:36 +0000 Subject: [PATCH 2/7] Tweak comment wording --- Include/pyport.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index 3f77548384f6a5..d27b3dde11659b 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -87,8 +87,7 @@ Used in: Py_SAFE_DOWNCAST /* 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 PyLong digit option may be removed in the - * future. + * defaulting to 30. The 15-bit digit option may be removed in the future. */ #ifndef PYLONG_BITS_IN_DIGIT #define PYLONG_BITS_IN_DIGIT 30 From 2fdd174f821e0adbede5cba943716496c7e886c1 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 13 Jan 2022 19:27:29 +0000 Subject: [PATCH 3/7] Add what's new entry --- Doc/whatsnew/3.11.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 28ac57e9544385..9de81a16441339 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -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 the + ``PYLONG_BITS_IN_DIGIT`` variable in ``pyconfig.h``, but this option may be + removed at some point in the future. (Contributed by Mark Dickinson in + :issue:`45569`.) + + C API Changes ============= From d537d229535a0d163b93192ac4bc5cdeff8bf0ab Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 13 Jan 2022 19:29:55 +0000 Subject: [PATCH 4/7] Update configure docs --- Doc/using/configure.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 771ad3cf18d97b..f1c156c042353a 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -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``. From 4e927c74bfc8d6ea1ac4f9ca255149977c2d32c8 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 13 Jan 2022 20:07:28 +0000 Subject: [PATCH 5/7] Update configure.ac --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e5ebf7bc2e07aa..281d3b1855ca07 100644 --- a/configure.ac +++ b/configure.ac @@ -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)]]), +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 ;; From f7e903323567db76346ab6817db1ad8bca55705c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 13 Jan 2022 20:10:45 +0000 Subject: [PATCH 6/7] Replace pyconfig.h with PC/pyconfig.h --- Doc/whatsnew/3.11.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 9de81a16441339..f726ad60b5ec09 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -626,9 +626,9 @@ Build Changes 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 the - ``PYLONG_BITS_IN_DIGIT`` variable in ``pyconfig.h``, but this option may be - removed at some point in the future. (Contributed by Mark Dickinson in + ``--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`.) From 34dcb2c99ab7d32fd6198cf4860ae131686da9ee Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 13 Jan 2022 20:13:38 +0000 Subject: [PATCH 7/7] Make corresponding change in configure --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 127b350b4bb045..52730a78c36118 100755 --- a/configure +++ b/configure @@ -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: