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