[issue19915] int.bit_at(n) - Accessing a single bit in O(1)
Change by Niklas Fiekas : -- nosy: +niklasf ___ Python tracker <https://bugs.python.org/issue19915> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29782] Use __builtin_clzl for bits_in_digit if available
Change by Niklas Fiekas : -- pull_requests: +19946 pull_request: https://github.com/python/cpython/pull/20739 ___ Python tracker <https://bugs.python.org/issue29782> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31031] Unify duplicate bits_in_digit and bit_length
New submission from Niklas Fiekas: My previous patch to optimize bits_in_digit was rejected: http://bugs.python.org/issue29782 This leaves this issue open (mathmodule.c): /* XXX: This routine does more or less the same thing as * bits_in_digit() in Objects/longobject.c. Someday it would be nice to * consolidate them. On BSD, there's a library function called fls() * that we could use, and GCC provides __builtin_clz(). */ We could still deal with the code duplication without the complexity of the optimizations in the previous patch. -- components: Interpreter Core messages: 299069 nosy: louielu, mark.dickinson, niklasf priority: normal severity: normal status: open title: Unify duplicate bits_in_digit and bit_length type: enhancement versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue31031> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31031] Unify duplicate bits_in_digit and bit_length
Changes by Niklas Fiekas : -- pull_requests: +2916 ___ Python tracker <http://bugs.python.org/issue31031> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35721] _UnixSubprocessTransport leaks socket pair if Popen fails
New submission from Niklas Fiekas : Output of attached test case: non-existing indeed subprocess-exec-test.py:11: ResourceWarning: unclosed print("non-existing indeed") ResourceWarning: Enable tracemalloc to get the object allocation traceback subprocess-exec-test.py:11: ResourceWarning: unclosed print("non-existing indeed") ResourceWarning: Enable tracemalloc to get the object allocation traceback . -- Ran 1 test in 0.007s OK -- components: asyncio files: subprocess-exec-test.py messages: 333501 nosy: asvetlov, niklasf, yselivanov priority: normal severity: normal status: open title: _UnixSubprocessTransport leaks socket pair if Popen fails type: resource usage versions: Python 3.8 Added file: https://bugs.python.org/file48043/subprocess-exec-test.py ___ Python tracker <https://bugs.python.org/issue35721> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35721] _UnixSubprocessTransport leaks socket pair if Popen fails
Change by Niklas Fiekas : -- keywords: +patch pull_requests: +11184 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue35721> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35721] _UnixSubprocessTransport leaks socket pair if Popen fails
Change by Niklas Fiekas : -- keywords: +patch, patch pull_requests: +11184, 11185 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue35721> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35721] _UnixSubprocessTransport leaks socket pair if Popen fails
Change by Niklas Fiekas : -- keywords: +patch, patch, patch pull_requests: +11184, 11185, 11186 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue35721> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29782] Use __builtin_clzl for bits_in_digit if available
New submission from Niklas Fiekas: Baseline performance (9e6ac83acae): $ ./python -m timeit "12345678 == 12345678.0" 500 loops, best of 5: 40 nsec per loop $ ./python -m timeit "1 == 1.0" 1000 loops, best of 5: 38.8 nsec per loop $ ./python -m timeit "(1234578987654321).bit_length()" 1000 loops, best of 5: 39.4 nsec per loop Upcoming PR: $ ./python -m timeit "12345678 == 12345678.0" 1000 loops, best of 5: 34.3 nsec per loop $ ./python -m timeit "1 == 1.0" 1000 loops, best of 5: 34.4 nsec per loop $ ./python -m timeit "(1234578987654321).bit_length()" 1000 loops, best of 5: 36.4 nsec per loop -- components: Interpreter Core messages: 289353 nosy: niklasf priority: normal severity: normal status: open title: Use __builtin_clzl for bits_in_digit if available type: performance versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue29782> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29782] Use __builtin_clzl for bits_in_digit if available
Changes by Niklas Fiekas : -- pull_requests: +490 ___ Python tracker <http://bugs.python.org/issue29782> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29782] Use __builtin_clzl for bits_in_digit if available
Niklas Fiekas added the comment: Thanks for the review. I pushed a change to check if clz can be used (`sizeof(digit) <= sizeof(unsigned int)`). Otherwise use clzl. I believe the latter should be the most common, since unsigned long has 32bits. As you say unsigned long long should never be needed. Btw. mathmodule.c currently duplicates the function: https://github.com/python/cpython/blob/master/Modules/mathmodule.c#L1317. It might be worth factoring it out, but I don't know where to put it. -- ___ Python tracker <http://bugs.python.org/issue29782> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29782] Use __builtin_clzl for bits_in_digit if available
Niklas Fiekas added the comment: Oops. Actually clz should commonly be enough. And platforms where clz and clzl are different (<=> unsigned int and unsigned long are different) should be rare. -- ___ Python tracker <http://bugs.python.org/issue29782> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29882] Add an efficient popcount method for integers
New submission from Niklas Fiekas: An efficient popcount (something equivalent to bin(a).count("1")) would be useful for numerics, parsing binary formats, scientific applications and others. DESIGN DECISIONS * Is a popcount method useful enough? * How to handle negative values? * How should the method be named? SURVEY gmpy calls the operation popcount and returns -1/None for negative values: >>> import gmpy2 >>> gmpy2.popcount(-10) -1 >>> import gmpy >>> gmpy.popcount(-10) >From the documentation [1]: > If x < 0, the number of bits with value 1 is infinite > so -1 is returned in that case. (I am not a fan of the arbitrary return value). The bitarray module has a count(value=True) method: >>> from bitarray import bitarray >>> bitarray(bin(123456789).strip("0b")).count() 16 Bitsets [2] exposes __len__. There is an SSE4 POPCNT instruction. C compilers call the corresponding intrinsic popcnt or popcount (with some prefix and suffix) and they accept unsigned arguments. Rust calls the operation count_ones [3]. Ones are counted in the binary representation of the *absolute* value. (I propose to do the same). Introducing popcount was previously considered here but closed for lack of a PEP or patch: http://bugs.python.org/issue722647 Sensible names could be bit_count along the lines of the existing bit_length or popcount for gmpy compability and to distinguish it more. PERFORMANCE $ ./python -m timeit "bin(123456789).count('1')" # equivalent 100 loops, best of 5: 286 nsec per loop $ ./python -m timeit "(123456789).bit_count()" # fallback 500 loops, best of 5: 46.3 nsec per loop [1] https://gmpy2.readthedocs.io/en/latest/mpz.html#mpz-functions [2] https://pypi.python.org/pypi/bitsets/0.7.9 [3] https://doc.rust-lang.org/std/primitive.i64.html#method.count_ones -- components: Interpreter Core messages: 290003 nosy: mark.dickinson, niklasf priority: normal severity: normal status: open title: Add an efficient popcount method for integers type: enhancement versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue29882> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29882] Add an efficient popcount method for integers
Changes by Niklas Fiekas : -- pull_requests: +678 ___ Python tracker <http://bugs.python.org/issue29882> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29882] Add an efficient popcount method for integers
Niklas Fiekas added the comment: Searching popcount in Python files on GitHub yields a considerable number of examples: https://github.com/search?utf8=%E2%9C%93&q=popcount+extension%3Apy&type=Code Perhaps intresting: * In CPython itself: See count_set_bits in Modules/mathmodule.c * Domain specific applications: Bitboards in Chess, fairly shuffling cards in Poker, comparing molecules * Size of bitsets (see bitarray and bitsets I listed above). Probably for this reason also as a first class citizen in Redis: https://redis.io/commands/bitcount. Probably most important: * As the Hamming Distance: https://en.wikipedia.org/wiki/Hamming_distance#History_and_applications --- Btw. not a concrete application. I just stumbled upon this. popcnt was considered important enough to be included in the rather limited WebAssembly instruction set: https://github.com/WebAssembly/spec/raw/master/papers/pldi2017.pdf -- ___ Python tracker <http://bugs.python.org/issue29882> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29936] Typo in __GNU*C*_MINOR__ guard affecting gcc 3.x
New submission from Niklas Fiekas: The patch in http://bugs.python.org/issue16881 disables the nicer macro for gcc 3.x due to a small typo. The build is not failing. The guard just unnescessarily evaluates to false. -- components: Interpreter Core messages: 290738 nosy: niklasf priority: normal severity: normal status: open title: Typo in __GNU*C*_MINOR__ guard affecting gcc 3.x versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue29936> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29936] Typo in __GNU*C*_MINOR__ guard affecting gcc 3.x
Changes by Niklas Fiekas : -- pull_requests: +777 ___ Python tracker <http://bugs.python.org/issue29936> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29936] Typo in __GNU*C*_MINOR__ guard affecting gcc 3.x
Changes by Niklas Fiekas : -- components: +Build -Interpreter Core nosy: +Jeffrey.Armstrong, christian.heimes type: -> compile error ___ Python tracker <http://bugs.python.org/issue29936> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com