Uh oh!
There was an error while loading. Please reload this page.
bpo-29882: Add _Py_popcount32() function - #20518
Conversation
@mdickinson: here you have. |
vstinner
commented
May 29, 2020
On my x86-64 Fedora 32 with GCC 10.1.1, __builtin_popcount() becomes a call to __popcountdi2() function: It looks like the SWAR popcount. Using |
vstinner
commented
May 29, 2020
I wrote this PR to factorize duplicate function:
I also added |
vstinner
commented
May 29, 2020
This PR is a follow-up of PR #771 which added int.bit_count() Python function and popcount_digit() C function. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Jun 2, 2020
@mdickinson: I updated the PR. Would you mind to review it? |
mdickinson
commented
Jun 5, 2020
Will do, but not before the weekend. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mdickinson
left a comment
There was a problem hiding this comment.
I left a few comments; mostly nitpicks, but there are some bits I don't understand (like the SIZEOF_INT == 8 branch).
vstinner
commented
Jun 7, 2020
Oh, 45af786 is good example of why I'm mentioning one used function on an include :-) |
* Rename pycore_byteswap.h to pycore_bitutils.h. * Move popcount_digit() to pycore_bitutils.h as _Py_popcount32(). * _Py_popcount32() uses GCC and clang builtin function if available. * Add unit tests to _Py_popcount32().
* Remove UINT32_C() * Fix #ifdef to decide if builtin functions are used of not: use SIZEOF_INT >= 4. Always use __builtin_popcountl() otherwise. * popcount_digit(): check PyLong_SHIFT rather than sizeof(digit). * Fix also two comments
vstinner
commented
Jun 7, 2020
@mdickinson: PR updated to address your latest review. PR rebased to fix a merge conflict with 45af786 |
vstinner
commented
Jun 8, 2020
Thanks @mdickinson for the reviews! |
In pythonGH-2866, _Py_Bit_Length() was added to pymath.h for lack of a better location. pythonGH-20518 added a more appropriate header file for bit utilities. It also shows how to properly use intrinsics. This allows reconsidering bpo-29782. * Move the function to the new header. * Changed return type to match __builtin_clzl and reviewed usage. * Use intrinsics where available. * Pick a (mostly theoretical) fallback implementation suitable for inlining.
In GH-2866, _Py_Bit_Length() was added to pymath.h for lack of a better location. GH-20518 added a more appropriate header file for bit utilities. It also shows how to properly use intrinsics. This allows reconsidering bpo-29782. * Move the function to the new header. * Changed return type to match __builtin_clzl() and reviewed usage. * Use intrinsics where available. * Pick a fallback implementation suitable for inlining.
https://bugs.python.org/issue29882