bpo-29782: Consolidate _Py_Bit_Length() by niklasf · Pull Request #20739 · python/cpython

vstinner

vstinner

vstinner

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.

@niklasf

@niklasf

@niklasf

@niklasf

vstinner

vstinner

@niklasf

vstinner

@niklasf

Co-authored-by: Victor Stinner <vstinner@python.org>

vstinner

vstinner

vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>

@niklasf

@niklasf

@niklasf

@niklasf

@niklasf

vstinner

mdickinson

mdickinson