49d9884ab50ddc3fff4f1283cb008cfd708b2179
[musl] / arch / mips64 / atomic_arch.h
1 #define a_ll a_ll
2 static inline int a_ll(volatile int *p)
3 {
4         int v;
5         __asm__ __volatile__ (
6                 "ll %0, %1"
7                 : "=r"(v) : "m"(*p));
8         return v;
9 }
10
11 #define a_sc a_sc
12 static inline int a_sc(volatile int *p, int v)
13 {
14         int r;
15         __asm__ __volatile__ (
16                 "sc %0, %1"
17                 : "=r"(r), "=m"(*p) : "0"(v) : "memory");
18         return r;
19 }
20
21 #define a_ll_p a_ll_p
22 static inline void *a_ll_p(volatile long *p)
23 {
24         void *v;
25         __asm__ __volatile__ (
26                 "lld %0, %1"
27                 : "=r"(v) : "m"(*p));
28         return v;
29 }
30
31 #define a_sc_p a_sc_p
32 static inline int a_sc_p(volatile long *p, void *v)
33 {
34         int r;
35         __asm__ __volatile__ (
36                 "scd %0, %1"
37                 : "=r"(r), "=m"(*p) : "0"(v) : "memory");
38         return r;
39 }
40
41 #define a_barrier a_barrier
42 static inline void a_barrier()
43 {
44         /* mips2 sync, but using too many directives causes
45          * gcc not to inline it, so encode with .long instead. */
46         __asm__ __volatile__ (".long 0xf" : : : "memory");
47 }
48
49 #define a_pre_llsc a_barrier
50 #define a_post_llsc a_barrier