27 const uint64_t *old_value,
28 const uint64_t *new_value) {
30 #if defined(__GNUC__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16)
32 __uint128_t* ptr_casted =
reinterpret_cast<__uint128_t*
>(ptr);
33 __uint128_t old_casted = *
reinterpret_cast<const __uint128_t*
>(old_value);
34 __uint128_t new_casted = *
reinterpret_cast<const __uint128_t*
>(new_value);
35 ret = ::__sync_bool_compare_and_swap(ptr_casted, old_casted, new_casted);
36 #elif defined(__GNUC__) && defined(__aarch64__)
39 __uint128_t* ptr_casted =
reinterpret_cast<__uint128_t*
>(ptr);
40 __uint128_t old_casted = *
reinterpret_cast<const __uint128_t*
>(old_value);
41 __uint128_t new_casted = *
reinterpret_cast<const __uint128_t*
>(new_value);
42 ret = ::__atomic_compare_exchange_16(
49 #else // everything else
53 asm volatile(
"lock; cmpxchg16b %2;setz %1"
54 :
"=d"(junk),
"=a"(ret),
"+m" (*ptr)
55 :
"b"(new_value[0]),
"c"(new_value[1]),
"a"(old_value[0]),
"d"(old_value[1]));
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
bool raw_atomic_compare_exchange_strong_uint128(uint64_t *ptr, const uint64_t *old_value, const uint64_t *new_value)
Atomic 128-bit CAS, which is not in the standard yet.
Raw atomic operations that work for both C++11 and non-C++11 code.