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 static __always_inline
unsigned int __arch_hweight32(unsigned int w
)
19 asm (ALTERNATIVE("call __sw_hweight32", "popcntl %1, %0", X86_FEATURE_POPCNT
)
26 static inline unsigned int __arch_hweight16(unsigned int w
)
28 return __arch_hweight32(w
& 0xffff);
31 static inline unsigned int __arch_hweight8(unsigned int w
)
33 return __arch_hweight32(w
& 0xff);
37 static inline unsigned long __arch_hweight64(__u64 w
)
39 return __arch_hweight32((u32
)w
) +
40 __arch_hweight32((u32
)(w
>> 32));
43 static __always_inline
unsigned long __arch_hweight64(__u64 w
)
47 asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0", X86_FEATURE_POPCNT
)
53 #endif /* CONFIG_X86_32 */