3 ms·
https://en.wikipedia.org/wiki/Hamming_weight https://en.wikipedia.org/wiki/Hamming_weight I guess it's included as an easy way to access the fast hardware supp
by sio8ohPi 4y ago
https://en.wikipedia.org/wiki/Hamming_weight https://en.wikipedia.org/wiki/Hamming_weight
I guess it's included as an easy way to access the fast hardware supported implementation, on architectures where it is available.
- saagarjha 4y agoSadly it does not call into the hardware implementation: https://github.com/python/cpython/blob/f62ad4f2c4214fdc05cc45c27a5c068553c7942c/Objects/longobject.c#L5711 https://github.com/python/cpython/blob/f62ad4f2c4214fdc05cc4...
- orlp 4y agoIt does. Note that it calls popcount_digit on each digit of the integer (a 'digit' here is 32 bits), which calls _Py_popcount32, which does map to a hardware instruction if possible: https://github.com/python/cpython/blob/f62ad4f2c4214fdc05cc45c27a5c068553c7942c/Include/internal/pycore_bitutils.h#L95 https://github.com/python/cpython/blob/f62ad4f2c4214fdc05cc4...
- saagarjha 4y agoAh, you are correct. Although I still take issue with "fast" in the comment I was replying to ;)