In x86_64 architecture, we could use cmpxchg16b to compare and exchange a 128bit value in one atomic operation. But how to operate a 128bit value in aarch64 architecture (arm64) machine ? The answer is __atomic_compare_exchange().
As below code:
.... __int128 value = 0, value1 = 0, value2 = 1; __int128 ptr = &value; __int128 expected = &value1; __int128 desired = &value2; __atomic_compare_exchange(ptr, expected, desitre, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); ....
use “gcc test.c -o test” to compile code, but it reports:
undefined reference to `__atomic_compare_exchange_16'
The reason is we have not use “libatomic.so”, so use “gcc test.c -o test -latomic” to compile and link the code agin. It works in Fedora 21 (aarch64).