aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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