]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-29882: _Py_popcount32() doesn't need 64x64 multiply (GH-30774)
authorVictor Stinner <vstinner@python.org>
Fri, 21 Jan 2022 23:54:42 +0000 (00:54 +0100)
committerGitHub <noreply@github.com>
Fri, 21 Jan 2022 23:54:42 +0000 (00:54 +0100)
32x32 bits multiply is enough for _Py_popcount32().

Include/internal/pycore_bitutils.h

index e4aa7a3d0d05670b0ab5e4db826f1670522a5454..3fd70b0e417c19393607ed49bd2579d533377634 100644 (file)
@@ -125,7 +125,7 @@ _Py_popcount32(uint32_t x)
     // Put count of each 8 bits into those 8 bits
     x = (x + (x >> 4)) & M4;
     // Sum of the 4 byte counts
-    return (uint32_t)((uint64_t)x * (uint64_t)SUM) >> 24;
+    return (x * SUM) >> 24;
 #endif
 }