diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2010-02-01 09:03:07 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2010-04-06 18:52:11 -0400 |
commit | 1527bc8b928dd1399c3d3467dd47d9ede210978a (patch) | |
tree | fb391da915bdae9f933b8170ff61aa43c85ef9ae /include/linux/bitops.h | |
parent | 0fdf86754f70e813845af4abaa805165ce57a0bb (diff) |
bitops: Optimize hweight() by making use of compile-time evaluation
Rename the extisting runtime hweight() implementations to
__arch_hweight(), rename the compile-time versions to __const_hweight()
and then have hweight() pick between them.
Suggested-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20100318111929.GB11152@aftab>
Acked-by: H. Peter Anvin <hpa@zytor.com>
LKML-Reference: <1265028224.24455.154.camel@laptop>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'include/linux/bitops.h')
-rw-r--r-- | include/linux/bitops.h | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h index b79389879238..c55d5bc4ee58 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h | |||
@@ -47,31 +47,6 @@ static inline unsigned long hweight_long(unsigned long w) | |||
47 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | 47 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); |
48 | } | 48 | } |
49 | 49 | ||
50 | /* | ||
51 | * Clearly slow versions of the hweightN() functions, their benefit is | ||
52 | * of course compile time evaluation of constant arguments. | ||
53 | */ | ||
54 | #define HWEIGHT8(w) \ | ||
55 | ( BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + \ | ||
56 | (!!((w) & (1ULL << 0))) + \ | ||
57 | (!!((w) & (1ULL << 1))) + \ | ||
58 | (!!((w) & (1ULL << 2))) + \ | ||
59 | (!!((w) & (1ULL << 3))) + \ | ||
60 | (!!((w) & (1ULL << 4))) + \ | ||
61 | (!!((w) & (1ULL << 5))) + \ | ||
62 | (!!((w) & (1ULL << 6))) + \ | ||
63 | (!!((w) & (1ULL << 7))) ) | ||
64 | |||
65 | #define HWEIGHT16(w) (HWEIGHT8(w) + HWEIGHT8((w) >> 8)) | ||
66 | #define HWEIGHT32(w) (HWEIGHT16(w) + HWEIGHT16((w) >> 16)) | ||
67 | #define HWEIGHT64(w) (HWEIGHT32(w) + HWEIGHT32((w) >> 32)) | ||
68 | |||
69 | /* | ||
70 | * Type invariant version that simply casts things to the | ||
71 | * largest type. | ||
72 | */ | ||
73 | #define HWEIGHT(w) HWEIGHT64((u64)(w)) | ||
74 | |||
75 | /** | 50 | /** |
76 | * rol32 - rotate a 32-bit value left | 51 | * rol32 - rotate a 32-bit value left |
77 | * @word: value to rotate | 52 | * @word: value to rotate |