17 #ifndef __ASM_ARM_BITOPS_H
18 #define __ASM_ARM_BITOPS_H
22 #ifndef _LINUX_BITOPS_H
23 #error only <linux/bitops.h> can be included directly
26 #include <linux/compiler.h>
29 #define smp_mb__before_clear_bit() smp_mb()
30 #define smp_mb__after_clear_bit() smp_mb()
37 static inline void ____atomic_set_bit(
unsigned int bit,
volatile unsigned long *
p)
40 unsigned long mask = 1
UL << (bit & 31);
49 static inline void ____atomic_clear_bit(
unsigned int bit,
volatile unsigned long *
p)
52 unsigned long mask = 1
UL << (bit & 31);
61 static inline void ____atomic_change_bit(
unsigned int bit,
volatile unsigned long *
p)
64 unsigned long mask = 1
UL << (bit & 31);
74 ____atomic_test_and_set_bit(
unsigned int bit,
volatile unsigned long *
p)
78 unsigned long mask = 1
UL << (bit & 31);
87 return (res & mask) != 0;
91 ____atomic_test_and_clear_bit(
unsigned int bit,
volatile unsigned long *p)
95 unsigned long mask = 1
UL << (bit & 31);
104 return (res & mask) != 0;
108 ____atomic_test_and_change_bit(
unsigned int bit,
volatile unsigned long *p)
112 unsigned long mask = 1
UL << (bit & 31);
121 return (res & mask) != 0;
154 extern void _set_bit(
int nr,
volatile unsigned long * p);
155 extern void _clear_bit(
int nr,
volatile unsigned long * p);
156 extern void _change_bit(
int nr,
volatile unsigned long * p);
157 extern int _test_and_set_bit(
int nr,
volatile unsigned long * p);
158 extern int _test_and_clear_bit(
int nr,
volatile unsigned long * p);
159 extern int _test_and_change_bit(
int nr,
volatile unsigned long * p);
164 extern int _find_first_zero_bit_le(
const void * p,
unsigned size);
165 extern int _find_next_zero_bit_le(
const void * p,
int size,
int offset);
166 extern int _find_first_bit_le(
const unsigned long *p,
unsigned size);
167 extern int _find_next_bit_le(
const unsigned long *p,
int size,
int offset);
172 extern int _find_first_zero_bit_be(
const void * p,
unsigned size);
173 extern int _find_next_zero_bit_be(
const void * p,
int size,
int offset);
174 extern int _find_first_bit_be(
const unsigned long *p,
unsigned size);
175 extern int _find_next_bit_be(
const unsigned long *p,
int size,
int offset);
181 #define ATOMIC_BITOP(name,nr,p) \
182 (__builtin_constant_p(nr) ? ____atomic_##name(nr, p) : _##name(nr,p))
184 #define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
190 #define set_bit(nr,p) ATOMIC_BITOP(set_bit,nr,p)
191 #define clear_bit(nr,p) ATOMIC_BITOP(clear_bit,nr,p)
192 #define change_bit(nr,p) ATOMIC_BITOP(change_bit,nr,p)
193 #define test_and_set_bit(nr,p) ATOMIC_BITOP(test_and_set_bit,nr,p)
194 #define test_and_clear_bit(nr,p) ATOMIC_BITOP(test_and_clear_bit,nr,p)
195 #define test_and_change_bit(nr,p) ATOMIC_BITOP(test_and_change_bit,nr,p)
201 #define find_first_zero_bit(p,sz) _find_first_zero_bit_le(p,sz)
202 #define find_next_zero_bit(p,sz,off) _find_next_zero_bit_le(p,sz,off)
203 #define find_first_bit(p,sz) _find_first_bit_le(p,sz)
204 #define find_next_bit(p,sz,off) _find_next_bit_le(p,sz,off)
210 #define find_first_zero_bit(p,sz) _find_first_zero_bit_be(p,sz)
211 #define find_next_zero_bit(p,sz,off) _find_next_zero_bit_be(p,sz,off)
212 #define find_first_bit(p,sz) _find_first_bit_be(p,sz)
213 #define find_next_bit(p,sz,off) _find_next_bit_be(p,sz,off)
217 #if __LINUX_ARM_ARCH__ < 5
227 static inline int constant_fls(
int x)
233 if (!(x & 0xffff0000u)) {
237 if (!(x & 0xff000000u)) {
241 if (!(x & 0xf0000000u)) {
245 if (!(x & 0xc0000000u)) {
249 if (!(x & 0x80000000u)) {
261 static inline int fls(
int x)
265 if (__builtin_constant_p(x))
266 return constant_fls(x);
268 asm(
"clz\t%0, %1" :
"=r" (
ret) :
"r" (x));
273 #define __fls(x) (fls(x) - 1)
274 #define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
275 #define __ffs(x) (ffs(x) - 1)
276 #define ffz(x) __ffs( ~(x) )
290 return _find_first_zero_bit_le(p, size);
292 #define find_first_zero_bit_le find_first_zero_bit_le
296 return _find_next_zero_bit_le(p, size, offset);
298 #define find_next_zero_bit_le find_next_zero_bit_le
302 return _find_next_bit_le(p, size, offset);
304 #define find_next_bit_le find_next_bit_le