mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-11 10:15:36 +00:00
atomics: Use __atomic_*_n() variant primitives
Use the __atomic_*_n() primitives which take the value as argument. It is not necessary to store the value locally before calling the primitive, hence saving us a stack store and load. Backports commit 89943de17c4e276f2c47f05b4604e8816a6a636c from qemu
This commit is contained in:
parent
1a2c30abbf
commit
9e6fec8741
|
@ -60,14 +60,13 @@ void _ReadWriteBarrier(void);
|
||||||
*/
|
*/
|
||||||
#define atomic_read(ptr) \
|
#define atomic_read(ptr) \
|
||||||
({ \
|
({ \
|
||||||
typeof(*ptr) _val; \
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
__atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
|
__atomic_load_n(ptr, __ATOMIC_RELAXED); \
|
||||||
_val; \
|
|
||||||
})
|
})
|
||||||
|
|
||||||
#define atomic_set(ptr, i) do { \
|
#define atomic_set(ptr, i) do { \
|
||||||
typeof(*ptr) _val = (i); \
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
__atomic_store(ptr, &_val, __ATOMIC_RELAXED); \
|
__atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/* See above: most compilers currently treat consume and acquire the
|
/* See above: most compilers currently treat consume and acquire the
|
||||||
|
@ -84,14 +83,15 @@ void _ReadWriteBarrier(void);
|
||||||
|
|
||||||
#define atomic_rcu_read(ptr) \
|
#define atomic_rcu_read(ptr) \
|
||||||
({ \
|
({ \
|
||||||
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
typeof(*ptr) _val; \
|
typeof(*ptr) _val; \
|
||||||
atomic_rcu_read__nocheck(ptr, &_val); \
|
atomic_rcu_read__nocheck(ptr, &_val); \
|
||||||
_val; \
|
_val; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define atomic_rcu_set(ptr, i) do { \
|
#define atomic_rcu_set(ptr, i) do { \
|
||||||
typeof(*ptr) _val = (i); \
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
__atomic_store(ptr, &_val, __ATOMIC_RELEASE); \
|
__atomic_store_n(ptr, i, __ATOMIC_RELEASE); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/* atomic_mb_read/set semantics map Java volatile variables. They are
|
/* atomic_mb_read/set semantics map Java volatile variables. They are
|
||||||
|
@ -105,6 +105,7 @@ void _ReadWriteBarrier(void);
|
||||||
#if defined(_ARCH_PPC)
|
#if defined(_ARCH_PPC)
|
||||||
#define atomic_mb_read(ptr) \
|
#define atomic_mb_read(ptr) \
|
||||||
({ \
|
({ \
|
||||||
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
typeof(*ptr) _val; \
|
typeof(*ptr) _val; \
|
||||||
__atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
|
__atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
|
||||||
smp_rmb(); \
|
smp_rmb(); \
|
||||||
|
@ -112,22 +113,23 @@ void _ReadWriteBarrier(void);
|
||||||
})
|
})
|
||||||
|
|
||||||
#define atomic_mb_set(ptr, i) do { \
|
#define atomic_mb_set(ptr, i) do { \
|
||||||
typeof(*ptr) _val = (i); \
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
smp_wmb(); \
|
smp_wmb(); \
|
||||||
__atomic_store(ptr, &_val, __ATOMIC_RELAXED); \
|
__atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
|
||||||
smp_mb(); \
|
smp_mb(); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#else
|
#else
|
||||||
#define atomic_mb_read(ptr) \
|
#define atomic_mb_read(ptr) \
|
||||||
({ \
|
({ \
|
||||||
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
typeof(*ptr) _val; \
|
typeof(*ptr) _val; \
|
||||||
__atomic_load(ptr, &_val, __ATOMIC_SEQ_CST); \
|
__atomic_load(ptr, &_val, __ATOMIC_SEQ_CST); \
|
||||||
_val; \
|
_val; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define atomic_mb_set(ptr, i) do { \
|
#define atomic_mb_set(ptr, i) do { \
|
||||||
typeof(*ptr) _val = (i); \
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
__atomic_store(ptr, &_val, __ATOMIC_SEQ_CST); \
|
__atomic_store_n(ptr, i, __ATOMIC_SEQ_CST); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -135,18 +137,17 @@ void _ReadWriteBarrier(void);
|
||||||
/* All the remaining operations are fully sequentially consistent */
|
/* All the remaining operations are fully sequentially consistent */
|
||||||
|
|
||||||
#define atomic_xchg(ptr, i) ({ \
|
#define atomic_xchg(ptr, i) ({ \
|
||||||
typeof(*ptr) _new = (i), _old; \
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
__atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \
|
__atomic_exchange_n(ptr, i, __ATOMIC_SEQ_CST); \
|
||||||
_old; \
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/* Returns the eventual value, failed or not */
|
/* Returns the eventual value, failed or not */
|
||||||
#define atomic_cmpxchg(ptr, old, new) \
|
#define atomic_cmpxchg(ptr, old, new) \
|
||||||
({ \
|
({ \
|
||||||
|
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
|
||||||
typeof(*ptr) _old = (old), _new = (new); \
|
typeof(*ptr) _old = (old), _new = (new); \
|
||||||
__atomic_compare_exchange(ptr, &_old, &_new, false, \
|
__atomic_compare_exchange_n(ptr, &_old, new, false, \
|
||||||
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
|
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
|
||||||
_old; \
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/* Provide shorter names for GCC atomic builtins, return old value */
|
/* Provide shorter names for GCC atomic builtins, return old value */
|
||||||
|
|
Loading…
Reference in a new issue