According to GCC definition: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
__ATOMIC_SEQ_CST Enforces total ordering with all other __ATOMIC_SEQ_CST operations.
now let's look on the following example:
int test(int* num)
{
int m = __atomic_load_n(num, __ATOMIC_SEQ_CST);
int z = __atomic_load_n(num, __ATOMIC_SEQ_CST);
}
compiling with x86-64 gcc 12.2 produce the following assembly using this site https://godbolt.org/
test:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-4], eax
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-8], eax
nop
pop rbp
ret
now my question is, what prevents CPU reordering between these two atomics operations?