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)); \
54 H8300_GEN_BITOP(set_bit
, "bset")
55 H8300_GEN_BITOP(clear_bit
, "bclr")
56 H8300_GEN_BITOP(change_bit
, "bnot")
57 #define __set_bit(nr, addr) set_bit((nr), (addr))
58 #define __clear_bit(nr, addr) clear_bit((nr), (addr))
59 #define __change_bit(nr, addr) change_bit((nr), (addr))
61 #undef H8300_GEN_BITOP
63 static inline int test_bit(int nr
, const volatile unsigned long *addr
)
66 unsigned char *b_addr
;
67 unsigned char bit
= nr
& 7;
69 b_addr
= (unsigned char *)addr
+ ((nr
>> 3) ^ 3);
70 if (__builtin_constant_p(nr
)) {
71 __asm__("bld %Z2,%1\n\t"
74 : "WU"(*b_addr
), "i"(nr
& 7), "0"(ret
) : "cc");
76 __asm__("btst %w2,%1\n\t"
81 : "WU"(*b_addr
), "r"(bit
), "0"(ret
) : "cc");
86 #define __test_bit(nr, addr) test_bit(nr, addr)
88 #define H8300_GEN_TEST_BITOP(FNNAME, OP) \
89 static inline int FNNAME(int nr, void *addr) \
93 unsigned char *b_addr; \
94 unsigned char bit = nr & 7; \
96 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
97 if (__builtin_constant_p(nr)) { \
98 __asm__("stc ccr,%s2\n\t" \
104 : "=r"(retval), "+WU" (*b_addr), "=&r"(ccrsave) \
105 : "0"(retval), "i"(nr & 7) : "cc"); \
107 __asm__("stc ccr,%t3\n\t" \
108 "orc #0x80,ccr\n\t" \
115 : "=r"(retval), "+WU" (*b_addr) \
116 : "0" (retval), "r"(bit) : "cc"); \
121 static inline int __ ## FNNAME(int nr, void *addr) \
124 unsigned char *b_addr; \
125 unsigned char bit = nr & 7; \
127 b_addr = (unsigned char *)addr + ((nr >> 3) ^ 3); \
128 if (__builtin_constant_p(nr)) { \
129 __asm__("bld %3,%1\n\t" \
132 : "=r"(retval), "+WU"(*b_addr) \
133 : "0" (retval), "i"(nr & 7)); \
135 __asm__("btst %s3,%1\n\t" \
140 : "=r"(retval), "+WU"(*b_addr) \
141 : "0" (retval), "r"(bit)); \
146 H8300_GEN_TEST_BITOP(test_and_set_bit
, "bset")
147 H8300_GEN_TEST_BITOP(test_and_clear_bit
, "bclr")
148 H8300_GEN_TEST_BITOP(test_and_change_bit
, "bnot")
149 #undef H8300_GEN_TEST_BITOP
151 #include <asm-generic/bitops/ffs.h>
153 static inline unsigned long __ffs(unsigned long word
)
155 unsigned long result
;
162 : "=r" (result
),"=r"(word
)
163 : "0"(result
), "1"(word
));
167 #include <asm-generic/bitops/find.h>
168 #include <asm-generic/bitops/sched.h>
169 #include <asm-generic/bitops/hweight.h>
170 #include <asm-generic/bitops/lock.h>
171 #include <asm-generic/bitops/le.h>
172 #include <asm-generic/bitops/ext2-atomic.h>
174 #endif /* __KERNEL__ */
176 #include <asm-generic/bitops/fls.h>
177 #include <asm-generic/bitops/__fls.h>
178 #include <asm-generic/bitops/fls64.h>
180 #endif /* _H8300_BITOPS_H */