17 of_atomic_int_add(
volatile int *_Nonnull p,
int i)
19 __asm__ __volatile__ (
23 "stwcx. %0, 0, %2\n\t"
33 static OF_INLINE int32_t
34 of_atomic_int32_add(
volatile int32_t *_Nonnull p, int32_t i)
36 __asm__ __volatile__ (
40 "stwcx. %0, 0, %2\n\t"
50 static OF_INLINE
void *_Nullable
51 of_atomic_ptr_add(
void *
volatile _Nullable *_Nonnull p, intptr_t i)
53 __asm__ __volatile__ (
57 "stwcx. %0, 0, %2\n\t"
68 of_atomic_int_sub(
volatile int *_Nonnull p,
int i)
70 __asm__ __volatile__ (
74 "stwcx. %0, 0, %2\n\t"
84 static OF_INLINE int32_t
85 of_atomic_int32_sub(
volatile int32_t *_Nonnull p, int32_t i)
87 __asm__ __volatile__ (
91 "stwcx. %0, 0, %2\n\t"
101 static OF_INLINE
void *_Nullable
102 of_atomic_ptr_sub(
void *
volatile _Nullable *_Nonnull p, intptr_t i)
104 __asm__ __volatile__ (
106 "lwarx %0, 0, %2\n\t"
108 "stwcx. %0, 0, %2\n\t"
119 of_atomic_int_inc(
volatile int *_Nonnull p)
123 __asm__ __volatile__ (
125 "lwarx %0, 0, %1\n\t"
127 "stwcx. %0, 0, %1\n\t"
137 static OF_INLINE int32_t
138 of_atomic_int32_inc(
volatile int32_t *_Nonnull p)
142 __asm__ __volatile__ (
144 "lwarx %0, 0, %1\n\t"
146 "stwcx. %0, 0, %1\n\t"
157 of_atomic_int_dec(
volatile int *_Nonnull p)
161 __asm__ __volatile__ (
163 "lwarx %0, 0, %1\n\t"
165 "stwcx. %0, 0, %1\n\t"
175 static OF_INLINE int32_t
176 of_atomic_int32_dec(
volatile int32_t *_Nonnull p)
180 __asm__ __volatile__ (
182 "lwarx %0, 0, %1\n\t"
184 "stwcx. %0, 0, %1\n\t"
194 static OF_INLINE
unsigned int
195 of_atomic_int_or(
volatile unsigned int *_Nonnull p,
unsigned int i)
197 __asm__ __volatile__ (
199 "lwarx %0, 0, %2\n\t"
201 "stwcx. %0, 0, %2\n\t"
211 static OF_INLINE uint32_t
212 of_atomic_int32_or(
volatile uint32_t *_Nonnull p, uint32_t i)
214 __asm__ __volatile__ (
216 "lwarx %0, 0, %2\n\t"
218 "stwcx. %0, 0, %2\n\t"
228 static OF_INLINE
unsigned int
229 of_atomic_int_and(
volatile unsigned int *_Nonnull p,
unsigned int i)
231 __asm__ __volatile__ (
233 "lwarx %0, 0, %2\n\t"
235 "stwcx. %0, 0, %2\n\t"
245 static OF_INLINE uint32_t
246 of_atomic_int32_and(
volatile uint32_t *_Nonnull p, uint32_t i)
248 __asm__ __volatile__ (
250 "lwarx %0, 0, %2\n\t"
252 "stwcx. %0, 0, %2\n\t"
262 static OF_INLINE
unsigned int
263 of_atomic_int_xor(
volatile unsigned int *_Nonnull p,
unsigned int i)
265 __asm__ __volatile__ (
267 "lwarx %0, 0, %2\n\t"
269 "stwcx. %0, 0, %2\n\t"
279 static OF_INLINE uint32_t
280 of_atomic_int32_xor(
volatile uint32_t *_Nonnull p, uint32_t i)
282 __asm__ __volatile__ (
284 "lwarx %0, 0, %2\n\t"
286 "stwcx. %0, 0, %2\n\t"
296 static OF_INLINE
bool
297 of_atomic_int_cmpswap(
volatile int *_Nonnull p,
int o,
int n)
301 __asm__ __volatile__ (
303 "lwarx %0, 0, %3\n\t"
306 "stwcx. %2, 0, %3\n\t"
311 "stwcx. %0, 0, %3\n\t"
315 :
"r"(o),
"r"(n),
"r"(p)
322 static OF_INLINE
bool
323 of_atomic_int32_cmpswap(
volatile int32_t *_Nonnull p, int32_t o, int32_t n)
327 __asm__ __volatile__ (
329 "lwarx %0, 0, %3\n\t"
332 "stwcx. %2, 0, %3\n\t"
337 "stwcx. %0, 0, %3\n\t"
341 :
"r"(o),
"r"(n),
"r"(p)
348 static OF_INLINE
bool
349 of_atomic_ptr_cmpswap(
void *
volatile _Nullable *_Nonnull p,
350 void *_Nullable o,
void *_Nullable n)
354 __asm__ __volatile__ (
356 "lwarx %0, 0, %3\n\t"
359 "stwcx. %2, 0, %3\n\t"
364 "stwcx. %0, 0, %3\n\t"
368 :
"r"(o),
"r"(n),
"r"(p)
375 static OF_INLINE
void
376 of_memory_barrier(
void)
378 __asm__ __volatile__ (
379 ".long 0x7C2004AC /* lwsync */" :::
"memory"
383 static OF_INLINE
void
384 of_memory_barrier_acquire(
void)
386 __asm__ __volatile__ (
387 ".long 0x7C2004AC /* lwsync */" :::
"memory"
391 static OF_INLINE
void
392 of_memory_barrier_release(
void)
394 __asm__ __volatile__ (
395 ".long 0x7C2004AC /* lwsync */" :::
"memory"