WIP FPC-III support
[linux/fpc-iii.git] / arch / sh / include / asm / bitops-cas.h
blobba517b3f24da62cef771b1cd6be4e99a1994e123
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_BITOPS_CAS_H
3 #define __ASM_SH_BITOPS_CAS_H
5 static inline unsigned __bo_cas(volatile unsigned *p, unsigned old, unsigned new)
7 __asm__ __volatile__("cas.l %1,%0,@r0"
8 : "+r"(new)
9 : "r"(old), "z"(p)
10 : "t", "memory" );
11 return new;
14 static inline void set_bit(int nr, volatile void *addr)
16 unsigned mask, old;
17 volatile unsigned *a = addr;
19 a += nr >> 5;
20 mask = 1U << (nr & 0x1f);
22 do old = *a;
23 while (__bo_cas(a, old, old|mask) != old);
26 static inline void clear_bit(int nr, volatile void *addr)
28 unsigned mask, old;
29 volatile unsigned *a = addr;
31 a += nr >> 5;
32 mask = 1U << (nr & 0x1f);
34 do old = *a;
35 while (__bo_cas(a, old, old&~mask) != old);
38 static inline void change_bit(int nr, volatile void *addr)
40 unsigned mask, old;
41 volatile unsigned *a = addr;
43 a += nr >> 5;
44 mask = 1U << (nr & 0x1f);
46 do old = *a;
47 while (__bo_cas(a, old, old^mask) != old);
50 static inline int test_and_set_bit(int nr, volatile void *addr)
52 unsigned mask, old;
53 volatile unsigned *a = addr;
55 a += nr >> 5;
56 mask = 1U << (nr & 0x1f);
58 do old = *a;
59 while (__bo_cas(a, old, old|mask) != old);
61 return !!(old & mask);
64 static inline int test_and_clear_bit(int nr, volatile void *addr)
66 unsigned mask, old;
67 volatile unsigned *a = addr;
69 a += nr >> 5;
70 mask = 1U << (nr & 0x1f);
72 do old = *a;
73 while (__bo_cas(a, old, old&~mask) != old);
75 return !!(old & mask);
78 static inline int test_and_change_bit(int nr, volatile void *addr)
80 unsigned mask, old;
81 volatile unsigned *a = addr;
83 a += nr >> 5;
84 mask = 1U << (nr & 0x1f);
86 do old = *a;
87 while (__bo_cas(a, old, old^mask) != old);
89 return !!(old & mask);
92 #include <asm-generic/bitops/non-atomic.h>
94 #endif /* __ASM_SH_BITOPS_CAS_H */