diff options
Diffstat (limited to 'include/asm-cris/bitops.h')
-rw-r--r-- | include/asm-cris/bitops.h | 235 |
1 files changed, 8 insertions, 227 deletions
diff --git a/include/asm-cris/bitops.h b/include/asm-cris/bitops.h index b7fef1572dc0..a569065113d9 100644 --- a/include/asm-cris/bitops.h +++ b/include/asm-cris/bitops.h | |||
@@ -39,8 +39,6 @@ struct __dummy { unsigned long a[100]; }; | |||
39 | 39 | ||
40 | #define set_bit(nr, addr) (void)test_and_set_bit(nr, addr) | 40 | #define set_bit(nr, addr) (void)test_and_set_bit(nr, addr) |
41 | 41 | ||
42 | #define __set_bit(nr, addr) (void)__test_and_set_bit(nr, addr) | ||
43 | |||
44 | /* | 42 | /* |
45 | * clear_bit - Clears a bit in memory | 43 | * clear_bit - Clears a bit in memory |
46 | * @nr: Bit to clear | 44 | * @nr: Bit to clear |
@@ -54,8 +52,6 @@ struct __dummy { unsigned long a[100]; }; | |||
54 | 52 | ||
55 | #define clear_bit(nr, addr) (void)test_and_clear_bit(nr, addr) | 53 | #define clear_bit(nr, addr) (void)test_and_clear_bit(nr, addr) |
56 | 54 | ||
57 | #define __clear_bit(nr, addr) (void)__test_and_clear_bit(nr, addr) | ||
58 | |||
59 | /* | 55 | /* |
60 | * change_bit - Toggle a bit in memory | 56 | * change_bit - Toggle a bit in memory |
61 | * @nr: Bit to change | 57 | * @nr: Bit to change |
@@ -68,18 +64,6 @@ struct __dummy { unsigned long a[100]; }; | |||
68 | 64 | ||
69 | #define change_bit(nr, addr) (void)test_and_change_bit(nr, addr) | 65 | #define change_bit(nr, addr) (void)test_and_change_bit(nr, addr) |
70 | 66 | ||
71 | /* | ||
72 | * __change_bit - Toggle a bit in memory | ||
73 | * @nr: the bit to change | ||
74 | * @addr: the address to start counting from | ||
75 | * | ||
76 | * Unlike change_bit(), this function is non-atomic and may be reordered. | ||
77 | * If it's called on the same region of memory simultaneously, the effect | ||
78 | * may be that only one operation succeeds. | ||
79 | */ | ||
80 | |||
81 | #define __change_bit(nr, addr) (void)__test_and_change_bit(nr, addr) | ||
82 | |||
83 | /** | 67 | /** |
84 | * test_and_set_bit - Set a bit and return its old value | 68 | * test_and_set_bit - Set a bit and return its old value |
85 | * @nr: Bit to set | 69 | * @nr: Bit to set |
@@ -101,19 +85,6 @@ static inline int test_and_set_bit(int nr, volatile unsigned long *addr) | |||
101 | retval = (mask & *adr) != 0; | 85 | retval = (mask & *adr) != 0; |
102 | *adr |= mask; | 86 | *adr |= mask; |
103 | cris_atomic_restore(addr, flags); | 87 | cris_atomic_restore(addr, flags); |
104 | local_irq_restore(flags); | ||
105 | return retval; | ||
106 | } | ||
107 | |||
108 | static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) | ||
109 | { | ||
110 | unsigned int mask, retval; | ||
111 | unsigned int *adr = (unsigned int *)addr; | ||
112 | |||
113 | adr += nr >> 5; | ||
114 | mask = 1 << (nr & 0x1f); | ||
115 | retval = (mask & *adr) != 0; | ||
116 | *adr |= mask; | ||
117 | return retval; | 88 | return retval; |
118 | } | 89 | } |
119 | 90 | ||
@@ -148,27 +119,6 @@ static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) | |||
148 | } | 119 | } |
149 | 120 | ||
150 | /** | 121 | /** |
151 | * __test_and_clear_bit - Clear a bit and return its old value | ||
152 | * @nr: Bit to clear | ||
153 | * @addr: Address to count from | ||
154 | * | ||
155 | * This operation is non-atomic and can be reordered. | ||
156 | * If two examples of this operation race, one can appear to succeed | ||
157 | * but actually fail. You must protect multiple accesses with a lock. | ||
158 | */ | ||
159 | |||
160 | static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) | ||
161 | { | ||
162 | unsigned int mask, retval; | ||
163 | unsigned int *adr = (unsigned int *)addr; | ||
164 | |||
165 | adr += nr >> 5; | ||
166 | mask = 1 << (nr & 0x1f); | ||
167 | retval = (mask & *adr) != 0; | ||
168 | *adr &= ~mask; | ||
169 | return retval; | ||
170 | } | ||
171 | /** | ||
172 | * test_and_change_bit - Change a bit and return its old value | 122 | * test_and_change_bit - Change a bit and return its old value |
173 | * @nr: Bit to change | 123 | * @nr: Bit to change |
174 | * @addr: Address to count from | 124 | * @addr: Address to count from |
@@ -191,42 +141,7 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr) | |||
191 | return retval; | 141 | return retval; |
192 | } | 142 | } |
193 | 143 | ||
194 | /* WARNING: non atomic and it can be reordered! */ | 144 | #include <asm-generic/bitops/non-atomic.h> |
195 | |||
196 | static inline int __test_and_change_bit(int nr, volatile unsigned long *addr) | ||
197 | { | ||
198 | unsigned int mask, retval; | ||
199 | unsigned int *adr = (unsigned int *)addr; | ||
200 | |||
201 | adr += nr >> 5; | ||
202 | mask = 1 << (nr & 0x1f); | ||
203 | retval = (mask & *adr) != 0; | ||
204 | *adr ^= mask; | ||
205 | |||
206 | return retval; | ||
207 | } | ||
208 | |||
209 | /** | ||
210 | * test_bit - Determine whether a bit is set | ||
211 | * @nr: bit number to test | ||
212 | * @addr: Address to start counting from | ||
213 | * | ||
214 | * This routine doesn't need to be atomic. | ||
215 | */ | ||
216 | |||
217 | static inline int test_bit(int nr, const volatile unsigned long *addr) | ||
218 | { | ||
219 | unsigned int mask; | ||
220 | unsigned int *adr = (unsigned int *)addr; | ||
221 | |||
222 | adr += nr >> 5; | ||
223 | mask = 1 << (nr & 0x1f); | ||
224 | return ((mask & *adr) != 0); | ||
225 | } | ||
226 | |||
227 | /* | ||
228 | * Find-bit routines.. | ||
229 | */ | ||
230 | 145 | ||
231 | /* | 146 | /* |
232 | * Since we define it "external", it collides with the built-in | 147 | * Since we define it "external", it collides with the built-in |
@@ -235,152 +150,18 @@ static inline int test_bit(int nr, const volatile unsigned long *addr) | |||
235 | */ | 150 | */ |
236 | #define ffs kernel_ffs | 151 | #define ffs kernel_ffs |
237 | 152 | ||
238 | /* | 153 | #include <asm-generic/bitops/fls.h> |
239 | * fls: find last bit set. | 154 | #include <asm-generic/bitops/fls64.h> |
240 | */ | 155 | #include <asm-generic/bitops/hweight.h> |
241 | 156 | #include <asm-generic/bitops/find.h> | |
242 | #define fls(x) generic_fls(x) | ||
243 | #define fls64(x) generic_fls64(x) | ||
244 | |||
245 | /* | ||
246 | * hweightN - returns the hamming weight of a N-bit word | ||
247 | * @x: the word to weigh | ||
248 | * | ||
249 | * The Hamming Weight of a number is the total number of bits set in it. | ||
250 | */ | ||
251 | 157 | ||
252 | #define hweight32(x) generic_hweight32(x) | 158 | #include <asm-generic/bitops/ext2-non-atomic.h> |
253 | #define hweight16(x) generic_hweight16(x) | ||
254 | #define hweight8(x) generic_hweight8(x) | ||
255 | 159 | ||
256 | /** | ||
257 | * find_next_zero_bit - find the first zero bit in a memory region | ||
258 | * @addr: The address to base the search on | ||
259 | * @offset: The bitnumber to start searching at | ||
260 | * @size: The maximum size to search | ||
261 | */ | ||
262 | static inline int find_next_zero_bit (const unsigned long * addr, int size, int offset) | ||
263 | { | ||
264 | unsigned long *p = ((unsigned long *) addr) + (offset >> 5); | ||
265 | unsigned long result = offset & ~31UL; | ||
266 | unsigned long tmp; | ||
267 | |||
268 | if (offset >= size) | ||
269 | return size; | ||
270 | size -= result; | ||
271 | offset &= 31UL; | ||
272 | if (offset) { | ||
273 | tmp = *(p++); | ||
274 | tmp |= ~0UL >> (32-offset); | ||
275 | if (size < 32) | ||
276 | goto found_first; | ||
277 | if (~tmp) | ||
278 | goto found_middle; | ||
279 | size -= 32; | ||
280 | result += 32; | ||
281 | } | ||
282 | while (size & ~31UL) { | ||
283 | if (~(tmp = *(p++))) | ||
284 | goto found_middle; | ||
285 | result += 32; | ||
286 | size -= 32; | ||
287 | } | ||
288 | if (!size) | ||
289 | return result; | ||
290 | tmp = *p; | ||
291 | |||
292 | found_first: | ||
293 | tmp |= ~0UL << size; | ||
294 | found_middle: | ||
295 | return result + ffz(tmp); | ||
296 | } | ||
297 | |||
298 | /** | ||
299 | * find_next_bit - find the first set bit in a memory region | ||
300 | * @addr: The address to base the search on | ||
301 | * @offset: The bitnumber to start searching at | ||
302 | * @size: The maximum size to search | ||
303 | */ | ||
304 | static __inline__ int find_next_bit(const unsigned long *addr, int size, int offset) | ||
305 | { | ||
306 | unsigned long *p = ((unsigned long *) addr) + (offset >> 5); | ||
307 | unsigned long result = offset & ~31UL; | ||
308 | unsigned long tmp; | ||
309 | |||
310 | if (offset >= size) | ||
311 | return size; | ||
312 | size -= result; | ||
313 | offset &= 31UL; | ||
314 | if (offset) { | ||
315 | tmp = *(p++); | ||
316 | tmp &= (~0UL << offset); | ||
317 | if (size < 32) | ||
318 | goto found_first; | ||
319 | if (tmp) | ||
320 | goto found_middle; | ||
321 | size -= 32; | ||
322 | result += 32; | ||
323 | } | ||
324 | while (size & ~31UL) { | ||
325 | if ((tmp = *(p++))) | ||
326 | goto found_middle; | ||
327 | result += 32; | ||
328 | size -= 32; | ||
329 | } | ||
330 | if (!size) | ||
331 | return result; | ||
332 | tmp = *p; | ||
333 | |||
334 | found_first: | ||
335 | tmp &= (~0UL >> (32 - size)); | ||
336 | if (tmp == 0UL) /* Are any bits set? */ | ||
337 | return result + size; /* Nope. */ | ||
338 | found_middle: | ||
339 | return result + __ffs(tmp); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * find_first_zero_bit - find the first zero bit in a memory region | ||
344 | * @addr: The address to start the search at | ||
345 | * @size: The maximum size to search | ||
346 | * | ||
347 | * Returns the bit-number of the first zero bit, not the number of the byte | ||
348 | * containing a bit. | ||
349 | */ | ||
350 | |||
351 | #define find_first_zero_bit(addr, size) \ | ||
352 | find_next_zero_bit((addr), (size), 0) | ||
353 | #define find_first_bit(addr, size) \ | ||
354 | find_next_bit((addr), (size), 0) | ||
355 | |||
356 | #define ext2_set_bit test_and_set_bit | ||
357 | #define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a) | 160 | #define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a) |
358 | #define ext2_clear_bit test_and_clear_bit | ||
359 | #define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a) | 161 | #define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a) |
360 | #define ext2_test_bit test_bit | ||
361 | #define ext2_find_first_zero_bit find_first_zero_bit | ||
362 | #define ext2_find_next_zero_bit find_next_zero_bit | ||
363 | |||
364 | /* Bitmap functions for the minix filesystem. */ | ||
365 | #define minix_set_bit(nr,addr) test_and_set_bit(nr,addr) | ||
366 | #define minix_clear_bit(nr,addr) test_and_clear_bit(nr,addr) | ||
367 | #define minix_test_bit(nr,addr) test_bit(nr,addr) | ||
368 | #define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size) | ||
369 | 162 | ||
370 | static inline int sched_find_first_bit(const unsigned long *b) | 163 | #include <asm-generic/bitops/minix.h> |
371 | { | 164 | #include <asm-generic/bitops/sched.h> |
372 | if (unlikely(b[0])) | ||
373 | return __ffs(b[0]); | ||
374 | if (unlikely(b[1])) | ||
375 | return __ffs(b[1]) + 32; | ||
376 | if (unlikely(b[2])) | ||
377 | return __ffs(b[2]) + 64; | ||
378 | if (unlikely(b[3])) | ||
379 | return __ffs(b[3]) + 96; | ||
380 | if (b[4]) | ||
381 | return __ffs(b[4]) + 128; | ||
382 | return __ffs(b[5]) + 32 + 128; | ||
383 | } | ||
384 | 165 | ||
385 | #endif /* __KERNEL__ */ | 166 | #endif /* __KERNEL__ */ |
386 | 167 | ||