1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_HWEIGHT_H
3 #define _ASM_X86_HWEIGHT_H
5 #include <asm/cpufeatures.h>
15 #define __HAVE_ARCH_SW_HWEIGHT
17 static __always_inline
unsigned int __arch_hweight32(unsigned int w
)
21 asm (ALTERNATIVE("call __sw_hweight32", "popcntl %1, %0", X86_FEATURE_POPCNT
)
28 static inline unsigned int __arch_hweight16(unsigned int w
)
30 return __arch_hweight32(w
& 0xffff);
33 static inline unsigned int __arch_hweight8(unsigned int w
)
35 return __arch_hweight32(w
& 0xff);
39 static inline unsigned long __arch_hweight64(__u64 w
)
41 return __arch_hweight32((u32
)w
) +
42 __arch_hweight32((u32
)(w
>> 32));
45 static __always_inline
unsigned long __arch_hweight64(__u64 w
)
49 asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0", X86_FEATURE_POPCNT
)
55 #endif /* CONFIG_X86_32 */