Deutsch   English   Français   Italiano  
<vk2ek2$33ckv$3@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups: comp.arch
Subject: Strange asm generated by GCC...
Date: Thu, 19 Dec 2024 16:43:46 -0800
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <vk2ek2$33ckv$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 20 Dec 2024 01:43:47 +0100 (CET)
Injection-Info: dont-email.me; posting-host="90d0359d260b5ab20f7104a3aa6ad836";
	logging-data="3256991"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+2KAZ3iPzLkNg2828GpEFvZ8+JkTVIbrM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:NqeolGRxoFzu21tdrNOfAPjRRwo=
Content-Language: en-US
Bytes: 1584

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!!!!!!!!