Commit 9f41699e authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

bitops: Provide compile time HWEIGHT{8,16,32,64}

Provide compile time versions of hweight.
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <20100122155535.797688466@chello.nl>
[ Remove some whitespace damage while we are at it ]
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 8433be11
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
static __inline__ int get_bitmask_order(unsigned int count) static __inline__ int get_bitmask_order(unsigned int count)
{ {
int order; int order;
order = fls(count); order = fls(count);
return order; /* We could be slightly more clever with -1 here... */ return order; /* We could be slightly more clever with -1 here... */
} }
...@@ -33,7 +33,7 @@ static __inline__ int get_bitmask_order(unsigned int count) ...@@ -33,7 +33,7 @@ static __inline__ int get_bitmask_order(unsigned int count)
static __inline__ int get_count_order(unsigned int count) static __inline__ int get_count_order(unsigned int count)
{ {
int order; int order;
order = fls(count) - 1; order = fls(count) - 1;
if (count & (count - 1)) if (count & (count - 1))
order++; order++;
...@@ -45,6 +45,20 @@ static inline unsigned long hweight_long(unsigned long w) ...@@ -45,6 +45,20 @@ static inline unsigned long hweight_long(unsigned long w)
return sizeof(w) == 4 ? hweight32(w) : hweight64(w); return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
} }
#define 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 HWEIGHT16(w) (HWEIGHT8(w) + HWEIGHT8(w >> 8))
#define HWEIGHT32(w) (HWEIGHT16(w) + HWEIGHT16(w >> 16))
#define HWEIGHT64(w) (HWEIGHT32(w) + HWEIGHT32(w >> 32))
/** /**
* rol32 - rotate a 32-bit value left * rol32 - rotate a 32-bit value left
* @word: value to rotate * @word: value to rotate
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment