8d1a03e51ae3f5b7aee2f32b1812023c49739617
[oweals/musl.git] / arch / x32 / atomic_arch.h
1 #define a_ctz_64 a_ctz_64
2 static inline int a_ctz_64(uint64_t x)
3 {
4         __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
5         return x;
6 }
7
8 #define a_ctz_l a_ctz_l
9 static inline int a_ctz_l(unsigned long x)
10 {
11         __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
12         return x;
13 }
14
15 #define a_and_64 a_and_64
16 static inline void a_and_64(volatile uint64_t *p, uint64_t v)
17 {
18         __asm__( "lock ; and %1, %0"
19                          : "=m"(*p) : "r"(v) : "memory" );
20 }
21
22 #define a_or_64 a_or_64
23 static inline void a_or_64(volatile uint64_t *p, uint64_t v)
24 {
25         __asm__( "lock ; or %1, %0"
26                          : "=m"(*p) : "r"(v) : "memory" );
27 }
28
29 #define a_or_l a_or_l
30 static inline void a_or_l(volatile void *p, long v)
31 {
32         __asm__( "lock ; or %1, %0"
33                 : "=m"(*(long *)p) : "r"(v) : "memory" );
34 }
35
36 #define a_cas a_cas
37 static inline int a_cas(volatile int *p, int t, int s)
38 {
39         __asm__( "lock ; cmpxchg %3, %1"
40                 : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
41         return t;
42 }
43
44 #define a_or a_or
45 static inline void a_or(volatile int *p, int v)
46 {
47         __asm__( "lock ; or %1, %0"
48                 : "=m"(*p) : "r"(v) : "memory" );
49 }
50
51 #define a_and a_and
52 static inline void a_and(volatile int *p, int v)
53 {
54         __asm__( "lock ; and %1, %0"
55                 : "=m"(*p) : "r"(v) : "memory" );
56 }
57
58 #define a_swap a_swap
59 static inline int a_swap(volatile int *x, int v)
60 {
61         __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
62         return v;
63 }
64
65 #define a_fetch_add a_fetch_add
66 static inline int a_fetch_add(volatile int *x, int v)
67 {
68         __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
69         return v;
70 }
71
72 #define a_inc a_inc
73 static inline void a_inc(volatile int *x)
74 {
75         __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
76 }
77
78 #define a_dec a_dec
79 static inline void a_dec(volatile int *x)
80 {
81         __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
82 }
83
84 #define a_store a_store
85 static inline void a_store(volatile int *p, int x)
86 {
87         __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
88 }
89
90 #define a_spin a_spin
91 static inline void a_spin()
92 {
93         __asm__ __volatile__( "pause" : : : "memory" );
94 }
95
96 #define a_barrier a_barrier
97 static inline void a_barrier()
98 {
99         __asm__ __volatile__( "" : : : "memory" );
100 }
101
102 #define a_crash a_crash
103 static inline void a_crash()
104 {
105         __asm__ __volatile__( "hlt" : : : "memory" );
106 }