bitops: Optimize hweight() by making use of compile-time evaluation
Rename the extisting runtime hweight() implementations to __arch_hweight(), rename the compile-time versions to __const_hweight() and then have hweight() pick between them. Suggested-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <20100318111929.GB11152@aftab> Acked-by: H. Peter Anvin <hpa@zytor.com> LKML-Reference: <1265028224.24455.154.camel@laptop> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
committed by
H. Peter Anvin
parent
0fdf86754f
commit
1527bc8b92
@@ -437,17 +437,18 @@ __fls (unsigned long x)
|
||||
* hweightN: returns the hamming weight (i.e. the number
|
||||
* of bits set) of a N-bit word
|
||||
*/
|
||||
static __inline__ unsigned long
|
||||
hweight64 (unsigned long x)
|
||||
static __inline__ unsigned long __arch_hweight64(unsigned long x)
|
||||
{
|
||||
unsigned long result;
|
||||
result = ia64_popcnt(x);
|
||||
return result;
|
||||
}
|
||||
|
||||
#define hweight32(x) (unsigned int) hweight64((x) & 0xfffffffful)
|
||||
#define hweight16(x) (unsigned int) hweight64((x) & 0xfffful)
|
||||
#define hweight8(x) (unsigned int) hweight64((x) & 0xfful)
|
||||
#define __arch_hweight32(x) ((unsigned int) __arch_hweight64((x) & 0xfffffffful))
|
||||
#define __arch_hweight16(x) ((unsigned int) __arch_hweight64((x) & 0xfffful))
|
||||
#define __arch_hweight8(x) ((unsigned int) __arch_hweight64((x) & 0xfful))
|
||||
|
||||
#include <asm-generic/bitops/const_hweight.h>
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
|
Reference in New Issue
Block a user