x86-64 SIMD popcnt

David Sparks sparks05 at proton.me
Sun Oct 11 07:39:10 CEST 2026


On Wednesday, 7 October 2026 at 13:48, Torbjörn Granlund <tg at gmplib.org> wrote:
> I played with this back in 2021.  You might want to take a look at what
> I got:

Fun reading!  My detailed comments got lost in a power glitch,
but while I'm recreating this, I got the following working.

On my Haswell, I measure about 0.75 cycles/limb for that AVX2 code.

The attached Harley-Seal core achieves 0.5 cycles/limb for
L2-resident data.  Extending it to handle odd-sized
and unaligned buffers is a small matter of programming I'll
undertake if you're interested.

It's 5 instructions (plus one load, plus two moves if limited
to 2-operand instructions) per SIMD word.  Still a ways from
Haswell's theoretical 8 limbs/cycle L2 cache bandwidth, but
it's not too shabby.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: popcount2-avx2.asm
Type: application/octet-stream
Size: 5842 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20261011/a438479e/attachment.obj>


More information about the gmp-bugs mailing list