Re: Strange asm generated by GCC...

Liste des GroupesRevenir à c arch 
Sujet : Re: Strange asm generated by GCC...
De : jseigh_es00 (at) *nospam* xemaps.com (jseigh)
Groupes : comp.arch
Date : 24. Dec 2024, 14:26:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vkecpd$1s4mt$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Mozilla Thunderbird
On 12/23/24 21:35, Chris M. Thomasson wrote:
On 12/23/2024 5:53 PM, Chris M. Thomasson wrote:
On 12/23/2024 5:16 PM, jseigh wrote:

>
You are probably ok using relaxed loading the old value.  It's not
real clear how aggressive the compiler is allowed to be with relaxed
loads and stores.  To be super safe, you might want to add acquire
to all your cas loops.
I usually use signal fences in loops w/ relaxed atomics.

>
I would just stick with the compare_exchange w/ 1 memory order
parameter.  The success/fail form is just confusing, the fail
parameter doesn't do anything.
>
>
>
 Actually, can the acquire be relaxed into a consume?
Compare_exchange is 2 ops.
A load which happens on success and fail paths.
A store which effectively only happens on success path.
The memory barrier argument is decomposed into the what
is valid for a load and a store respectively.  The 2nd
memory barrier appears to be redundant.
So for arm w/o cas
#include <atomic>
bool try_add(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);
}
try_add(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
You can see the load has acquire and the store
has the release.  You'd get the same thing even
if you used seq_cst.
Joe Seigh

Date Sujet#  Auteur
20 Dec 24 * Strange asm generated by GCC...21Chris M. Thomasson
20 Dec 24 +- Re: Strange asm generated by GCC...1Chris M. Thomasson
20 Dec 24 +* Re: Strange asm generated by GCC...5Chris M. Thomasson
20 Dec 24 i`* Re: Strange asm generated by GCC...4jseigh
20 Dec 24 i `* Re: Strange asm generated by GCC...3Chris M. Thomasson
20 Dec 24 i  +- Re: Strange asm generated by GCC...1Chris M. Thomasson
20 Dec 24 i  `- Re: Strange asm generated by GCC...1Chris M. Thomasson
20 Dec 24 `* Re: Strange asm generated by GCC...14jseigh
20 Dec 24  +* Re: Strange asm generated by GCC...2jseigh
20 Dec 24  i`- Re: Strange asm generated by GCC...1jseigh
21 Dec 24  `* Re: Strange asm generated by GCC...11aph
23 Dec 24   +- Re: Strange asm generated by GCC...1Chris M. Thomasson
23 Dec 24   `* Re: Strange asm generated by GCC...9Chris M. Thomasson
23 Dec 24    `* Re: Strange asm generated by GCC...8Chris M. Thomasson
23 Dec 24     +- Re: Strange asm generated by GCC...1Chris M. Thomasson
23 Dec 24     `* Re: Strange asm generated by GCC...6aph
23 Dec 24      `* Re: Strange asm generated by GCC...5Chris M. Thomasson
24 Dec 24       `* Re: Strange asm generated by GCC...4jseigh
24 Dec 24        `* Re: Strange asm generated by GCC...3Chris M. Thomasson
24 Dec 24         `* Re: Strange asm generated by GCC...2Chris M. Thomasson
24 Dec 24          `- Re: Strange asm generated by GCC...1jseigh

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal