Re: [tip:perf/core] bitops: Provide compile time HWEIGHT{8,16,32,64}

From: H. Peter Anvin
Date: Mon Feb 01 2010 - 14:12:12 EST


On 02/01/2010 04:43 AM, Peter Zijlstra wrote:
>
> The below does work, but is still a tad ugly in that if you want to use
> any of the HWEIGHT functions that use BUILD_BUG_ON_ZERO() you have to
> have included linux/kernel.h yourself.
>
> But at least it builds on x86_64, alpha and sparc64 (didn't have a ia64
> compiler around).
>
> FWIW I was tempted to change the return type of hweight64() from
> unsigned long to unsigned int, its not as if it'll ever return a value
> larger than 64.
>

That might generate worse code in some cases, though (something that
needs it as a 64-bit value would have to extend it unnecessarily), but
probably the easiest is to just compile and see what happens.

x86 also has a POPCNT instruction now, which we should be able to use
via alternatives. That's something to do after your cleanup is in.

Anyway, I like the cleanup.

Acked-by: H. Peter Anvin <hpa@xxxxxxxxx>

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/