2010-03-05 23:34:46 +07:00
|
|
|
#ifndef _ASM_X86_HWEIGHT_H
|
|
|
|
#define _ASM_X86_HWEIGHT_H
|
|
|
|
|
2016-01-27 04:12:04 +07:00
|
|
|
#include <asm/cpufeatures.h>
|
|
|
|
|
2010-03-05 23:34:46 +07:00
|
|
|
#ifdef CONFIG_64BIT
|
2016-05-30 17:56:27 +07:00
|
|
|
/* popcnt %edi, %eax */
|
|
|
|
#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc7"
|
2010-03-05 23:34:46 +07:00
|
|
|
/* popcnt %rdi, %rax */
|
2010-05-18 05:13:23 +07:00
|
|
|
#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7"
|
2010-03-05 23:34:46 +07:00
|
|
|
#define REG_IN "D"
|
|
|
|
#define REG_OUT "a"
|
|
|
|
#else
|
|
|
|
/* popcnt %eax, %eax */
|
2010-05-18 05:13:23 +07:00
|
|
|
#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0"
|
2010-03-05 23:34:46 +07:00
|
|
|
#define REG_IN "a"
|
|
|
|
#define REG_OUT "a"
|
|
|
|
#endif
|
|
|
|
|
2016-05-30 17:56:27 +07:00
|
|
|
#define __HAVE_ARCH_SW_HWEIGHT
|
|
|
|
|
2015-08-04 21:15:15 +07:00
|
|
|
static __always_inline unsigned int __arch_hweight32(unsigned int w)
|
2010-03-05 23:34:46 +07:00
|
|
|
{
|
2016-05-30 17:56:27 +07:00
|
|
|
unsigned int res;
|
2010-03-05 23:34:46 +07:00
|
|
|
|
2010-05-18 05:13:23 +07:00
|
|
|
asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT)
|
2016-05-30 17:56:27 +07:00
|
|
|
: "="REG_OUT (res)
|
|
|
|
: REG_IN (w));
|
2010-03-05 23:34:46 +07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int __arch_hweight16(unsigned int w)
|
|
|
|
{
|
|
|
|
return __arch_hweight32(w & 0xffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int __arch_hweight8(unsigned int w)
|
|
|
|
{
|
|
|
|
return __arch_hweight32(w & 0xff);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:15:15 +07:00
|
|
|
#ifdef CONFIG_X86_32
|
2010-03-05 23:34:46 +07:00
|
|
|
static inline unsigned long __arch_hweight64(__u64 w)
|
|
|
|
{
|
|
|
|
return __arch_hweight32((u32)w) +
|
|
|
|
__arch_hweight32((u32)(w >> 32));
|
2015-08-04 21:15:15 +07:00
|
|
|
}
|
2010-03-05 23:34:46 +07:00
|
|
|
#else
|
2015-08-04 21:15:15 +07:00
|
|
|
static __always_inline unsigned long __arch_hweight64(__u64 w)
|
|
|
|
{
|
2016-05-30 17:56:27 +07:00
|
|
|
unsigned long res;
|
2015-08-04 21:15:15 +07:00
|
|
|
|
2010-05-18 05:13:23 +07:00
|
|
|
asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
|
2016-05-30 17:56:27 +07:00
|
|
|
: "="REG_OUT (res)
|
|
|
|
: REG_IN (w));
|
2010-03-05 23:34:46 +07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2015-08-04 21:15:15 +07:00
|
|
|
#endif /* CONFIG_X86_32 */
|
2010-03-05 23:34:46 +07:00
|
|
|
|
|
|
|
#endif
|