Debian Codegraph @

internal/overlay/musl/arch/i386/atomic_arch.h

raw
1 #define a_cas a_cas
2 static inline int a_cas(volatile int *p, int t, int s)
3 #ifndef __CCGO__
4 {
5 __asm__ __volatile__ (
6 "lock ; cmpxchg %3, %1"
7 : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
8 return t;
9 }
10 #else
11 ;
12 #endif
13
14 #define a_swap a_swap
15 static inline int a_swap(volatile int *p, int v)
16 #ifndef __CCGO__
17 {
18 __asm__ __volatile__(
19 "xchg %0, %1"
20 : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
21 return v;
22 }
23 #else
24 ;
25 #endif
26
27 #define a_fetch_add a_fetch_add
28 static inline int a_fetch_add(volatile int *p, int v)
29 #ifndef __CCGO__
30 {
31 __asm__ __volatile__(
32 "lock ; xadd %0, %1"
33 : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
34 return v;
35 }
36 #else
37 ;
38 #endif
39
40 #define a_and a_and
41 static inline void a_and(volatile int *p, int v)
42 #ifndef __CCGO__
43 {
44 __asm__ __volatile__(
45 "lock ; and %1, %0"
46 : "=m"(*p) : "r"(v) : "memory" );
47 }
48 #else
49 ;
50 #endif
51
52 #define a_or a_or
53 static inline void a_or(volatile int *p, int v)
54 #ifndef __CCGO__
55 {
56 __asm__ __volatile__(
57 "lock ; or %1, %0"
58 : "=m"(*p) : "r"(v) : "memory" );
59 }
60 #else
61 ;
62 #endif
63
64 #define a_inc a_inc
65 static inline void a_inc(volatile int *p)
66 #ifndef __CCGO__
67 {
68 __asm__ __volatile__(
69 "lock ; incl %0"
70 : "=m"(*p) : "m"(*p) : "memory" );
71 }
72 #else
73 ;
74 #endif
75
76 #define a_dec a_dec
77 static inline void a_dec(volatile int *p)
78 #ifndef __CCGO__
79 {
80 __asm__ __volatile__(
81 "lock ; decl %0"
82 : "=m"(*p) : "m"(*p) : "memory" );
83 }
84 #else
85 ;
86 #endif
87
88 #define a_store a_store
89 static inline void a_store(volatile int *p, int x)
90 #ifndef __CCGO__
91 {
92 __asm__ __volatile__(
93 "mov %1, %0 ; lock ; orl $0,(%%esp)"
94 : "=m"(*p) : "r"(x) : "memory" );
95 }
96 #else
97 ;
98 #endif
99
100 #define a_barrier a_barrier
101 static inline void a_barrier()
102 #ifndef __CCGO__
103 {
104 __asm__ __volatile__( "" : : : "memory" );
105 }
106 #else
107 ;
108 #endif
109
110 #define a_spin a_spin
111 static inline void a_spin()
112 #ifndef __CCGO__
113 {
114 __asm__ __volatile__( "pause" : : : "memory" );
115 }
116 #else
117 ;
118 #endif
119
120 #define a_crash a_crash
121 static inline void a_crash()
122 #ifndef __CCGO__
123 {
124 __asm__ __volatile__( "hlt" : : : "memory" );
125 }
126 #else
127 ;
128 #endif
129
130 #define a_ctz_64 a_ctz_64
131 static inline int a_ctz_64(uint64_t x)
132 #ifndef __CCGO__
133 {
134 int r;
135 __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; add $32,%0\n1:"
136 : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
137 return r;
138 }
139 #else
140 ;
141 #endif
142
143 #define a_ctz_32 a_ctz_32
144 static inline int a_ctz_32(uint32_t x)
145 #ifndef __CCGO__
146 {
147 int r;
148 __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
149 return r;
150 }
151 #else
152 ;
153 #endif
154
155 #define a_clz_32 a_clz_32
156 static inline int a_clz_32(uint32_t x)
157 #ifndef __CCGO__
158 {
159 __asm__( "bsr %1,%0 ; xor $31,%0" : "=r"(x) : "r"(x) );
160 return x;
161 }
162 #else
163 ;
164 #endif