- As known, on x86_64 can be Store-Load reordering, if between Store & Load is no
MFENCE
.
Intel® 64 and IA-32 Architectures
8.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locations
- Also known, that in such example can be Store-Load reordering
c.store(relaxed)
<--> b.load(seq_cst)
: https://stackoverflow.com/a/42857017/1558037
// Atomic load-store
void test() {
std::atomic<int> b, c;
c.store(4, std::memory_order_relaxed); // movl 4,[c];
int tmp = b.load(std::memory_order_seq_cst); // movl [b],[tmp];
}
can be reordered to:
// Atomic load-store
void test() {
std::atomic<int> b, c;
int tmp = b.load(std::memory_order_seq_cst); // movl [b],[tmp];
c.store(4, std::memory_order_relaxed); // movl 4,[c];
}
Because, there is no MFENCE
on x86_64:
- clang 4.0.0 - x86_64: https://godbolt.org/g/N9CPyJ
- gcc 7.0 - x86_64: https://godbolt.org/g/MdjvI0
But is there a really working example which showing the side effect of Store-Load reordering on x86_64?
Example, that shows correct result when used Store(seq_cst), Load(seq_cst)
, but shows wrong result when used Store(relaxed), Load(seq_cst)
.
Or is Store-Load reordering allowed on x86_64 because it can not be detected and shown in a program?