1 #ifndef _H8300_BITOPS_H
2 #define _H8300_BITOPS_H
5 * Copyright 1992, Linus Torvalds.
6 * Copyright 2002, Yoshinori Sato
9 #include <linux/compiler.h>
13 #ifndef _LINUX_BITOPS_H
14 #error only <linux/bitops.h> can be included directly
18 * Function prototypes to keep gcc -Wall happy
22 * ffz = Find First Zero in word. Undefined if no zero exists,
23 * so code should check against ~0UL first..
25 static inline unsigned long ffz(unsigned long word
)
35 : "0"(result
), "r"(word
));
39 #define H8300_GEN_BITOP(FNAME, OP) \
40 static inline void FNAME(int nr, volatile unsigned long *addr) \
42 unsigned char *b_addr; \
43 unsigned char bit = nr & 7; \
45 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
46 if (__builtin_constant_p(nr)) { \
47 __asm__(OP " %1,%0" : "+WU"(*b_addr) : "i"(nr & 7)); \
49 __asm__(OP " %s1,%0" : "+WU"(*b_addr) : "r"(bit)); \
54 * clear_bit() doesn't provide any barrier for the compiler.
56 #define smp_mb__before_clear_bit() barrier()
57 #define smp_mb__after_clear_bit() barrier()
59 H8300_GEN_BITOP(set_bit
, "bset")
60 H8300_GEN_BITOP(clear_bit
, "bclr")
61 H8300_GEN_BITOP(change_bit
, "bnot")
62 #define __set_bit(nr, addr) set_bit((nr), (addr))
63 #define __clear_bit(nr, addr) clear_bit((nr), (addr))
64 #define __change_bit(nr, addr) change_bit((nr), (addr))
66 #undef H8300_GEN_BITOP
68 static inline int test_bit(int nr
, const unsigned long *addr
)
71 unsigned char *b_addr
;
72 unsigned char bit
= nr
& 7;
74 b_addr
= (unsigned char *)addr
+ ((nr
>> 3) ^ 3);
75 if (__builtin_constant_p(nr
)) {
76 __asm__("bld %Z2,%1\n\t"
79 : "WU"(*b_addr
), "i"(nr
& 7), "0"(ret
) : "cc");
81 __asm__("btst %w2,%1\n\t"
86 : "WU"(*b_addr
), "r"(bit
), "0"(ret
) : "cc");
91 #define __test_bit(nr, addr) test_bit(nr, addr)
93 #define H8300_GEN_TEST_BITOP(FNNAME, OP) \
94 static inline int FNNAME(int nr, void *addr) \
98 unsigned char *b_addr; \
99 unsigned char bit = nr & 7; \
101 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
102 if (__builtin_constant_p(nr)) { \
103 __asm__("stc ccr,%s2\n\t" \
104 "orc #0x80,ccr\n\t" \
109 : "=r"(retval), "+WU" (*b_addr), "=&r"(ccrsave) \
110 : "0"(retval), "i"(nr & 7) : "cc"); \
112 __asm__("stc ccr,%t3\n\t" \
113 "orc #0x80,ccr\n\t" \
120 : "=r"(retval), "+WU" (*b_addr) \
121 : "0" (retval), "r"(bit) : "cc"); \
126 static inline int __ ## FNNAME(int nr, void *addr) \
129 unsigned char *b_addr; \
130 unsigned char bit = nr & 7; \
132 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
133 if (__builtin_constant_p(nr)) { \
134 __asm__("bld %3,%1\n\t" \
137 : "=r"(retval), "+WU"(*b_addr) \
138 : "0" (retval), "i"(nr & 7)); \
140 __asm__("btst %s3,%1\n\t" \
145 : "=r"(retval), "+WU"(*b_addr) \
146 : "0" (retval), "r"(bit)); \
151 H8300_GEN_TEST_BITOP(test_and_set_bit
, "bset")
152 H8300_GEN_TEST_BITOP(test_and_clear_bit
, "bclr")
153 H8300_GEN_TEST_BITOP(test_and_change_bit
, "bnot")
154 #undef H8300_GEN_TEST_BITOP
156 #include <asm-generic/bitops/ffs.h>
158 static inline unsigned long __ffs(unsigned long word
)
160 unsigned long result
;
168 : "0"(result
), "r"(word
));
172 #include <asm-generic/bitops/find.h>
173 #include <asm-generic/bitops/sched.h>
174 #include <asm-generic/bitops/hweight.h>
175 #include <asm-generic/bitops/lock.h>
176 #include <asm-generic/bitops/le.h>
177 #include <asm-generic/bitops/ext2-atomic.h>
179 #endif /* __KERNEL__ */
181 #include <asm-generic/bitops/fls.h>
182 #include <asm-generic/bitops/__fls.h>
183 #include <asm-generic/bitops/fls64.h>
185 #endif /* _H8300_BITOPS_H */