Deutsch English Français Italiano |
<vk4ib8$3jn8h$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: jseigh <jseigh_es00@xemaps.com> Newsgroups: comp.arch Subject: Re: Strange asm generated by GCC... Date: Fri, 20 Dec 2024 14:59:36 -0500 Organization: A noiseless patient Spider Lines: 38 Message-ID: <vk4ib8$3jn8h$1@dont-email.me> References: <vk2ek2$33ckv$3@dont-email.me> <vk4ahk$3i1bs$1@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 20:59:36 +0100 (CET) Injection-Info: dont-email.me; posting-host="cfa45f408349cb568665e199ccce92c2"; logging-data="3792145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hI7v0gv9M5n9i0iZSJ3Ov" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ODWyIytKbmEvSbYHGUsu6aiLdXE= In-Reply-To: <vk4ahk$3i1bs$1@dont-email.me> Content-Language: en-US Bytes: 2045 On 12/20/24 12:46, jseigh wrote: > On 12/19/24 19:43, 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! >> > > Speaking of strange code > That should be a ref paramter. I though I updated the pasted code. #include <atomic> bool test1(std::atomic<int>& var, int addend) { int expected = var.load(std::memory_order_relaxed); int update = expected + addend; return var.compare_exchange_weak(expected, update, std::memory_order_acq_rel, std::memory_order_seq_cst); } test1(std::atomic<int>&, int): // @test1(std::atomic<int>&, int) ldr w8, [x0] ldaxr w9, [x0] cmp w9, w8 b.ne .LBB0_3 add w8, w8, w1 stlxr w9, w8, [x0] cbz w9, .LBB0_4 mov w0, wzr ret ..LBB0_3: clrex mov w0, wzr ret ..LBB0_4: mov w0, #1 ret