Re: Strange asm generated by GCC...

Liste des GroupesRevenir à c arch 
Sujet : Re: Strange asm generated by GCC...
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.arch
Date : 20. Dec 2024, 01:54:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vk2f93$33q08$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 12/19/2024 4:43 PM, Chris M. Thomasson wrote:
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;
}
_______________________
[...]
Ahhh! Actually, I am not sure what that even compiled! Now, this is much better:
https://godbolt.org/z/d46q9dd4h
_____________________________
#include <atomic>
static std::atomic<unsigned long> m_state = 0;
int main()
{
     m_state.store(1, std::memory_order_relaxed);
     return 0;
}
_____________________________
and I get:
_____________________________
main:
         mov     QWORD PTR m_state[rip], 1
         xor     eax, eax
         ret
_____________________________
Okay. This makes much more sense.

Date Sujet#  Auteur
20 Dec01:43 * Strange asm generated by GCC...11Chris M. Thomasson
20 Dec01:54 +- Re: Strange asm generated by GCC...1Chris M. Thomasson
20 Dec02:02 +* Re: Strange asm generated by GCC...5Chris M. Thomasson
20 Dec12:55 i`* Re: Strange asm generated by GCC...4jseigh
20 Dec21:12 i `* Re: Strange asm generated by GCC...3Chris M. Thomasson
20 Dec21:15 i  +- Re: Strange asm generated by GCC...1Chris M. Thomasson
20 Dec21:23 i  `- Re: Strange asm generated by GCC...1Chris M. Thomasson
20 Dec18:46 `* Re: Strange asm generated by GCC...4jseigh
20 Dec20:59  +* Re: Strange asm generated by GCC...2jseigh
20 Dec21:17  i`- Re: Strange asm generated by GCC...1jseigh
21 Dec11:37  `- Re: Strange asm generated by GCC...1aph

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal