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>
10 #include <asm/system.h>
14 * Function prototypes to keep gcc -Wall happy
18 * ffz = Find First Zero in word. Undefined if no zero exists,
19 * so code should check against ~0UL first..
21 static __inline__
unsigned long ffz(unsigned long word
)
31 : "0" (result
),"r" (word
));
35 #define H8300_GEN_BITOP_CONST(OP,BIT) \
37 __asm__(OP " #" #BIT ",@%0"::"r"(b_addr):"memory"); \
40 #define H8300_GEN_BITOP(FNAME,OP) \
41 static __inline__ void FNAME(int nr, volatile unsigned long* addr) \
43 volatile unsigned char *b_addr; \
44 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
45 if (__builtin_constant_p(nr)) { \
47 H8300_GEN_BITOP_CONST(OP,0) \
48 H8300_GEN_BITOP_CONST(OP,1) \
49 H8300_GEN_BITOP_CONST(OP,2) \
50 H8300_GEN_BITOP_CONST(OP,3) \
51 H8300_GEN_BITOP_CONST(OP,4) \
52 H8300_GEN_BITOP_CONST(OP,5) \
53 H8300_GEN_BITOP_CONST(OP,6) \
54 H8300_GEN_BITOP_CONST(OP,7) \
57 __asm__(OP " %w0,@%1"::"r"(nr),"r"(b_addr):"memory"); \
62 * clear_bit() doesn't provide any barrier for the compiler.
64 #define smp_mb__before_clear_bit() barrier()
65 #define smp_mb__after_clear_bit() barrier()
67 H8300_GEN_BITOP(set_bit
,"bset")
68 H8300_GEN_BITOP(clear_bit
,"bclr")
69 H8300_GEN_BITOP(change_bit
,"bnot")
70 #define __set_bit(nr,addr) set_bit((nr),(addr))
71 #define __clear_bit(nr,addr) clear_bit((nr),(addr))
72 #define __change_bit(nr,addr) change_bit((nr),(addr))
74 #undef H8300_GEN_BITOP
75 #undef H8300_GEN_BITOP_CONST
77 static __inline__
int test_bit(int nr
, const unsigned long* addr
)
79 return (*((volatile unsigned char *)addr
+
80 ((nr
>> 3) ^ 3)) & (1UL << (nr
& 7))) != 0;
83 #define __test_bit(nr, addr) test_bit(nr, addr)
85 #define H8300_GEN_TEST_BITOP_CONST_INT(OP,BIT) \
87 __asm__("stc ccr,%w1\n\t" \
89 "bld #" #BIT ",@%4\n\t" \
90 OP " #" #BIT ",@%4\n\t" \
93 : "=r"(retval),"=&r"(ccrsave),"=m"(*b_addr) \
94 : "0" (retval),"r" (b_addr) \
98 #define H8300_GEN_TEST_BITOP_CONST(OP,BIT) \
100 __asm__("bld #" #BIT ",@%3\n\t" \
101 OP " #" #BIT ",@%3\n\t" \
103 : "=r"(retval),"=m"(*b_addr) \
104 : "0" (retval),"r" (b_addr) \
108 #define H8300_GEN_TEST_BITOP(FNNAME,OP) \
109 static __inline__ int FNNAME(int nr, volatile void * addr) \
113 volatile unsigned char *b_addr; \
114 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
115 if (__builtin_constant_p(nr)) { \
117 H8300_GEN_TEST_BITOP_CONST_INT(OP,0) \
118 H8300_GEN_TEST_BITOP_CONST_INT(OP,1) \
119 H8300_GEN_TEST_BITOP_CONST_INT(OP,2) \
120 H8300_GEN_TEST_BITOP_CONST_INT(OP,3) \
121 H8300_GEN_TEST_BITOP_CONST_INT(OP,4) \
122 H8300_GEN_TEST_BITOP_CONST_INT(OP,5) \
123 H8300_GEN_TEST_BITOP_CONST_INT(OP,6) \
124 H8300_GEN_TEST_BITOP_CONST_INT(OP,7) \
127 __asm__("stc ccr,%w1\n\t" \
128 "orc #0x80,ccr\n\t" \
135 : "=r"(retval),"=&r"(ccrsave),"=m"(*b_addr) \
136 : "0" (retval),"r" (b_addr),"r"(nr) \
142 static __inline__ int __ ## FNNAME(int nr, volatile void * addr) \
145 volatile unsigned char *b_addr; \
146 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
147 if (__builtin_constant_p(nr)) { \
149 H8300_GEN_TEST_BITOP_CONST(OP,0) \
150 H8300_GEN_TEST_BITOP_CONST(OP,1) \
151 H8300_GEN_TEST_BITOP_CONST(OP,2) \
152 H8300_GEN_TEST_BITOP_CONST(OP,3) \
153 H8300_GEN_TEST_BITOP_CONST(OP,4) \
154 H8300_GEN_TEST_BITOP_CONST(OP,5) \
155 H8300_GEN_TEST_BITOP_CONST(OP,6) \
156 H8300_GEN_TEST_BITOP_CONST(OP,7) \
159 __asm__("btst %w4,@%3\n\t" \
164 : "=r"(retval),"=m"(*b_addr) \
165 : "0" (retval),"r" (b_addr),"r"(nr) \
171 H8300_GEN_TEST_BITOP(test_and_set_bit
, "bset")
172 H8300_GEN_TEST_BITOP(test_and_clear_bit
, "bclr")
173 H8300_GEN_TEST_BITOP(test_and_change_bit
,"bnot")
174 #undef H8300_GEN_TEST_BITOP_CONST
175 #undef H8300_GEN_TEST_BITOP_CONST_INT
176 #undef H8300_GEN_TEST_BITOP
178 #include <asm-generic/bitops/ffs.h>
180 static __inline__
unsigned long __ffs(unsigned long word
)
182 unsigned long result
;
190 : "0"(result
),"r"(word
));
194 #include <asm-generic/bitops/find.h>
195 #include <asm-generic/bitops/sched.h>
196 #include <asm-generic/bitops/hweight.h>
197 #include <asm-generic/bitops/ext2-non-atomic.h>
198 #include <asm-generic/bitops/ext2-atomic.h>
199 #include <asm-generic/bitops/minix.h>
201 #endif /* __KERNEL__ */
203 #include <asm-generic/bitops/fls.h>
204 #include <asm-generic/bitops/fls64.h>
206 #endif /* _H8300_BITOPS_H */