1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _H8300_BITOPS_H
3 #define _H8300_BITOPS_H
6 * Copyright 1992, Linus Torvalds.
7 * Copyright 2002, Yoshinori Sato
10 #include <linux/compiler.h>
14 #ifndef _LINUX_BITOPS_H
15 #error only <linux/bitops.h> can be included directly
19 * Function prototypes to keep gcc -Wall happy
23 * ffz = Find First Zero in word. Undefined if no zero exists,
24 * so code should check against ~0UL first..
26 static inline unsigned long ffz(unsigned long word
)
35 : "=r"(result
),"=r"(word
)
36 : "0"(result
), "1"(word
));
40 #define H8300_GEN_BITOP(FNAME, OP) \
41 static inline void FNAME(int nr, volatile unsigned long *addr) \
43 unsigned char *b_addr; \
44 unsigned char bit = nr & 7; \
46 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
47 if (__builtin_constant_p(nr)) { \
48 __asm__(OP " %1,%0" : "+WU"(*b_addr) : "i"(nr & 7)); \
50 __asm__(OP " %s1,%0" : "+WU"(*b_addr) : "r"(bit)); \
55 * clear_bit() doesn't provide any barrier for the compiler.
57 #define smp_mb__before_clear_bit() barrier()
58 #define smp_mb__after_clear_bit() barrier()
60 H8300_GEN_BITOP(set_bit
, "bset")
61 H8300_GEN_BITOP(clear_bit
, "bclr")
62 H8300_GEN_BITOP(change_bit
, "bnot")
63 #define __set_bit(nr, addr) set_bit((nr), (addr))
64 #define __clear_bit(nr, addr) clear_bit((nr), (addr))
65 #define __change_bit(nr, addr) change_bit((nr), (addr))
67 #undef H8300_GEN_BITOP
69 static inline int test_bit(int nr
, const volatile unsigned long *addr
)
72 unsigned char *b_addr
;
73 unsigned char bit
= nr
& 7;
75 b_addr
= (unsigned char *)addr
+ ((nr
>> 3) ^ 3);
76 if (__builtin_constant_p(nr
)) {
77 __asm__("bld %Z2,%1\n\t"
80 : "WU"(*b_addr
), "i"(nr
& 7), "0"(ret
) : "cc");
82 __asm__("btst %w2,%1\n\t"
87 : "WU"(*b_addr
), "r"(bit
), "0"(ret
) : "cc");
92 #define __test_bit(nr, addr) test_bit(nr, addr)
94 #define H8300_GEN_TEST_BITOP(FNNAME, OP) \
95 static inline int FNNAME(int nr, void *addr) \
99 unsigned char *b_addr; \
100 unsigned char bit = nr & 7; \
102 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
103 if (__builtin_constant_p(nr)) { \
104 __asm__("stc ccr,%s2\n\t" \
105 "orc #0x80,ccr\n\t" \
110 : "=r"(retval), "+WU" (*b_addr), "=&r"(ccrsave) \
111 : "0"(retval), "i"(nr & 7) : "cc"); \
113 __asm__("stc ccr,%t3\n\t" \
114 "orc #0x80,ccr\n\t" \
121 : "=r"(retval), "+WU" (*b_addr) \
122 : "0" (retval), "r"(bit) : "cc"); \
127 static inline int __ ## FNNAME(int nr, void *addr) \
130 unsigned char *b_addr; \
131 unsigned char bit = nr & 7; \
133 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
134 if (__builtin_constant_p(nr)) { \
135 __asm__("bld %3,%1\n\t" \
138 : "=r"(retval), "+WU"(*b_addr) \
139 : "0" (retval), "i"(nr & 7)); \
141 __asm__("btst %s3,%1\n\t" \
146 : "=r"(retval), "+WU"(*b_addr) \
147 : "0" (retval), "r"(bit)); \
152 H8300_GEN_TEST_BITOP(test_and_set_bit
, "bset")
153 H8300_GEN_TEST_BITOP(test_and_clear_bit
, "bclr")
154 H8300_GEN_TEST_BITOP(test_and_change_bit
, "bnot")
155 #undef H8300_GEN_TEST_BITOP
157 #include <asm-generic/bitops/ffs.h>
159 static inline unsigned long __ffs(unsigned long word
)
161 unsigned long result
;
168 : "=r" (result
),"=r"(word
)
169 : "0"(result
), "1"(word
));
173 #include <asm-generic/bitops/find.h>
174 #include <asm-generic/bitops/sched.h>
175 #include <asm-generic/bitops/hweight.h>
176 #include <asm-generic/bitops/lock.h>
177 #include <asm-generic/bitops/le.h>
178 #include <asm-generic/bitops/ext2-atomic.h>
180 #endif /* __KERNEL__ */
182 #include <asm-generic/bitops/fls.h>
183 #include <asm-generic/bitops/__fls.h>
184 #include <asm-generic/bitops/fls64.h>
186 #endif /* _H8300_BITOPS_H */