diff options
Diffstat (limited to 'tools/testing/radix-tree/linux/bitops.h')
-rw-r--r-- | tools/testing/radix-tree/linux/bitops.h | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/tools/testing/radix-tree/linux/bitops.h b/tools/testing/radix-tree/linux/bitops.h index 71d58427ab60..a13e9bc76eec 100644 --- a/tools/testing/radix-tree/linux/bitops.h +++ b/tools/testing/radix-tree/linux/bitops.h | |||
@@ -2,9 +2,14 @@ | |||
2 | #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ | 2 | #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ |
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | #include <linux/bitops/find.h> | ||
6 | #include <linux/bitops/hweight.h> | ||
7 | #include <linux/kernel.h> | ||
5 | 8 | ||
6 | #define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) | 9 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) |
7 | #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) | 10 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) |
11 | #define BITS_PER_BYTE 8 | ||
12 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) | ||
8 | 13 | ||
9 | /** | 14 | /** |
10 | * __set_bit - Set a bit in memory | 15 | * __set_bit - Set a bit in memory |
@@ -17,16 +22,16 @@ | |||
17 | */ | 22 | */ |
18 | static inline void __set_bit(int nr, volatile unsigned long *addr) | 23 | static inline void __set_bit(int nr, volatile unsigned long *addr) |
19 | { | 24 | { |
20 | unsigned long mask = BITOP_MASK(nr); | 25 | unsigned long mask = BIT_MASK(nr); |
21 | unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); | 26 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); |
22 | 27 | ||
23 | *p |= mask; | 28 | *p |= mask; |
24 | } | 29 | } |
25 | 30 | ||
26 | static inline void __clear_bit(int nr, volatile unsigned long *addr) | 31 | static inline void __clear_bit(int nr, volatile unsigned long *addr) |
27 | { | 32 | { |
28 | unsigned long mask = BITOP_MASK(nr); | 33 | unsigned long mask = BIT_MASK(nr); |
29 | unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); | 34 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); |
30 | 35 | ||
31 | *p &= ~mask; | 36 | *p &= ~mask; |
32 | } | 37 | } |
@@ -42,8 +47,8 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr) | |||
42 | */ | 47 | */ |
43 | static inline void __change_bit(int nr, volatile unsigned long *addr) | 48 | static inline void __change_bit(int nr, volatile unsigned long *addr) |
44 | { | 49 | { |
45 | unsigned long mask = BITOP_MASK(nr); | 50 | unsigned long mask = BIT_MASK(nr); |
46 | unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); | 51 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); |
47 | 52 | ||
48 | *p ^= mask; | 53 | *p ^= mask; |
49 | } | 54 | } |
@@ -59,8 +64,8 @@ static inline void __change_bit(int nr, volatile unsigned long *addr) | |||
59 | */ | 64 | */ |
60 | static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) | 65 | static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) |
61 | { | 66 | { |
62 | unsigned long mask = BITOP_MASK(nr); | 67 | unsigned long mask = BIT_MASK(nr); |
63 | unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); | 68 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); |
64 | unsigned long old = *p; | 69 | unsigned long old = *p; |
65 | 70 | ||
66 | *p = old | mask; | 71 | *p = old | mask; |
@@ -78,8 +83,8 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) | |||
78 | */ | 83 | */ |
79 | static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) | 84 | static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) |
80 | { | 85 | { |
81 | unsigned long mask = BITOP_MASK(nr); | 86 | unsigned long mask = BIT_MASK(nr); |
82 | unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); | 87 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); |
83 | unsigned long old = *p; | 88 | unsigned long old = *p; |
84 | 89 | ||
85 | *p = old & ~mask; | 90 | *p = old & ~mask; |
@@ -90,8 +95,8 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) | |||
90 | static inline int __test_and_change_bit(int nr, | 95 | static inline int __test_and_change_bit(int nr, |
91 | volatile unsigned long *addr) | 96 | volatile unsigned long *addr) |
92 | { | 97 | { |
93 | unsigned long mask = BITOP_MASK(nr); | 98 | unsigned long mask = BIT_MASK(nr); |
94 | unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); | 99 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); |
95 | unsigned long old = *p; | 100 | unsigned long old = *p; |
96 | 101 | ||
97 | *p = old ^ mask; | 102 | *p = old ^ mask; |
@@ -105,7 +110,7 @@ static inline int __test_and_change_bit(int nr, | |||
105 | */ | 110 | */ |
106 | static inline int test_bit(int nr, const volatile unsigned long *addr) | 111 | static inline int test_bit(int nr, const volatile unsigned long *addr) |
107 | { | 112 | { |
108 | return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); | 113 | return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); |
109 | } | 114 | } |
110 | 115 | ||
111 | /** | 116 | /** |
@@ -147,4 +152,9 @@ unsigned long find_next_bit(const unsigned long *addr, | |||
147 | unsigned long size, | 152 | unsigned long size, |
148 | unsigned long offset); | 153 | unsigned long offset); |
149 | 154 | ||
155 | static inline unsigned long hweight_long(unsigned long w) | ||
156 | { | ||
157 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | ||
158 | } | ||
159 | |||
150 | #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */ | 160 | #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */ |