(no title)
CodeArtisan | 2 months ago
unsigned int popcount(unsigned int n)
{
return (n &= n - 1u) ? (1u + popcount(n)) : 0u;
}
Clang 21.1 x64: popcount:
mov eax, -1
.LBB0_1:
lea ecx, [rdi - 1]
inc eax
and ecx, edi
mov edi, ecx
jne .LBB0_1
ret
GCC 15.2: popcount:
blsr edi, edi
popcnt eax, edi
ret
Both compiled with -O3 -march=znver5
pbsd|2 months ago
1718627440|2 months ago