Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_X86_HWEIGHT_H
0003 #define _ASM_X86_HWEIGHT_H
0004 
0005 #include <asm/cpufeatures.h>
0006 
0007 #ifdef CONFIG_64BIT
0008 #define REG_IN "D"
0009 #define REG_OUT "a"
0010 #else
0011 #define REG_IN "a"
0012 #define REG_OUT "a"
0013 #endif
0014 
0015 static __always_inline unsigned int __arch_hweight32(unsigned int w)
0016 {
0017     unsigned int res;
0018 
0019     asm (ALTERNATIVE("call __sw_hweight32", "popcntl %1, %0", X86_FEATURE_POPCNT)
0020              : "="REG_OUT (res)
0021              : REG_IN (w));
0022 
0023     return res;
0024 }
0025 
0026 static inline unsigned int __arch_hweight16(unsigned int w)
0027 {
0028     return __arch_hweight32(w & 0xffff);
0029 }
0030 
0031 static inline unsigned int __arch_hweight8(unsigned int w)
0032 {
0033     return __arch_hweight32(w & 0xff);
0034 }
0035 
0036 #ifdef CONFIG_X86_32
0037 static inline unsigned long __arch_hweight64(__u64 w)
0038 {
0039     return  __arch_hweight32((u32)w) +
0040         __arch_hweight32((u32)(w >> 32));
0041 }
0042 #else
0043 static __always_inline unsigned long __arch_hweight64(__u64 w)
0044 {
0045     unsigned long res;
0046 
0047     asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0", X86_FEATURE_POPCNT)
0048              : "="REG_OUT (res)
0049              : REG_IN (w));
0050 
0051     return res;
0052 }
0053 #endif /* CONFIG_X86_32 */
0054 
0055 #endif