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_CONST(OP,BIT) \
41 __asm__(OP " #" #BIT ",@%0"::"r"(b_addr):"memory"); \
44 #define H8300_GEN_BITOP(FNAME,OP) \
45 static __inline__ void FNAME(int nr, volatile unsigned long* addr) \
47 volatile unsigned char *b_addr; \
48 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
49 if (__builtin_constant_p(nr)) { \
51 H8300_GEN_BITOP_CONST(OP,0) \
52 H8300_GEN_BITOP_CONST(OP,1) \
53 H8300_GEN_BITOP_CONST(OP,2) \
54 H8300_GEN_BITOP_CONST(OP,3) \
55 H8300_GEN_BITOP_CONST(OP,4) \
56 H8300_GEN_BITOP_CONST(OP,5) \
57 H8300_GEN_BITOP_CONST(OP,6) \
58 H8300_GEN_BITOP_CONST(OP,7) \
61 __asm__(OP " %w0,@%1"::"r"(nr),"r"(b_addr):"memory"); \
66 * clear_bit() doesn't provide any barrier for the compiler.
68 #define smp_mb__before_clear_bit() barrier()
69 #define smp_mb__after_clear_bit() barrier()
71 H8300_GEN_BITOP(set_bit
,"bset")
72 H8300_GEN_BITOP(clear_bit
,"bclr")
73 H8300_GEN_BITOP(change_bit
,"bnot")
74 #define __set_bit(nr,addr) set_bit((nr),(addr))
75 #define __clear_bit(nr,addr) clear_bit((nr),(addr))
76 #define __change_bit(nr,addr) change_bit((nr),(addr))
78 #undef H8300_GEN_BITOP
79 #undef H8300_GEN_BITOP_CONST
81 static __inline__
int test_bit(int nr
, const unsigned long* addr
)
83 return (*((volatile unsigned char *)addr
+
84 ((nr
>> 3) ^ 3)) & (1UL << (nr
& 7))) != 0;
87 #define __test_bit(nr, addr) test_bit(nr, addr)
89 #define H8300_GEN_TEST_BITOP_CONST_INT(OP,BIT) \
91 __asm__("stc ccr,%w1\n\t" \
93 "bld #" #BIT ",@%4\n\t" \
94 OP " #" #BIT ",@%4\n\t" \
97 : "=r"(retval),"=&r"(ccrsave),"=m"(*b_addr) \
98 : "0" (retval),"r" (b_addr) \
102 #define H8300_GEN_TEST_BITOP_CONST(OP,BIT) \
104 __asm__("bld #" #BIT ",@%3\n\t" \
105 OP " #" #BIT ",@%3\n\t" \
107 : "=r"(retval),"=m"(*b_addr) \
108 : "0" (retval),"r" (b_addr) \
112 #define H8300_GEN_TEST_BITOP(FNNAME,OP) \
113 static __inline__ int FNNAME(int nr, volatile void * addr) \
117 volatile unsigned char *b_addr; \
118 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
119 if (__builtin_constant_p(nr)) { \
121 H8300_GEN_TEST_BITOP_CONST_INT(OP,0) \
122 H8300_GEN_TEST_BITOP_CONST_INT(OP,1) \
123 H8300_GEN_TEST_BITOP_CONST_INT(OP,2) \
124 H8300_GEN_TEST_BITOP_CONST_INT(OP,3) \
125 H8300_GEN_TEST_BITOP_CONST_INT(OP,4) \
126 H8300_GEN_TEST_BITOP_CONST_INT(OP,5) \
127 H8300_GEN_TEST_BITOP_CONST_INT(OP,6) \
128 H8300_GEN_TEST_BITOP_CONST_INT(OP,7) \
131 __asm__("stc ccr,%w1\n\t" \
132 "orc #0x80,ccr\n\t" \
139 : "=r"(retval),"=&r"(ccrsave),"=m"(*b_addr) \
140 : "0" (retval),"r" (b_addr),"r"(nr) \
146 static __inline__ int __ ## FNNAME(int nr, volatile void * addr) \
149 volatile unsigned char *b_addr; \
150 b_addr = (volatile unsigned char *)addr + ((nr >> 3) ^ 3); \
151 if (__builtin_constant_p(nr)) { \
153 H8300_GEN_TEST_BITOP_CONST(OP,0) \
154 H8300_GEN_TEST_BITOP_CONST(OP,1) \
155 H8300_GEN_TEST_BITOP_CONST(OP,2) \
156 H8300_GEN_TEST_BITOP_CONST(OP,3) \
157 H8300_GEN_TEST_BITOP_CONST(OP,4) \
158 H8300_GEN_TEST_BITOP_CONST(OP,5) \
159 H8300_GEN_TEST_BITOP_CONST(OP,6) \
160 H8300_GEN_TEST_BITOP_CONST(OP,7) \
163 __asm__("btst %w4,@%3\n\t" \
168 : "=r"(retval),"=m"(*b_addr) \
169 : "0" (retval),"r" (b_addr),"r"(nr) \
175 H8300_GEN_TEST_BITOP(test_and_set_bit
, "bset")
176 H8300_GEN_TEST_BITOP(test_and_clear_bit
, "bclr")
177 H8300_GEN_TEST_BITOP(test_and_change_bit
,"bnot")
178 #undef H8300_GEN_TEST_BITOP_CONST
179 #undef H8300_GEN_TEST_BITOP_CONST_INT
180 #undef H8300_GEN_TEST_BITOP
182 #include <asm-generic/bitops/ffs.h>
184 static __inline__
unsigned long __ffs(unsigned long word
)
186 unsigned long result
;
194 : "0"(result
),"r"(word
));
198 #include <asm-generic/bitops/find.h>
199 #include <asm-generic/bitops/sched.h>
200 #include <asm-generic/bitops/hweight.h>
201 #include <asm-generic/bitops/lock.h>
202 #include <asm-generic/bitops/le.h>
203 #include <asm-generic/bitops/ext2-atomic.h>
205 #endif /* __KERNEL__ */
207 #include <asm-generic/bitops/fls.h>
208 #include <asm-generic/bitops/__fls.h>
209 #include <asm-generic/bitops/fls64.h>
211 #endif /* _H8300_BITOPS_H */