49#ifndef __ATOMIC_OPS_UNIX_H__
50#define __ATOMIC_OPS_UNIX_H__
54#if defined(__arm__) || defined(__riscv)
59# define JE_FORCE_SYNC_COMPARE_AND_SWAP_1
60# define JE_FORCE_SYNC_COMPARE_AND_SWAP_2
61# define JE_FORCE_SYNC_COMPARE_AND_SWAP_4
62# define JE_FORCE_SYNC_COMPARE_AND_SWAP_8
68#undef ATOMIC_FORCE_USE_FALLBACK
86 while (__sync_lock_test_and_set(&
lock->lock, 1)) {
94 __sync_lock_release(&
lock->lock);
106#define __atomic_impl_load_generic(v) (__sync_synchronize(), *(v))
107#define __atomic_impl_store_generic(p, v) \
110 __sync_synchronize(); \
125#define ATOMIC_LOCKING_OP_AND_FETCH_DEFINE(_type, _op_name, _op) \
126 ATOMIC_INLINE _type##_t atomic_##_op_name##_and_fetch_##_type(_type##_t *p, _type##_t x) \
128 atomic_spin_lock(&_atomic_global_lock); \
129 const _type##_t original_value = *(p); \
130 const _type##_t new_value = original_value _op(x); \
132 atomic_spin_unlock(&_atomic_global_lock); \
136#define ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, _op_name, _op) \
137 ATOMIC_INLINE _type##_t atomic_fetch_and_##_op_name##_##_type(_type##_t *p, _type##_t x) \
139 atomic_spin_lock(&_atomic_global_lock); \
140 const _type##_t original_value = *(p); \
141 *(p) = original_value _op(x); \
142 atomic_spin_unlock(&_atomic_global_lock); \
143 return original_value; \
146#define ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(_type) \
147 ATOMIC_LOCKING_OP_AND_FETCH_DEFINE(_type, add, +)
149#define ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(_type) \
150 ATOMIC_LOCKING_OP_AND_FETCH_DEFINE(_type, sub, -)
152#define ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(_type) \
153 ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, add, +)
155#define ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE(_type) \
156 ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, sub, -)
158#define ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(_type) ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, or, |)
160#define ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(_type) \
161 ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, and, &)
163#define ATOMIC_LOCKING_CAS_DEFINE(_type) \
164 ATOMIC_INLINE _type##_t atomic_cas_##_type(_type##_t *v, _type##_t old, _type##_t _new) \
166 atomic_spin_lock(&_atomic_global_lock); \
167 const _type##_t original_value = *v; \
171 atomic_spin_unlock(&_atomic_global_lock); \
172 return original_value; \
175#define ATOMIC_LOCKING_LOAD_DEFINE(_type) \
176 ATOMIC_INLINE _type##_t atomic_load_##_type(const _type##_t *v) \
178 atomic_spin_lock(&_atomic_global_lock); \
179 const _type##_t value = *v; \
180 atomic_spin_unlock(&_atomic_global_lock); \
184#define ATOMIC_LOCKING_STORE_DEFINE(_type) \
185 ATOMIC_INLINE void atomic_store_##_type(_type##_t *p, const _type##_t v) \
187 atomic_spin_lock(&_atomic_global_lock); \
189 atomic_spin_unlock(&_atomic_global_lock); \
198#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \
199 (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_8))
203 return __sync_add_and_fetch(p, x);
208 return __sync_sub_and_fetch(p, x);
213 return __sync_fetch_and_add(p, x);
218 return __sync_fetch_and_sub(p, x);
223 return __sync_val_compare_and_swap(
v, old, _new);
228 return __atomic_load_n(
v, __ATOMIC_SEQ_CST);
233 __atomic_store(p, &
v, __ATOMIC_SEQ_CST);
239 return __sync_add_and_fetch(p, x);
244 return __sync_sub_and_fetch(p, x);
249 return __sync_fetch_and_add(p, x);
254 return __sync_fetch_and_sub(p, x);
259 return __sync_val_compare_and_swap(
v, old, _new);
264 return __atomic_load_n(
v, __ATOMIC_SEQ_CST);
269 __atomic_store(p, &
v, __ATOMIC_SEQ_CST);
272#elif !defined(ATOMIC_FORCE_USE_FALLBACK) && (defined(__amd64__) || defined(__x86_64__))
276 asm volatile(
"lock; xaddq %0, %1;"
286 asm volatile(
"lock; xaddq %0, %1;"
306 asm volatile(
"lock; cmpxchgq %2,%1" :
"=a"(
ret),
"+m"(*
v) :
"r"(_new),
"0"(old) :
"memory");
323 asm volatile(
"lock; xaddq %0, %1;"
333 asm volatile(
"lock; xaddq %0, %1;"
353 asm volatile(
"lock; cmpxchgq %2,%1" :
"=a"(
ret),
"+m"(*
v) :
"r"(_new),
"0"(old) :
"memory");
402#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \
403 (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4))
407 return __sync_add_and_fetch(p, x);
412 return __sync_sub_and_fetch(p, x);
417 return __sync_val_compare_and_swap(
v, old, _new);
422 return __atomic_load_n(
v, __ATOMIC_SEQ_CST);
427 __atomic_store(p, &
v, __ATOMIC_SEQ_CST);
433 return __sync_add_and_fetch(p, x);
438 return __sync_sub_and_fetch(p, x);
443 return __sync_val_compare_and_swap(
v, old, _new);
448 return __atomic_load_n(
v, __ATOMIC_SEQ_CST);
453 __atomic_store(p, &
v, __ATOMIC_SEQ_CST);
456#elif !defined(ATOMIC_FORCE_USE_FALLBACK) && \
457 (defined(__i386__) || defined(__amd64__) || defined(__x86_64__))
462 asm volatile(
"lock; xaddl %0, %1;"
463 :
"+r"(
ret),
"=m"(*p)
472 asm volatile(
"lock; xaddl %0, %1;"
473 :
"+r"(
ret),
"=m"(*p)
482 asm volatile(
"lock; cmpxchgl %2,%1" :
"=a"(
ret),
"+m"(*
v) :
"r"(_new),
"0"(old) :
"memory");
488 return __atomic_load_n(
v, __ATOMIC_SEQ_CST);
493 __atomic_store(p, &
v, __ATOMIC_SEQ_CST);
500 asm volatile(
"lock; xaddl %0, %1;"
501 :
"+r"(
ret),
"=m"(*p)
510 asm volatile(
"lock; xaddl %0, %1;"
511 :
"+r"(
ret),
"=m"(*p)
520 asm volatile(
"lock; cmpxchgl %2,%1" :
"=a"(
ret),
"+m"(*
v) :
"r"(_new),
"0"(old) :
"memory");
526 return __atomic_load_n(
v, __ATOMIC_SEQ_CST);
531 __atomic_store(p, &
v, __ATOMIC_SEQ_CST);
558#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \
559 (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4))
563 return __sync_fetch_and_add(p, x);
568 return __sync_fetch_and_or(p, x);
573 return __sync_fetch_and_and(p, x);
579 return __sync_fetch_and_add(p, x);
584 return __sync_fetch_and_or(p, x);
589 return __sync_fetch_and_and(p, x);
612#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \
613 (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_2))
618 return __sync_fetch_and_and(p,
b);
622 return __sync_fetch_and_or(p,
b);
638#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \
639 (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_1))
644 return __sync_fetch_and_and(p,
b);
648 return __sync_fetch_and_or(p,
b);
654 return __sync_fetch_and_and(p,
b);
658 return __sync_fetch_and_or(p,
b);
675#undef __atomic_impl_load_generic
676#undef __atomic_impl_store_generic
678#undef ATOMIC_LOCKING_OP_AND_FETCH_DEFINE
679#undef ATOMIC_LOCKING_FETCH_AND_OP_DEFINE
680#undef ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE
681#undef ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE
682#undef ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE
683#undef ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE
684#undef ATOMIC_LOCKING_FETCH_AND_OR_DEFINE
685#undef ATOMIC_LOCKING_FETCH_AND_AND_DEFINE
686#undef ATOMIC_LOCKING_CAS_DEFINE
687#undef ATOMIC_LOCKING_LOAD_DEFINE
688#undef ATOMIC_LOCKING_STORE_DEFINE
ATOMIC_INLINE uint32_t atomic_fetch_and_or_uint32(uint32_t *p, uint32_t x)
ATOMIC_INLINE int32_t atomic_add_and_fetch_int32(int32_t *p, int32_t x)
ATOMIC_INLINE int16_t atomic_fetch_and_or_int16(int16_t *p, int16_t b)
ATOMIC_INLINE void atomic_store_uint64(uint64_t *p, uint64_t v)
ATOMIC_INLINE uint64_t atomic_fetch_and_sub_uint64(uint64_t *p, uint64_t x)
ATOMIC_INLINE int64_t atomic_sub_and_fetch_int64(int64_t *p, int64_t x)
ATOMIC_INLINE uint8_t atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
ATOMIC_INLINE uint64_t atomic_load_uint64(const uint64_t *v)
ATOMIC_INLINE int64_t atomic_cas_int64(int64_t *v, int64_t old, int64_t _new)
ATOMIC_INLINE uint32_t atomic_fetch_and_add_uint32(uint32_t *p, uint32_t x)
ATOMIC_INLINE uint8_t atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b)
ATOMIC_INLINE int32_t atomic_load_int32(const int32_t *v)
ATOMIC_INLINE int64_t atomic_load_int64(const int64_t *v)
ATOMIC_INLINE int32_t atomic_fetch_and_or_int32(int32_t *p, int32_t x)
ATOMIC_INLINE uint32_t atomic_fetch_and_and_uint32(uint32_t *p, uint32_t x)
ATOMIC_INLINE void atomic_store_int64(int64_t *p, int64_t v)
ATOMIC_INLINE int64_t atomic_fetch_and_add_int64(int64_t *p, int64_t x)
ATOMIC_INLINE uint32_t atomic_add_and_fetch_uint32(uint32_t *p, uint32_t x)
ATOMIC_INLINE void atomic_store_int32(int32_t *p, int32_t v)
ATOMIC_INLINE int32_t atomic_fetch_and_add_int32(int32_t *p, int32_t x)
ATOMIC_INLINE uint64_t atomic_cas_uint64(uint64_t *v, uint64_t old, uint64_t _new)
ATOMIC_INLINE uint64_t atomic_fetch_and_add_uint64(uint64_t *p, uint64_t x)
ATOMIC_INLINE uint32_t atomic_sub_and_fetch_uint32(uint32_t *p, uint32_t x)
ATOMIC_INLINE int16_t atomic_fetch_and_and_int16(int16_t *p, int16_t b)
ATOMIC_INLINE int64_t atomic_add_and_fetch_int64(int64_t *p, int64_t x)
ATOMIC_INLINE uint64_t atomic_add_and_fetch_uint64(uint64_t *p, uint64_t x)
ATOMIC_INLINE uint32_t atomic_load_uint32(const uint32_t *v)
ATOMIC_INLINE uint64_t atomic_sub_and_fetch_uint64(uint64_t *p, uint64_t x)
ATOMIC_INLINE void atomic_store_uint32(uint32_t *p, uint32_t v)
ATOMIC_INLINE int32_t atomic_cas_int32(int32_t *v, int32_t old, int32_t _new)
ATOMIC_INLINE int32_t atomic_fetch_and_and_int32(int32_t *p, int32_t x)
ATOMIC_INLINE int8_t atomic_fetch_and_or_int8(int8_t *p, int8_t b)
ATOMIC_INLINE int32_t atomic_sub_and_fetch_int32(int32_t *p, int32_t x)
ATOMIC_INLINE int8_t atomic_fetch_and_and_int8(int8_t *p, int8_t b)
ATOMIC_INLINE int64_t atomic_fetch_and_sub_int64(int64_t *p, int64_t x)
ATOMIC_INLINE uint32_t atomic_cas_uint32(uint32_t *v, uint32_t old, uint32_t _new)
struct AtomicSpinLock __attribute__((aligned(32))) AtomicSpinLock
ATOMIC_INLINE void atomic_spin_lock(volatile AtomicSpinLock *lock)
ATOMIC_INLINE void atomic_spin_unlock(volatile AtomicSpinLock *lock)
#define ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(_type)
#define ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE(_type)
#define __atomic_impl_load_generic(v)
#define ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(_type)
#define ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(_type)
static _ATOMIC_MAYBE_UNUSED AtomicSpinLock _atomic_global_lock
#define ATOMIC_LOCKING_LOAD_DEFINE(_type)
#define __atomic_impl_store_generic(p, v)
#define ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(_type)
#define ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(_type)
#define ATOMIC_LOCKING_CAS_DEFINE(_type)
#define ATOMIC_LOCKING_STORE_DEFINE(_type)
#define _ATOMIC_MAYBE_UNUSED
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
unsigned __int64 uint64_t
int pad[32 - sizeof(int)]