Re: Adding __popcountsi2 and __popcountdi2

From: Linus Torvalds
Date: Thu Apr 24 2025 - 23:31:25 EST


On Thu, 24 Apr 2025 at 19:11, Nathan Chancellor <nathan@xxxxxxxxxx> wrote:
>
> I will test declaring __popcount{s,d}i2() as aliases of
> __sw_hweight{32,64}() to see what effect that has but I figured that
> calling the __arch_hweight variants was more correct because some
> architectures (at least RISC-V and x86 when I looked) use alternatives
> in that path to use hardware instructions and avoid the software path
> altogether. While there would still be the overhead from the function
> call, I figured not using the software fallback would at least soften
> that blow.

Once you have the overhead of a function call - and all the register
games etc that involves, you're almost certainly better off with the
simple unconditional bitwise games.

Linus