forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'core-hweight-for-linus' of git://git.kernel.org/pub/scm…
…/linux/kernel/git/tip/linux-2.6-tip * 'core-hweight-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, hweight: Use a 32-bit popcnt for __arch_hweight32() arch, hweight: Fix compilation errors x86: Add optimized popcnt variants bitops: Optimize hweight() by making use of compile-time evaluation
- Loading branch information
Showing
14 changed files
with
188 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef _ASM_X86_HWEIGHT_H | ||
#define _ASM_X86_HWEIGHT_H | ||
|
||
#ifdef CONFIG_64BIT | ||
/* popcnt %edi, %eax -- redundant REX prefix for alignment */ | ||
#define POPCNT32 ".byte 0xf3,0x40,0x0f,0xb8,0xc7" | ||
/* popcnt %rdi, %rax */ | ||
#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7" | ||
#define REG_IN "D" | ||
#define REG_OUT "a" | ||
#else | ||
/* popcnt %eax, %eax */ | ||
#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0" | ||
#define REG_IN "a" | ||
#define REG_OUT "a" | ||
#endif | ||
|
||
/* | ||
* __sw_hweightXX are called from within the alternatives below | ||
* and callee-clobbered registers need to be taken care of. See | ||
* ARCH_HWEIGHT_CFLAGS in <arch/x86/Kconfig> for the respective | ||
* compiler switches. | ||
*/ | ||
static inline unsigned int __arch_hweight32(unsigned int w) | ||
{ | ||
unsigned int res = 0; | ||
|
||
asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT) | ||
: "="REG_OUT (res) | ||
: REG_IN (w)); | ||
|
||
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); | ||
} | ||
|
||
static inline unsigned long __arch_hweight64(__u64 w) | ||
{ | ||
unsigned long res = 0; | ||
|
||
#ifdef CONFIG_X86_32 | ||
return __arch_hweight32((u32)w) + | ||
__arch_hweight32((u32)(w >> 32)); | ||
#else | ||
asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) | ||
: "="REG_OUT (res) | ||
: REG_IN (w)); | ||
#endif /* CONFIG_X86_32 */ | ||
|
||
return res; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ | ||
#define _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ | ||
|
||
#include <asm/types.h> | ||
|
||
static inline unsigned int __arch_hweight32(unsigned int w) | ||
{ | ||
return __sw_hweight32(w); | ||
} | ||
|
||
static inline unsigned int __arch_hweight16(unsigned int w) | ||
{ | ||
return __sw_hweight16(w); | ||
} | ||
|
||
static inline unsigned int __arch_hweight8(unsigned int w) | ||
{ | ||
return __sw_hweight8(w); | ||
} | ||
|
||
static inline unsigned long __arch_hweight64(__u64 w) | ||
{ | ||
return __sw_hweight64(w); | ||
} | ||
#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ | ||
#define _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ | ||
|
||
/* | ||
* Compile time versions of __arch_hweightN() | ||
*/ | ||
#define __const_hweight8(w) \ | ||
( (!!((w) & (1ULL << 0))) + \ | ||
(!!((w) & (1ULL << 1))) + \ | ||
(!!((w) & (1ULL << 2))) + \ | ||
(!!((w) & (1ULL << 3))) + \ | ||
(!!((w) & (1ULL << 4))) + \ | ||
(!!((w) & (1ULL << 5))) + \ | ||
(!!((w) & (1ULL << 6))) + \ | ||
(!!((w) & (1ULL << 7))) ) | ||
|
||
#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 )) | ||
#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16)) | ||
#define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32)) | ||
|
||
/* | ||
* Generic interface. | ||
*/ | ||
#define hweight8(w) (__builtin_constant_p(w) ? __const_hweight8(w) : __arch_hweight8(w)) | ||
#define hweight16(w) (__builtin_constant_p(w) ? __const_hweight16(w) : __arch_hweight16(w)) | ||
#define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w)) | ||
#define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w)) | ||
|
||
/* | ||
* Interface for known constant arguments | ||
*/ | ||
#define HWEIGHT8(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight8(w)) | ||
#define HWEIGHT16(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight16(w)) | ||
#define HWEIGHT32(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight32(w)) | ||
#define HWEIGHT64(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight64(w)) | ||
|
||
/* | ||
* Type invariant interface to the compile time constant hweight functions. | ||
*/ | ||
#define HWEIGHT(w) HWEIGHT64((u64)w) | ||
|
||
#endif /* _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ | ||
#define _ASM_GENERIC_BITOPS_HWEIGHT_H_ | ||
|
||
#include <asm/types.h> | ||
|
||
extern unsigned int hweight32(unsigned int w); | ||
extern unsigned int hweight16(unsigned int w); | ||
extern unsigned int hweight8(unsigned int w); | ||
extern unsigned long hweight64(__u64 w); | ||
#include <asm-generic/bitops/arch_hweight.h> | ||
#include <asm-generic/bitops/const_hweight.h> | ||
|
||
#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.