2 * Copyright 1995, Russell King.
3 * Various bits and pieces copyrights include:
4 * Linus Torvalds (test_bit).
6 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
8 * Please note that the code in this file should never be included
9 * from user space. Many of these are not implemented in assembler
10 * since they would be too costly. Also, they require priviledged
11 * instructions (which are not available from user mode) to ensure
12 * that they are atomic.
15 #ifndef __ASM_ARM_BITOPS_H
16 #define __ASM_ARM_BITOPS_H
18 #include <asm-generic/bitops/__ffs.h>
22 #include <asm/proc-armv/system.h>
24 #define smp_mb__before_clear_bit() do { } while (0)
25 #define smp_mb__after_clear_bit() do { } while (0)
28 * Function prototypes to keep gcc -Wall happy.
30 extern void set_bit(int nr, volatile void * addr);
32 extern void clear_bit(int nr, volatile void * addr);
34 extern void change_bit(int nr, volatile void * addr);
36 static inline void __change_bit(int nr, volatile void *addr)
38 unsigned long mask = BIT_MASK(nr);
39 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
44 static inline int __test_and_set_bit(int nr, volatile void *addr)
46 unsigned long mask = BIT_MASK(nr);
47 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
48 unsigned long old = *p;
51 return (old & mask) != 0;
54 static inline int test_and_set_bit(int nr, volatile void * addr)
56 unsigned long flags = 0;
59 local_irq_save(flags);
60 out = __test_and_set_bit(nr, addr);
61 local_irq_restore(flags);
66 static inline int __test_and_clear_bit(int nr, volatile void *addr)
68 unsigned long mask = BIT_MASK(nr);
69 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
70 unsigned long old = *p;
73 return (old & mask) != 0;
76 static inline int test_and_clear_bit(int nr, volatile void * addr)
78 unsigned long flags = 0;
81 local_irq_save(flags);
82 out = __test_and_clear_bit(nr, addr);
83 local_irq_restore(flags);
88 extern int test_and_change_bit(int nr, volatile void * addr);
90 static inline int __test_and_change_bit(int nr, volatile void *addr)
92 unsigned long mask = BIT_MASK(nr);
93 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
94 unsigned long old = *p;
97 return (old & mask) != 0;
101 * This routine doesn't need to be atomic.
103 static inline int test_bit(int nr, const void * addr)
105 return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7));
108 static inline int __ilog2(unsigned int x)
110 return generic_fls(x) - 1;
113 #define ffz(x) __ffs(~(x))
115 static inline int find_next_zero_bit(void *addr, int size, int offset)
117 unsigned long *p = ((unsigned long *)addr) + (offset / BITS_PER_LONG);
118 unsigned long result = offset & ~(BITS_PER_LONG - 1);
124 offset &= (BITS_PER_LONG - 1);
127 tmp |= ~0UL >> (BITS_PER_LONG - offset);
128 if (size < BITS_PER_LONG)
132 size -= BITS_PER_LONG;
133 result += BITS_PER_LONG;
135 while (size & ~(BITS_PER_LONG - 1)) {
139 result += BITS_PER_LONG;
140 size -= BITS_PER_LONG;
149 return result + ffz(tmp);
153 * hweightN: returns the hamming weight (i.e. the number
154 * of bits set) of a N-bit word
157 #define hweight32(x) generic_hweight32(x)
158 #define hweight16(x) generic_hweight16(x)
159 #define hweight8(x) generic_hweight8(x)
161 #define find_first_zero_bit(addr, size) \
162 find_next_zero_bit((addr), (size), 0)
164 #define ext2_set_bit test_and_set_bit
165 #define ext2_clear_bit test_and_clear_bit
166 #define ext2_test_bit test_bit
167 #define ext2_find_first_zero_bit find_first_zero_bit
168 #define ext2_find_next_zero_bit find_next_zero_bit
170 /* Bitmap functions for the minix filesystem. */
171 #define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
172 #define minix_set_bit(nr,addr) set_bit(nr,addr)
173 #define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
174 #define minix_test_bit(nr,addr) test_bit(nr,addr)
175 #define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
177 #endif /* __KERNEL__ */
179 #include <asm-generic/bitops/__fls.h>
180 #include <asm-generic/bitops/fls.h>
181 #include <asm-generic/bitops/fls64.h>
183 #endif /* _ARM_BITOPS_H */