summaryrefslogtreecommitdiffstats
path: root/Python/pymath.c
diff options
context:
space:
mode:
authorNiklas Fiekas <niklas.fiekas@backscattering.de>2020-06-15 12:33:48 (GMT)
committerGitHub <noreply@github.com>2020-06-15 12:33:48 (GMT)
commit794e7d1ab2d7afe70fe0dd87ca8174ac860413e4 (patch)
tree48ad4d0b5a06b4f80706b16e6ca069f660b25414 /Python/pymath.c
parent25f38d7044a3a47465edd851c4e04f337b2c4b9b (diff)
downloadcpython-794e7d1ab2d7afe70fe0dd87ca8174ac860413e4.zip
cpython-794e7d1ab2d7afe70fe0dd87ca8174ac860413e4.tar.gz
cpython-794e7d1ab2d7afe70fe0dd87ca8174ac860413e4.tar.bz2
bpo-29782: Consolidate _Py_Bit_Length() (GH-20739)
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.
Diffstat (limited to 'Python/pymath.c')
-rw-r--r--Python/pymath.c15
1 files changed, 0 insertions, 15 deletions
diff --git a/Python/pymath.c b/Python/pymath.c
index a08a0e7..24b8042 100644
--- a/Python/pymath.c
+++ b/Python/pymath.c
@@ -79,18 +79,3 @@ round(double x)
return copysign(y, x);
}
#endif /* HAVE_ROUND */
-
-static const unsigned int BitLengthTable[32] = {
- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
-};
-
-unsigned int _Py_bit_length(unsigned long d) {
- unsigned int d_bits = 0;
- while (d >= 32) {
- d_bits += 6;
- d >>= 6;
- }
- d_bits += BitLengthTable[d];
- return d_bits;
-}