Re: Adding __popcountsi2 and __popcountdi2
From: Linus Torvalds
Date: Thu Apr 24 2025 - 21:37:01 EST
On Thu, 24 Apr 2025 at 17:33, Nathan Chancellor <nathan@xxxxxxxxxx> wrote:
>
> I figured added
> these may not be as bad as the wcslen() case because most architectures
> generally have an optimized popcount implementation and I am not sure
> compiler builtins are banned entirely from the kernel but I can
> understand if it is still contentious.
Why does the compiler even bother to do this if the architecture
doesn't have the popcount instruction? The function call is quite
possibly more expensive than just doing it the stupid way.
But if you want to do this, put the damn thing as an alias on the code
that actually *does* the SW fallback in lib/hweight.c.
Because the way your patch does it now, it takes "I'm doing stupid
things" to the next level by turning that function call into *two*
function calls - first calling __popcountsi2, which then calls
__sw_hweight32.
Let's not do stupid things, ok?
Linus