1 #ifndef _H8300_BITOPS_H
2 #define _H8300_BITOPS_H
5 * Copyright 1992, Linus Torvalds.
6 * Copyright 2002, Yoshinori Sato
9 #include <linux/config.h>
10 #include <linux/compiler.h>
11 #include <asm/system.h>
15 * Function prototypes to keep gcc -Wall happy
19 * ffz = Find First Zero in word. Undefined if no zero exists,
20 * so code should check against ~0UL first..
22 static __inline__
unsigned long ffz(unsigned long word
)
32 : "0" (result
),"r" (word
));
36 #define H8300_GEN_BITOP_CONST(OP,BIT) \
38 __asm__(OP " #" #BIT ",@%0"::"r"(b_addr):"memory"); \
41 #define H8300_GEN_BITOP(FNAME,OP) \
42 static __inline__ void FNAME(int nr, volatile unsigned long* addr) \
44 volatile unsigned char *b_addr; \
45 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
46 if (__builtin_constant_p(nr)) { \
48 H8300_GEN_BITOP_CONST(OP,0) \
49 H8300_GEN_BITOP_CONST(OP,1) \
50 H8300_GEN_BITOP_CONST(OP,2) \
51 H8300_GEN_BITOP_CONST(OP,3) \
52 H8300_GEN_BITOP_CONST(OP,4) \
53 H8300_GEN_BITOP_CONST(OP,5) \
54 H8300_GEN_BITOP_CONST(OP,6) \
55 H8300_GEN_BITOP_CONST(OP,7) \
58 __asm__(OP " %w0,@%1"::"r"(nr),"r"(b_addr):"memory"); \
63 * clear_bit() doesn't provide any barrier for the compiler.
65 #define smp_mb__before_clear_bit() barrier()
66 #define smp_mb__after_clear_bit() barrier()
68 H8300_GEN_BITOP(set_bit
,"bset")
69 H8300_GEN_BITOP(clear_bit
,"bclr")
70 H8300_GEN_BITOP(change_bit
,"bnot")
71 #define __set_bit(nr,addr) set_bit((nr),(addr))
72 #define __clear_bit(nr,addr) clear_bit((nr),(addr))
73 #define __change_bit(nr,addr) change_bit((nr),(addr))
75 #undef H8300_GEN_BITOP
76 #undef H8300_GEN_BITOP_CONST
78 static __inline__
int test_bit(int nr
, const unsigned long* addr
)
80 return (*((volatile unsigned char *)addr
+
81 ((nr
>> 3) ^ 3)) & (1UL << (nr
& 7))) != 0;
84 #define __test_bit(nr, addr) test_bit(nr, addr)
86 #define H8300_GEN_TEST_BITOP_CONST_INT(OP,BIT) \
88 __asm__("stc ccr,%w1\n\t" \
90 "bld #" #BIT ",@%4\n\t" \
91 OP " #" #BIT ",@%4\n\t" \
94 : "=r"(retval),"=&r"(ccrsave),"=m"(*b_addr) \
95 : "0" (retval),"r" (b_addr) \
99 #define H8300_GEN_TEST_BITOP_CONST(OP,BIT) \
101 __asm__("bld #" #BIT ",@%3\n\t" \
102 OP " #" #BIT ",@%3\n\t" \
104 : "=r"(retval),"=m"(*b_addr) \
105 : "0" (retval),"r" (b_addr) \
109 #define H8300_GEN_TEST_BITOP(FNNAME,OP) \
110 static __inline__ int FNNAME(int nr, volatile void * addr) \
114 volatile unsigned char *b_addr; \
115 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
116 if (__builtin_constant_p(nr)) { \
118 H8300_GEN_TEST_BITOP_CONST_INT(OP,0) \
119 H8300_GEN_TEST_BITOP_CONST_INT(OP,1) \
120 H8300_GEN_TEST_BITOP_CONST_INT(OP,2) \
121 H8300_GEN_TEST_BITOP_CONST_INT(OP,3) \
122 H8300_GEN_TEST_BITOP_CONST_INT(OP,4) \
123 H8300_GEN_TEST_BITOP_CONST_INT(OP,5) \
124 H8300_GEN_TEST_BITOP_CONST_INT(OP,6) \
125 H8300_GEN_TEST_BITOP_CONST_INT(OP,7) \
128 __asm__("stc ccr,%w1\n\t" \
129 "orc #0x80,ccr\n\t" \
136 : "=r"(retval),"=&r"(ccrsave),"=m"(*b_addr) \
137 : "0" (retval),"r" (b_addr),"r"(nr) \
143 static __inline__ int __ ## FNNAME(int nr, volatile void * addr) \
146 volatile unsigned char *b_addr; \
147 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
148 if (__builtin_constant_p(nr)) { \
150 H8300_GEN_TEST_BITOP_CONST(OP,0) \
151 H8300_GEN_TEST_BITOP_CONST(OP,1) \
152 H8300_GEN_TEST_BITOP_CONST(OP,2) \
153 H8300_GEN_TEST_BITOP_CONST(OP,3) \
154 H8300_GEN_TEST_BITOP_CONST(OP,4) \
155 H8300_GEN_TEST_BITOP_CONST(OP,5) \
156 H8300_GEN_TEST_BITOP_CONST(OP,6) \
157 H8300_GEN_TEST_BITOP_CONST(OP,7) \
160 __asm__("btst %w4,@%3\n\t" \
165 : "=r"(retval),"=m"(*b_addr) \
166 : "0" (retval),"r" (b_addr),"r"(nr) \
172 H8300_GEN_TEST_BITOP(test_and_set_bit
, "bset")
173 H8300_GEN_TEST_BITOP(test_and_clear_bit
, "bclr")
174 H8300_GEN_TEST_BITOP(test_and_change_bit
,"bnot")
175 #undef H8300_GEN_TEST_BITOP_CONST
176 #undef H8300_GEN_TEST_BITOP_CONST_INT
177 #undef H8300_GEN_TEST_BITOP
179 #include <asm-generic/bitops/ffs.h>
181 static __inline__
unsigned long __ffs(unsigned long word
)
183 unsigned long result
;
191 : "0"(result
),"r"(word
));
195 #include <asm-generic/bitops/find.h>
196 #include <asm-generic/bitops/sched.h>
197 #include <asm-generic/bitops/hweight.h>
198 #include <asm-generic/bitops/ext2-non-atomic.h>
199 #include <asm-generic/bitops/ext2-atomic.h>
200 #include <asm-generic/bitops/minix.h>
202 #endif /* __KERNEL__ */
204 #include <asm-generic/bitops/fls.h>
205 #include <asm-generic/bitops/fls64.h>
207 #endif /* _H8300_BITOPS_H */