4 ms·
There is more! You can be _faster_ than __builtin_popcount()! Wojciech Muła did an excellent SSSE3 implementation: http://0x80.pl/articles/sse-popcount.html h
by majke 7y ago
There is more! You can be _faster_ than __builtin_popcount()!
Wojciech Muła did an excellent SSSE3 implementation:
http://0x80.pl/articles/sse-popcount.html http://0x80.pl/articles/sse-popcount.html
My understanding is that the set-up time is slower than the POPCNT cpu instruction, but throughput is higher. Useful if you need to count bits not on a register, but on a whole array.
- dalke 7y agoIt looks the conclusion is that the POPCNT instruction ("cpu") is faster than any of the SSE implementations. Only AVX2 outperforms POPCNT, and only for large enough bitstrings.
- majke 7y agoOn i7: > AVX2 code is faster than the dedicated instruction for input size 512 bytes and larger The difference is indeed tiny. Still - it's very cool the generic AVX2 code can beat the instruction burned in the silicon!