fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / include / asm-sh / bitops.h
blob1c16792cee1dbaf239948ac8971dd2ad7290865e
1 #ifndef __ASM_SH_BITOPS_H
2 #define __ASM_SH_BITOPS_H
4 #ifdef __KERNEL__
5 #include <asm/system.h>
6 /* For __swab32 */
7 #include <asm/byteorder.h>
9 static inline void set_bit(int nr, volatile void * addr)
11 int mask;
12 volatile unsigned int *a = addr;
13 unsigned long flags;
15 a += nr >> 5;
16 mask = 1 << (nr & 0x1f);
17 local_irq_save(flags);
18 *a |= mask;
19 local_irq_restore(flags);
23 * clear_bit() doesn't provide any barrier for the compiler.
25 #define smp_mb__before_clear_bit() barrier()
26 #define smp_mb__after_clear_bit() barrier()
27 static inline void clear_bit(int nr, volatile void * addr)
29 int mask;
30 volatile unsigned int *a = addr;
31 unsigned long flags;
33 a += nr >> 5;
34 mask = 1 << (nr & 0x1f);
35 local_irq_save(flags);
36 *a &= ~mask;
37 local_irq_restore(flags);
40 static inline void change_bit(int nr, volatile void * addr)
42 int mask;
43 volatile unsigned int *a = addr;
44 unsigned long flags;
46 a += nr >> 5;
47 mask = 1 << (nr & 0x1f);
48 local_irq_save(flags);
49 *a ^= mask;
50 local_irq_restore(flags);
53 static inline int test_and_set_bit(int nr, volatile void * addr)
55 int mask, retval;
56 volatile unsigned int *a = addr;
57 unsigned long flags;
59 a += nr >> 5;
60 mask = 1 << (nr & 0x1f);
61 local_irq_save(flags);
62 retval = (mask & *a) != 0;
63 *a |= mask;
64 local_irq_restore(flags);
66 return retval;
69 static inline int test_and_clear_bit(int nr, volatile void * addr)
71 int mask, retval;
72 volatile unsigned int *a = addr;
73 unsigned long flags;
75 a += nr >> 5;
76 mask = 1 << (nr & 0x1f);
77 local_irq_save(flags);
78 retval = (mask & *a) != 0;
79 *a &= ~mask;
80 local_irq_restore(flags);
82 return retval;
85 static inline int test_and_change_bit(int nr, volatile void * addr)
87 int mask, retval;
88 volatile unsigned int *a = addr;
89 unsigned long flags;
91 a += nr >> 5;
92 mask = 1 << (nr & 0x1f);
93 local_irq_save(flags);
94 retval = (mask & *a) != 0;
95 *a ^= mask;
96 local_irq_restore(flags);
98 return retval;
101 #include <asm-generic/bitops/non-atomic.h>
103 static inline unsigned long ffz(unsigned long word)
105 unsigned long result;
107 __asm__("1:\n\t"
108 "shlr %1\n\t"
109 "bt/s 1b\n\t"
110 " add #1, %0"
111 : "=r" (result), "=r" (word)
112 : "0" (~0L), "1" (word)
113 : "t");
114 return result;
118 * __ffs - find first bit in word.
119 * @word: The word to search
121 * Undefined if no bit exists, so code should check against 0 first.
123 static inline unsigned long __ffs(unsigned long word)
125 unsigned long result;
127 __asm__("1:\n\t"
128 "shlr %1\n\t"
129 "bf/s 1b\n\t"
130 " add #1, %0"
131 : "=r" (result), "=r" (word)
132 : "0" (~0L), "1" (word)
133 : "t");
134 return result;
137 #include <asm-generic/bitops/find.h>
138 #include <asm-generic/bitops/ffs.h>
139 #include <asm-generic/bitops/hweight.h>
140 #include <asm-generic/bitops/sched.h>
141 #include <asm-generic/bitops/ext2-non-atomic.h>
142 #include <asm-generic/bitops/ext2-atomic.h>
143 #include <asm-generic/bitops/minix.h>
144 #include <asm-generic/bitops/fls.h>
145 #include <asm-generic/bitops/fls64.h>
147 #endif /* __KERNEL__ */
149 #endif /* __ASM_SH_BITOPS_H */