aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sh64/bitops.h
diff options
context:
space:
mode:
authorAkinobu Mita <mita@miraclelinux.com>2006-03-26 04:39:37 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-26 11:57:14 -0500
commit62f1b2465bdf77bb95037a5418040edb2af142d0 (patch)
tree8243a25283889278cbf6674ad4771dc638cdec33 /include/asm-sh64/bitops.h
parente2268c7129e6cab53a5dac1ab0790a547555e21a (diff)
[PATCH] bitops: sh64: use generic bitops
- remove __{,test_and_}{set,clear,change}_bit() and test_bit() - remove __ffs() - remove find_{next,first}{,_zero}_bit() - remove generic_hweight{32,16,8}() - remove sched_find_first_bit() - remove generic_ffs() - remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit() - remove ext2_{set,clear}_bit_atomic() - remove minix_{test,set,test_and_clear,test,find_first_zero}_bit() - remove generic_fls() - remove generic_fls64() Signed-off-by: Akinobu Mita <mita@miraclelinux.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Richard Curnow <rc@rc0.org.uk> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-sh64/bitops.h')
-rw-r--r--include/asm-sh64/bitops.h384
1 files changed, 11 insertions, 373 deletions
diff --git a/include/asm-sh64/bitops.h b/include/asm-sh64/bitops.h
index 5622b1a50cb1..f3bdcdb5d046 100644
--- a/include/asm-sh64/bitops.h
+++ b/include/asm-sh64/bitops.h
@@ -31,16 +31,6 @@ static __inline__ void set_bit(int nr, volatile void * addr)
31 local_irq_restore(flags); 31 local_irq_restore(flags);
32} 32}
33 33
34static inline void __set_bit(int nr, void *addr)
35{
36 int mask;
37 unsigned int *a = addr;
38
39 a += nr >> 5;
40 mask = 1 << (nr & 0x1f);
41 *a |= mask;
42}
43
44/* 34/*
45 * clear_bit() doesn't provide any barrier for the compiler. 35 * clear_bit() doesn't provide any barrier for the compiler.
46 */ 36 */
@@ -58,15 +48,6 @@ static inline void clear_bit(int nr, volatile unsigned long *a)
58 local_irq_restore(flags); 48 local_irq_restore(flags);
59} 49}
60 50
61static inline void __clear_bit(int nr, volatile unsigned long *a)
62{
63 int mask;
64
65 a += nr >> 5;
66 mask = 1 << (nr & 0x1f);
67 *a &= ~mask;
68}
69
70static __inline__ void change_bit(int nr, volatile void * addr) 51static __inline__ void change_bit(int nr, volatile void * addr)
71{ 52{
72 int mask; 53 int mask;
@@ -80,16 +61,6 @@ static __inline__ void change_bit(int nr, volatile void * addr)
80 local_irq_restore(flags); 61 local_irq_restore(flags);
81} 62}
82 63
83static __inline__ void __change_bit(int nr, volatile void * addr)
84{
85 int mask;
86 volatile unsigned int *a = addr;
87
88 a += nr >> 5;
89 mask = 1 << (nr & 0x1f);
90 *a ^= mask;
91}
92
93static __inline__ int test_and_set_bit(int nr, volatile void * addr) 64static __inline__ int test_and_set_bit(int nr, volatile void * addr)
94{ 65{
95 int mask, retval; 66 int mask, retval;
@@ -106,19 +77,6 @@ static __inline__ int test_and_set_bit(int nr, volatile void * addr)
106 return retval; 77 return retval;
107} 78}
108 79
109static __inline__ int __test_and_set_bit(int nr, volatile void * addr)
110{
111 int mask, retval;
112 volatile unsigned int *a = addr;
113
114 a += nr >> 5;
115 mask = 1 << (nr & 0x1f);
116 retval = (mask & *a) != 0;
117 *a |= mask;
118
119 return retval;
120}
121
122static __inline__ int test_and_clear_bit(int nr, volatile void * addr) 80static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
123{ 81{
124 int mask, retval; 82 int mask, retval;
@@ -135,19 +93,6 @@ static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
135 return retval; 93 return retval;
136} 94}
137 95
138static __inline__ int __test_and_clear_bit(int nr, volatile void * addr)
139{
140 int mask, retval;
141 volatile unsigned int *a = addr;
142
143 a += nr >> 5;
144 mask = 1 << (nr & 0x1f);
145 retval = (mask & *a) != 0;
146 *a &= ~mask;
147
148 return retval;
149}
150
151static __inline__ int test_and_change_bit(int nr, volatile void * addr) 96static __inline__ int test_and_change_bit(int nr, volatile void * addr)
152{ 97{
153 int mask, retval; 98 int mask, retval;
@@ -164,23 +109,7 @@ static __inline__ int test_and_change_bit(int nr, volatile void * addr)
164 return retval; 109 return retval;
165} 110}
166 111
167static __inline__ int __test_and_change_bit(int nr, volatile void * addr) 112#include <asm-generic/bitops/non-atomic.h>
168{
169 int mask, retval;
170 volatile unsigned int *a = addr;
171
172 a += nr >> 5;
173 mask = 1 << (nr & 0x1f);
174 retval = (mask & *a) != 0;
175 *a ^= mask;
176
177 return retval;
178}
179
180static __inline__ int test_bit(int nr, const volatile void *addr)
181{
182 return 1UL & (((const volatile unsigned int *) addr)[nr >> 5] >> (nr & 31));
183}
184 113
185static __inline__ unsigned long ffz(unsigned long word) 114static __inline__ unsigned long ffz(unsigned long word)
186{ 115{
@@ -204,307 +133,16 @@ static __inline__ unsigned long ffz(unsigned long word)
204 return result; 133 return result;
205} 134}
206 135
207/** 136#include <asm-generic/bitops/__ffs.h>
208 * __ffs - find first bit in word 137#include <asm-generic/bitops/find.h>
209 * @word: The word to search 138#include <asm-generic/bitops/hweight.h>
210 * 139#include <asm-generic/bitops/sched.h>
211 * Undefined if no bit exists, so code should check against 0 first. 140#include <asm-generic/bitops/ffs.h>
212 */ 141#include <asm-generic/bitops/ext2-non-atomic.h>
213static inline unsigned long __ffs(unsigned long word) 142#include <asm-generic/bitops/ext2-atomic.h>
214{ 143#include <asm-generic/bitops/minix.h>
215 int r = 0; 144#include <asm-generic/bitops/fls.h>
216 145#include <asm-generic/bitops/fls64.h>
217 if (!word)
218 return 0;
219 if (!(word & 0xffff)) {
220 word >>= 16;
221 r += 16;
222 }
223 if (!(word & 0xff)) {
224 word >>= 8;
225 r += 8;
226 }
227 if (!(word & 0xf)) {
228 word >>= 4;
229 r += 4;
230 }
231 if (!(word & 3)) {
232 word >>= 2;
233 r += 2;
234 }
235 if (!(word & 1)) {
236 word >>= 1;
237 r += 1;
238 }
239 return r;
240}
241
242/**
243 * find_next_bit - find the next set bit in a memory region
244 * @addr: The address to base the search on
245 * @offset: The bitnumber to start searching at
246 * @size: The maximum size to search
247 */
248static inline unsigned long find_next_bit(const unsigned long *addr,
249 unsigned long size, unsigned long offset)
250{
251 unsigned int *p = ((unsigned int *) addr) + (offset >> 5);
252 unsigned int result = offset & ~31UL;
253 unsigned int tmp;
254
255 if (offset >= size)
256 return size;
257 size -= result;
258 offset &= 31UL;
259 if (offset) {
260 tmp = *p++;
261 tmp &= ~0UL << offset;
262 if (size < 32)
263 goto found_first;
264 if (tmp)
265 goto found_middle;
266 size -= 32;
267 result += 32;
268 }
269 while (size >= 32) {
270 if ((tmp = *p++) != 0)
271 goto found_middle;
272 result += 32;
273 size -= 32;
274 }
275 if (!size)
276 return result;
277 tmp = *p;
278
279found_first:
280 tmp &= ~0UL >> (32 - size);
281 if (tmp == 0UL) /* Are any bits set? */
282 return result + size; /* Nope. */
283found_middle:
284 return result + __ffs(tmp);
285}
286
287/**
288 * find_first_bit - find the first set bit in a memory region
289 * @addr: The address to start the search at
290 * @size: The maximum size to search
291 *
292 * Returns the bit-number of the first set bit, not the number of the byte
293 * containing a bit.
294 */
295#define find_first_bit(addr, size) \
296 find_next_bit((addr), (size), 0)
297
298
299static inline int find_next_zero_bit(void *addr, int size, int offset)
300{
301 unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
302 unsigned long result = offset & ~31UL;
303 unsigned long tmp;
304
305 if (offset >= size)
306 return size;
307 size -= result;
308 offset &= 31UL;
309 if (offset) {
310 tmp = *(p++);
311 tmp |= ~0UL >> (32-offset);
312 if (size < 32)
313 goto found_first;
314 if (~tmp)
315 goto found_middle;
316 size -= 32;
317 result += 32;
318 }
319 while (size & ~31UL) {
320 if (~(tmp = *(p++)))
321 goto found_middle;
322 result += 32;
323 size -= 32;
324 }
325 if (!size)
326 return result;
327 tmp = *p;
328
329found_first:
330 tmp |= ~0UL << size;
331found_middle:
332 return result + ffz(tmp);
333}
334
335#define find_first_zero_bit(addr, size) \
336 find_next_zero_bit((addr), (size), 0)
337
338/*
339 * hweightN: returns the hamming weight (i.e. the number
340 * of bits set) of a N-bit word
341 */
342
343#define hweight32(x) generic_hweight32(x)
344#define hweight16(x) generic_hweight16(x)
345#define hweight8(x) generic_hweight8(x)
346
347/*
348 * Every architecture must define this function. It's the fastest
349 * way of searching a 140-bit bitmap where the first 100 bits are
350 * unlikely to be set. It's guaranteed that at least one of the 140
351 * bits is cleared.
352 */
353
354static inline int sched_find_first_bit(unsigned long *b)
355{
356 if (unlikely(b[0]))
357 return __ffs(b[0]);
358 if (unlikely(b[1]))
359 return __ffs(b[1]) + 32;
360 if (unlikely(b[2]))
361 return __ffs(b[2]) + 64;
362 if (b[3])
363 return __ffs(b[3]) + 96;
364 return __ffs(b[4]) + 128;
365}
366
367/*
368 * ffs: find first bit set. This is defined the same way as
369 * the libc and compiler builtin ffs routines, therefore
370 * differs in spirit from the above ffz (man ffs).
371 */
372
373#define ffs(x) generic_ffs(x)
374
375/*
376 * hweightN: returns the hamming weight (i.e. the number
377 * of bits set) of a N-bit word
378 */
379
380#define hweight32(x) generic_hweight32(x)
381#define hweight16(x) generic_hweight16(x)
382#define hweight8(x) generic_hweight8(x)
383
384#ifdef __LITTLE_ENDIAN__
385#define ext2_set_bit(nr, addr) __test_and_set_bit((nr), (addr))
386#define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr), (addr))
387#define ext2_test_bit(nr, addr) test_bit((nr), (addr))
388#define ext2_find_first_zero_bit(addr, size) find_first_zero_bit((addr), (size))
389#define ext2_find_next_zero_bit(addr, size, offset) \
390 find_next_zero_bit((addr), (size), (offset))
391#else
392static __inline__ int ext2_set_bit(int nr, volatile void * addr)
393{
394 int mask, retval;
395 volatile unsigned char *ADDR = (unsigned char *) addr;
396
397 ADDR += nr >> 3;
398 mask = 1 << (nr & 0x07);
399 retval = (mask & *ADDR) != 0;
400 *ADDR |= mask;
401 return retval;
402}
403
404static __inline__ int ext2_clear_bit(int nr, volatile void * addr)
405{
406 int mask, retval;
407 volatile unsigned char *ADDR = (unsigned char *) addr;
408
409 ADDR += nr >> 3;
410 mask = 1 << (nr & 0x07);
411 retval = (mask & *ADDR) != 0;
412 *ADDR &= ~mask;
413 return retval;
414}
415
416static __inline__ int ext2_test_bit(int nr, const volatile void * addr)
417{
418 int mask;
419 const volatile unsigned char *ADDR = (const unsigned char *) addr;
420
421 ADDR += nr >> 3;
422 mask = 1 << (nr & 0x07);
423 return ((mask & *ADDR) != 0);
424}
425
426#define ext2_find_first_zero_bit(addr, size) \
427 ext2_find_next_zero_bit((addr), (size), 0)
428
429static __inline__ unsigned long ext2_find_next_zero_bit(void *addr, unsigned long size, unsigned long offset)
430{
431 unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
432 unsigned long result = offset & ~31UL;
433 unsigned long tmp;
434
435 if (offset >= size)
436 return size;
437 size -= result;
438 offset &= 31UL;
439 if(offset) {
440 /* We hold the little endian value in tmp, but then the
441 * shift is illegal. So we could keep a big endian value
442 * in tmp, like this:
443 *
444 * tmp = __swab32(*(p++));
445 * tmp |= ~0UL >> (32-offset);
446 *
447 * but this would decrease preformance, so we change the
448 * shift:
449 */
450 tmp = *(p++);
451 tmp |= __swab32(~0UL >> (32-offset));
452 if(size < 32)
453 goto found_first;
454 if(~tmp)
455 goto found_middle;
456 size -= 32;
457 result += 32;
458 }
459 while(size & ~31UL) {
460 if(~(tmp = *(p++)))
461 goto found_middle;
462 result += 32;
463 size -= 32;
464 }
465 if(!size)
466 return result;
467 tmp = *p;
468
469found_first:
470 /* tmp is little endian, so we would have to swab the shift,
471 * see above. But then we have to swab tmp below for ffz, so
472 * we might as well do this here.
473 */
474 return result + ffz(__swab32(tmp) | (~0UL << size));
475found_middle:
476 return result + ffz(__swab32(tmp));
477}
478#endif
479
480#define ext2_set_bit_atomic(lock, nr, addr) \
481 ({ \
482 int ret; \
483 spin_lock(lock); \
484 ret = ext2_set_bit((nr), (addr)); \
485 spin_unlock(lock); \
486 ret; \
487 })
488
489#define ext2_clear_bit_atomic(lock, nr, addr) \
490 ({ \
491 int ret; \
492 spin_lock(lock); \
493 ret = ext2_clear_bit((nr), (addr)); \
494 spin_unlock(lock); \
495 ret; \
496 })
497
498/* Bitmap functions for the minix filesystem. */
499#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
500#define minix_set_bit(nr,addr) __set_bit(nr,addr)
501#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
502#define minix_test_bit(nr,addr) test_bit(nr,addr)
503#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
504
505#define ffs(x) generic_ffs(x)
506#define fls(x) generic_fls(x)
507#define fls64(x) generic_fls64(x)
508 146
509#endif /* __KERNEL__ */ 147#endif /* __KERNEL__ */
510 148