Sujet : Strange asm generated by GCC...
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.archDate : 20. Dec 2024, 01:43:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vk2ek2$33ckv$3@dont-email.me>
User-Agent : Mozilla Thunderbird
Why in the world would GCC use an XCHG instruction for the following code. The damn XCHG has an implied LOCK prefix! Yikes!
https://godbolt.org/z/Thxchdcr8_______________________
#include <atomic>
int main()
{
std::atomic<unsigned long> m_state = 0;
m_state.store(std::memory_order_relaxed);
return 0;
}
_______________________
Here is the generated ASM:
_______________________
main:
mov QWORD PTR [rsp-8], 0
xor eax, eax
xchg rax, QWORD PTR [rsp-8]
xor eax, eax
ret
_______________________
WTF!!!!!!!!