diff options
author | Borislav Petkov <borislav.petkov@amd.com> | 2010-03-05 11:34:46 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2010-04-06 18:52:11 -0400 |
commit | d61931d89be506372d01a90d1755f6d0a9fafe2d (patch) | |
tree | 652c34238edcb6c558163abc3cd9d6ce7c5f91a5 /include | |
parent | 1527bc8b928dd1399c3d3467dd47d9ede210978a (diff) |
x86: Add optimized popcnt variants
Add support for the hardware version of the Hamming weight function,
popcnt, present in CPUs which advertize it under CPUID, Function
0x0000_0001_ECX[23]. On CPUs which don't support it, we fallback to the
default lib/hweight.c sw versions.
A synthetic benchmark comparing popcnt with __sw_hweight64 showed almost
a 3x speedup on a F10h machine.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
LKML-Reference: <20100318112015.GC11152@aftab>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-generic/bitops/arch_hweight.h | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/include/asm-generic/bitops/arch_hweight.h b/include/asm-generic/bitops/arch_hweight.h index 3a7be842cdce..9a81c1e9436c 100644 --- a/include/asm-generic/bitops/arch_hweight.h +++ b/include/asm-generic/bitops/arch_hweight.h | |||
@@ -3,9 +3,23 @@ | |||
3 | 3 | ||
4 | #include <asm/types.h> | 4 | #include <asm/types.h> |
5 | 5 | ||
6 | extern unsigned int __arch_hweight32(unsigned int w); | 6 | inline unsigned int __arch_hweight32(unsigned int w) |
7 | extern unsigned int __arch_hweight16(unsigned int w); | 7 | { |
8 | extern unsigned int __arch_hweight8(unsigned int w); | 8 | return __sw_hweight32(w); |
9 | extern unsigned long __arch_hweight64(__u64 w); | 9 | } |
10 | 10 | ||
11 | inline unsigned int __arch_hweight16(unsigned int w) | ||
12 | { | ||
13 | return __sw_hweight16(w); | ||
14 | } | ||
15 | |||
16 | inline unsigned int __arch_hweight8(unsigned int w) | ||
17 | { | ||
18 | return __sw_hweight8(w); | ||
19 | } | ||
20 | |||
21 | inline unsigned long __arch_hweight64(__u64 w) | ||
22 | { | ||
23 | return __sw_hweight64(w); | ||
24 | } | ||
11 | #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ | 25 | #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ |