aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bitops.h
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2010-01-22 09:59:29 -0500
committerIngo Molnar <mingo@elte.hu>2010-01-29 03:01:39 -0500
commit9f41699ed067fa695faff8e2e9981b2550abec62 (patch)
treed579511fdefee2dff6d113f7afac1149a3bb6b0d /include/linux/bitops.h
parent8433be1184e4f22c37d4b8ed36cde529a47882f4 (diff)
bitops: Provide compile time HWEIGHT{8,16,32,64}
Provide compile time versions of hweight. Signed-off-by: Peter 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: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/linux/bitops.h')
-rw-r--r--include/linux/bitops.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index c05a29cb9bb2..ba0fd1eb4af7 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -25,7 +25,7 @@
25static __inline__ int get_bitmask_order(unsigned int count) 25static __inline__ int get_bitmask_order(unsigned int count)
26{ 26{
27 int order; 27 int order;
28 28
29 order = fls(count); 29 order = fls(count);
30 return order; /* We could be slightly more clever with -1 here... */ 30 return order; /* We could be slightly more clever with -1 here... */
31} 31}
@@ -33,7 +33,7 @@ static __inline__ int get_bitmask_order(unsigned int count)
33static __inline__ int get_count_order(unsigned int count) 33static __inline__ int get_count_order(unsigned int count)
34{ 34{
35 int order; 35 int order;
36 36
37 order = fls(count) - 1; 37 order = fls(count) - 1;
38 if (count & (count - 1)) 38 if (count & (count - 1))
39 order++; 39 order++;
@@ -45,6 +45,20 @@ static inline unsigned long hweight_long(unsigned long w)
45 return sizeof(w) == 4 ? hweight32(w) : hweight64(w); 45 return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
46} 46}
47 47
48#define HWEIGHT8(w) \
49 ( (!!((w) & (1ULL << 0))) + \
50 (!!((w) & (1ULL << 1))) + \
51 (!!((w) & (1ULL << 2))) + \
52 (!!((w) & (1ULL << 3))) + \
53 (!!((w) & (1ULL << 4))) + \
54 (!!((w) & (1ULL << 5))) + \
55 (!!((w) & (1ULL << 6))) + \
56 (!!((w) & (1ULL << 7))) )
57
58#define HWEIGHT16(w) (HWEIGHT8(w) + HWEIGHT8(w >> 8))
59#define HWEIGHT32(w) (HWEIGHT16(w) + HWEIGHT16(w >> 16))
60#define HWEIGHT64(w) (HWEIGHT32(w) + HWEIGHT32(w >> 32))
61
48/** 62/**
49 * rol32 - rotate a 32-bit value left 63 * rol32 - rotate a 32-bit value left
50 * @word: value to rotate 64 * @word: value to rotate