17 #include <linux/compiler.h>
18 #include <asm/byteorder.h>
22 #ifndef _LINUX_BITOPS_H
23 #error only <linux/bitops.h> can be included directly
31 #define smp_mb__before_clear_bit() barrier()
32 #define smp_mb__after_clear_bit() barrier()
34 #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
36 unsigned long atomic_test_and_ANDNOT_mask(
unsigned long mask,
volatile unsigned long *
v)
38 unsigned long old,
tmp;
42 " orcc gr0,gr0,gr0,icc3 \n"
45 " orcr cc7,cc7,cc3 \n"
47 " cst.p %2,%M0 ,cc3,#1 \n"
48 " corcc gr29,gr29,gr0 ,cc3,#1 \n"
50 :
"+U"(*v),
"=&r"(old),
"=r"(tmp)
52 :
"memory",
"cc7",
"cc3",
"icc3"
59 unsigned long atomic_test_and_OR_mask(
unsigned long mask,
volatile unsigned long *v)
61 unsigned long old,
tmp;
65 " orcc gr0,gr0,gr0,icc3 \n"
68 " orcr cc7,cc7,cc3 \n"
70 " cst.p %2,%M0 ,cc3,#1 \n"
71 " corcc gr29,gr29,gr0 ,cc3,#1 \n"
73 :
"+U"(*v),
"=&r"(old),
"=r"(tmp)
75 :
"memory",
"cc7",
"cc3",
"icc3"
82 unsigned long atomic_test_and_XOR_mask(
unsigned long mask,
volatile unsigned long *v)
84 unsigned long old,
tmp;
88 " orcc gr0,gr0,gr0,icc3 \n"
91 " orcr cc7,cc7,cc3 \n"
93 " cst.p %2,%M0 ,cc3,#1 \n"
94 " corcc gr29,gr29,gr0 ,cc3,#1 \n"
96 :
"+U"(*v),
"=&r"(old),
"=r"(tmp)
98 :
"memory",
"cc7",
"cc3",
"icc3"
106 extern unsigned long atomic_test_and_ANDNOT_mask(
unsigned long mask,
volatile unsigned long *v);
107 extern unsigned long atomic_test_and_OR_mask(
unsigned long mask,
volatile unsigned long *v);
108 extern unsigned long atomic_test_and_XOR_mask(
unsigned long mask,
volatile unsigned long *v);
112 #define atomic_clear_mask(mask, v) atomic_test_and_ANDNOT_mask((mask), (v))
113 #define atomic_set_mask(mask, v) atomic_test_and_OR_mask((mask), (v))
117 volatile unsigned long *
ptr =
addr;
118 unsigned long mask = 1
UL << (nr & 31);
120 return (atomic_test_and_ANDNOT_mask(mask, ptr) &
mask) != 0;
125 volatile unsigned long *ptr =
addr;
126 unsigned long mask = 1
UL << (nr & 31);
128 return (atomic_test_and_OR_mask(mask, ptr) &
mask) != 0;
133 volatile unsigned long *ptr =
addr;
134 unsigned long mask = 1
UL << (nr & 31);
136 return (atomic_test_and_XOR_mask(mask, ptr) &
mask) != 0;
139 static inline void clear_bit(
unsigned long nr,
volatile void *addr)
144 static inline void set_bit(
unsigned long nr,
volatile void *addr)
149 static inline void change_bit(
unsigned long nr,
volatile void *addr)
154 static inline void __clear_bit(
unsigned long nr,
volatile void *addr)
156 volatile unsigned long *
a =
addr;
160 mask = 1 << (nr & 31);
164 static inline void __set_bit(
unsigned long nr,
volatile void *addr)
166 volatile unsigned long *
a =
addr;
170 mask = 1 << (nr & 31);
174 static inline void __change_bit(
unsigned long nr,
volatile void *addr)
176 volatile unsigned long *
a =
addr;
180 mask = 1 << (nr & 31);
186 volatile unsigned long *
a =
addr;
190 mask = 1 << (nr & 31);
191 retval = (mask & *
a) != 0;
198 volatile unsigned long *
a =
addr;
202 mask = 1 << (nr & 31);
203 retval = (mask & *
a) != 0;
210 volatile unsigned long *
a =
addr;
214 mask = 1 << (nr & 31);
215 retval = (mask & *
a) != 0;
224 __constant_test_bit(
unsigned long nr,
const volatile void *addr)
226 return ((1
UL << (nr & 31)) & (((
const volatile unsigned int *) addr)[nr >> 5])) != 0;
229 static inline int __test_bit(
unsigned long nr,
const volatile void *addr)
231 int *
a = (
int *) addr;
235 mask = 1 << (nr & 0x1f);
236 return ((mask & *a) != 0);
239 #define test_bit(nr,addr) \
240 (__builtin_constant_p(nr) ? \
241 __constant_test_bit((nr),(addr)) : \
242 __test_bit((nr),(addr)))
258 asm(" subcc %1,gr0,gr0,icc0 \n" \
259 " ckne icc0,cc4 \n" \
260 " cscan.p %1,gr0,%0 ,cc4,#1 \n" \
261 " csub %0,%0,%0 ,cc4,#0 \n" \
262 " csub %2,%0,%0 ,cc4,#1 \n" \
284 struct {
u32 h,
l; };
290 asm(
" subcc.p %3,gr0,gr0,icc0 \n"
291 " subcc %4,gr0,gr0,icc1 \n"
294 " norcr cc4,cc5,cc6 \n"
295 " csub.p %0,%0,%0 ,cc6,1 \n"
296 " orcr cc5,cc4,cc4 \n"
297 " andcr cc4,cc5,cc4 \n"
298 " cscan.p %3,gr0,%0 ,cc4,0 \n"
300 " cscan.p %4,gr0,%0 ,cc4,1 \n"
302 " csub.p %1,%0,%0 ,cc4,0 \n"
303 " csub %2,%0,%0 ,cc4,1 \n"
304 :
"=&r"(
bit),
"=r"(x),
"=r"(
y)
305 :
"0r"(
_.h),
"r"(
_.l)
306 :
"icc0",
"icc1",
"cc4",
"cc5",
"cc6"
339 asm(
"scan %1,gr0,%0" :
"=r"(
bit) :
"r"(x & -x));
349 static inline unsigned long __fls(
unsigned long word)
352 asm(
"scan %1,gr0,%0" :
"=r"(
bit) :
"r"(word));
360 #define ARCH_HAS_ILOG2_U32
365 asm(
"scan %1,gr0,%0" :
"=r"(
bit) :
"r"(n));
373 #define ARCH_HAS_ILOG2_U64
379 struct {
u32 h,
l; };
385 asm(
" subcc %3,gr0,gr0,icc0 \n"
387 " cscan.p %3,gr0,%0 ,cc4,0 \n"
389 " cscan.p %4,gr0,%0 ,cc4,1 \n"
391 " csub.p %1,%0,%0 ,cc4,0 \n"
392 " csub %2,%0,%0 ,cc4,1 \n"
393 :
"=&r"(
bit),
"=r"(x),
"=r"(
y)
394 :
"0r"(
_.h),
"r"(
_.l)