Rev 1408 | Rev 3031 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1408 | Rev 1964 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef _LINUX_BITOPS_H |
1 | #ifndef _LINUX_BITOPS_H |
2 | #define _LINUX_BITOPS_H |
2 | #define _LINUX_BITOPS_H |
- | 3 | #include |
|
Line -... | Line 4... | ||
- | 4 | ||
3 | 5 | #ifdef __KERNEL__ |
|
4 | #define BIT(nr) (1UL << (nr)) |
6 | #define BIT(nr) (1UL << (nr)) |
5 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) |
7 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) |
6 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) |
8 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) |
7 | #define BITS_PER_BYTE 8 |
9 | #define BITS_PER_BYTE 8 |
- | 10 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
|
- | 11 | #endif |
|
- | 12 | ||
- | 13 | extern unsigned int __sw_hweight8(unsigned int w); |
|
- | 14 | extern unsigned int __sw_hweight16(unsigned int w); |
|
- | 15 | extern unsigned int __sw_hweight32(unsigned int w); |
|
Line 8... | Line 16... | ||
8 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
16 | extern unsigned long __sw_hweight64(__u64 w); |
9 | 17 | ||
10 | /* |
18 | /* |
11 | * Include this here because some architectures need generic_ffs/fls in |
19 | * Include this here because some architectures need generic_ffs/fls in |
12 | * scope |
20 | * scope |
Line 13... | Line 21... | ||
13 | */ |
21 | */ |
14 | #include |
22 | #include |
15 | 23 | ||
16 | #define for_each_bit(bit, addr, size) \ |
24 | #define for_each_set_bit(bit, addr, size) \ |
Line 17... | Line -... | ||
17 | for ((bit) = find_first_bit((addr), (size)); \ |
- | |
18 | (bit) < (size); \ |
25 | for ((bit) = find_first_bit((addr), (size)); \ |
19 | (bit) = find_next_bit((addr), (size), (bit) + 1)) |
26 | (bit) < (size); \ |
20 | 27 | (bit) = find_next_bit((addr), (size), (bit) + 1)) |
|
Line 21... | Line 28... | ||
21 | 28 | ||
Line 127... | Line 134... | ||
127 | #endif |
134 | #endif |
128 | return __ffs((unsigned long)word); |
135 | return __ffs((unsigned long)word); |
129 | } |
136 | } |
Line 130... | Line 137... | ||
130 | 137 | ||
131 | #ifdef __KERNEL__ |
- | |
132 | #ifdef CONFIG_GENERIC_FIND_FIRST_BIT |
- | |
133 | - | ||
134 | /** |
- | |
135 | * find_first_bit - find the first set bit in a memory region |
- | |
136 | * @addr: The address to start the search at |
- | |
137 | * @size: The maximum size to search |
- | |
138 | * |
- | |
139 | * Returns the bit number of the first set bit. |
- | |
140 | */ |
- | |
141 | extern unsigned long find_first_bit(const unsigned long *addr, |
- | |
142 | unsigned long size); |
- | |
143 | - | ||
144 | /** |
- | |
145 | * find_first_zero_bit - find the first cleared bit in a memory region |
- | |
146 | * @addr: The address to start the search at |
- | |
147 | * @size: The maximum size to search |
- | |
148 | * |
- | |
149 | * Returns the bit number of the first cleared bit. |
- | |
150 | */ |
- | |
151 | extern unsigned long find_first_zero_bit(const unsigned long *addr, |
- | |
152 | unsigned long size); |
- | |
Line 153... | Line 138... | ||
153 | #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ |
138 | #ifdef __KERNEL__ |
154 | 139 | ||
155 | #ifdef CONFIG_GENERIC_FIND_LAST_BIT |
140 | #ifdef CONFIG_GENERIC_FIND_LAST_BIT |
156 | /** |
141 | /** |
Line 162... | Line 147... | ||
162 | */ |
147 | */ |
163 | extern unsigned long find_last_bit(const unsigned long *addr, |
148 | extern unsigned long find_last_bit(const unsigned long *addr, |
164 | unsigned long size); |
149 | unsigned long size); |
165 | #endif /* CONFIG_GENERIC_FIND_LAST_BIT */ |
150 | #endif /* CONFIG_GENERIC_FIND_LAST_BIT */ |
Line 166... | Line -... | ||
166 | - | ||
167 | #ifdef CONFIG_GENERIC_FIND_NEXT_BIT |
- | |
168 | - | ||
169 | /** |
- | |
170 | * find_next_bit - find the next set bit in a memory region |
- | |
171 | * @addr: The address to base the search on |
- | |
172 | * @offset: The bitnumber to start searching at |
- | |
173 | * @size: The bitmap size in bits |
- | |
174 | */ |
- | |
175 | extern unsigned long find_next_bit(const unsigned long *addr, |
- | |
176 | unsigned long size, unsigned long offset); |
- | |
177 | - | ||
178 | /** |
- | |
179 | * find_next_zero_bit - find the next cleared bit in a memory region |
- | |
180 | * @addr: The address to base the search on |
- | |
181 | * @offset: The bitnumber to start searching at |
- | |
182 | * @size: The bitmap size in bits |
- | |
183 | */ |
- | |
184 | - | ||
185 | extern unsigned long find_next_zero_bit(const unsigned long *addr, |
- | |
186 | unsigned long size, |
- | |
187 | unsigned long offset); |
- | |
188 | - | ||
189 | #endif /* CONFIG_GENERIC_FIND_NEXT_BIT */ |
151 | |
190 | #endif /* __KERNEL__ */ |
152 | #endif /* __KERNEL__ */ |