1 /* asm/bitops.h for Linux/CRIS
3 * TODO: asm versions if speed is needed
5 * All bit operations return 0 if the bit was cleared before the
6 * operation and != 0 if it was not.
8 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
11 #ifndef _CRIS_BITOPS_H
12 #define _CRIS_BITOPS_H
14 /* Currently this is unsuitable for consumption outside the kernel. */
17 #ifndef _LINUX_BITOPS_H
18 #error only <linux/bitops.h> can be included directly
21 #include <arch/bitops.h>
22 #include <linux/atomic.h>
23 #include <linux/compiler.h>
24 #include <asm/barrier.h>
27 * set_bit - Atomically set a bit in memory
29 * @addr: the address to start counting from
31 * This function is atomic and may not be reordered. See __set_bit()
32 * if you do not require the atomic guarantees.
33 * Note that @nr may be almost arbitrarily large; this function is not
34 * restricted to acting on a single-word quantity.
37 #define set_bit(nr, addr) (void)test_and_set_bit(nr, addr)
40 * clear_bit - Clears a bit in memory
42 * @addr: Address to start counting from
44 * clear_bit() is atomic and may not be reordered. However, it does
45 * not contain a memory barrier, so if it is used for locking purposes,
46 * you should call smp_mb__before_atomic() and/or smp_mb__after_atomic()
47 * in order to ensure changes are visible on other processors.
50 #define clear_bit(nr, addr) (void)test_and_clear_bit(nr, addr)
53 * change_bit - Toggle a bit in memory
55 * @addr: Address to start counting from
57 * change_bit() is atomic and may not be reordered.
58 * Note that @nr may be almost arbitrarily large; this function is not
59 * restricted to acting on a single-word quantity.
62 #define change_bit(nr, addr) (void)test_and_change_bit(nr, addr)
65 * test_and_set_bit - Set a bit and return its old value
67 * @addr: Address to count from
69 * This operation is atomic and cannot be reordered.
70 * It also implies a memory barrier.
73 static inline int test_and_set_bit(int nr
, volatile unsigned long *addr
)
75 unsigned int mask
, retval
;
77 unsigned int *adr
= (unsigned int *)addr
;
80 mask
= 1 << (nr
& 0x1f);
81 cris_atomic_save(addr
, flags
);
82 retval
= (mask
& *adr
) != 0;
84 cris_atomic_restore(addr
, flags
);
89 * test_and_clear_bit - Clear a bit and return its old value
91 * @addr: Address to count from
93 * This operation is atomic and cannot be reordered.
94 * It also implies a memory barrier.
97 static inline int test_and_clear_bit(int nr
, volatile unsigned long *addr
)
99 unsigned int mask
, retval
;
101 unsigned int *adr
= (unsigned int *)addr
;
104 mask
= 1 << (nr
& 0x1f);
105 cris_atomic_save(addr
, flags
);
106 retval
= (mask
& *adr
) != 0;
108 cris_atomic_restore(addr
, flags
);
113 * test_and_change_bit - Change a bit and return its old value
115 * @addr: Address to count from
117 * This operation is atomic and cannot be reordered.
118 * It also implies a memory barrier.
121 static inline int test_and_change_bit(int nr
, volatile unsigned long *addr
)
123 unsigned int mask
, retval
;
125 unsigned int *adr
= (unsigned int *)addr
;
127 mask
= 1 << (nr
& 0x1f);
128 cris_atomic_save(addr
, flags
);
129 retval
= (mask
& *adr
) != 0;
131 cris_atomic_restore(addr
, flags
);
135 #include <asm-generic/bitops/non-atomic.h>
138 * Since we define it "external", it collides with the built-in
139 * definition, which doesn't have the same semantics. We don't want to
140 * use -fno-builtin, so just hide the name ffs.
142 #define ffs(x) kernel_ffs(x)
144 #include <asm-generic/bitops/fls.h>
145 #include <asm-generic/bitops/__fls.h>
146 #include <asm-generic/bitops/fls64.h>
147 #include <asm-generic/bitops/hweight.h>
148 #include <asm-generic/bitops/find.h>
149 #include <asm-generic/bitops/lock.h>
151 #include <asm-generic/bitops/le.h>
153 #include <asm-generic/bitops/ext2-atomic-setbit.h>
155 #include <asm-generic/bitops/sched.h>
157 #endif /* __KERNEL__ */
159 #endif /* _CRIS_BITOPS_H */