Deutsch English Français Italiano |
<vk4jok$3k2q0$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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: Re: Strange asm generated by GCC... Date: Fri, 20 Dec 2024 12:23:48 -0800 Organization: A noiseless patient Spider Lines: 44 Message-ID: <vk4jok$3k2q0$1@dont-email.me> References: <vk2ek2$33ckv$3@dont-email.me> <vk2fnf$33q08$3@dont-email.me> <vk3m06$3e8ii$1@dont-email.me> <vk4j3u$3k04r$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 20 Dec 2024 21:23:49 +0100 (CET) Injection-Info: dont-email.me; posting-host="90d0359d260b5ab20f7104a3aa6ad836"; logging-data="3803968"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18023A6XnIGTZckepH9ASA1NHvo2JLdo8o=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:exCRxlJ6fivb6F5zTnBJBRKpv6U= Content-Language: en-US In-Reply-To: <vk4j3u$3k04r$1@dont-email.me> Bytes: 2388 On 12/20/2024 12:12 PM, Chris M. Thomasson wrote: > On 12/20/2024 3:55 AM, jseigh wrote: >> On 12/19/24 20:02, Chris M. Thomasson wrote: >>> 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); >>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>> >>> Strange to me that this even compiled at all. I clearly forgot to put >>> in a value. aka: >>> >>> m_state.store(1, std::memory_order_release); >>> >>> Sorry about that. ;^o >> >> The 2nd parameter has a default value, std::memory_order_cst. >> Your 1st argument was a std::memory_order value which is an >> integer value. So basically >> >> m.state.store(std::memory_order_relaxed, std::memory_order_cst); >> > > https://en.cppreference.com/w/cpp/atomic/atomic/store > > The first param is the value we want to store. The second one is memory > order. AHHHHHH!!!!!!!!!!! Yup. This is why it compiled. DOH!!!!!!!! Sorry Joe.