summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/hamt.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-04-18 12:39:32 +0300
committershadchin <[email protected]>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Python/hamt.c
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Python/hamt.c')
-rw-r--r--contrib/tools/python3/src/Python/hamt.c25
1 files changed, 3 insertions, 22 deletions
diff --git a/contrib/tools/python3/src/Python/hamt.c b/contrib/tools/python3/src/Python/hamt.c
index 8801c5ea418..e272e8808fd 100644
--- a/contrib/tools/python3/src/Python/hamt.c
+++ b/contrib/tools/python3/src/Python/hamt.c
@@ -1,5 +1,6 @@
#include "Python.h"
+#include "pycore_bitutils.h" // _Py_popcount32
#include "pycore_hamt.h"
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include <stddef.h> // offsetof()
@@ -434,29 +435,9 @@ hamt_bitpos(int32_t hash, uint32_t shift)
}
static inline uint32_t
-hamt_bitcount(uint32_t i)
-{
- /* We could use native popcount instruction but that would
- require to either add configure flags to enable SSE4.2
- support or to detect it dynamically. Otherwise, we have
- a risk of CPython not working properly on older hardware.
-
- In practice, there's no observable difference in
- performance between using a popcount instruction or the
- following fallback code.
-
- The algorithm is copied from:
- https://graphics.stanford.edu/~seander/bithacks.html
- */
- i = i - ((i >> 1) & 0x55555555);
- i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
- return (((i + (i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
-}
-
-static inline uint32_t
hamt_bitindex(uint32_t bitmap, uint32_t bit)
{
- return hamt_bitcount(bitmap & (bit - 1));
+ return (uint32_t)_Py_popcount32(bitmap & (bit - 1));
}
@@ -820,7 +801,7 @@ hamt_node_bitmap_assoc(PyHamtNode_Bitmap *self,
else {
/* There was no key before with the same (shift,hash). */
- uint32_t n = hamt_bitcount(self->b_bitmap);
+ uint32_t n = (uint32_t)_Py_popcount32(self->b_bitmap);
if (n >= 16) {
/* When we have a situation where we want to store more