On Mon, Nov 30, 2026 at 07:55:06PM +0100, Christophe Leroy (CS GROUP) wrote:
> 
> 
> Le 25/11/2026 à 18:40, Nysal Jan K.A. a écrit :
> > +   union __u128_halves tmp, r, o = { .full = (old) },      \
> > +                               n = { .full = (new) };      \
> > +                                                           \
> > +   __asm__ __volatile__ (                                  \
> > +   entry_mb                                                \
> > +"1:     lqarx   14,0,%[ptr]\n"                                     \
> > +"       xor     %[tl],15,%[ol]\n"                          \
> > +"       xor     %[th],14,%[oh]\n"                          \
> > +"       or.     %[th],%[th],%[tl]\n"                               \
> > +"       bne-    2f\n"                                              \
> > +"       mr      17,%[nl]\n"                                        \
> > +"       mr      16,%[nh]\n"                                        \
> > +"       stqcx.  16,0,%[ptr]\n"                                     \
> > +"       bne-    1b\n"                                              \
> > +   exit_mb                                                 \
> > +"2:     mr      %[rh],14\n"                                        \
> > +"       mr      %[rl],15\n"                                        \
> > +   : [rl] "=&r" (r.low), [rh] "=&r" (r.high),              \
> > +     [tl] "=&r" (tmp.low), [th] "=&r" (tmp.high),          \
> > +     "+m" (*p)                                             \
> > +   : [ptr] "r" (p),                                        \
> > +     [ol] "r" (o.low), [oh] "r" (o.high),                  \
> > +     [nl] "r" (n.low), [nh] "r" (n.high)                   \
> > +   : "r14", "r15", "r16", "r17", "cc", "memory");          \
> 
> Would probably be better to declare some local variable as asm("r14") and
> asm("r15") instead of using clobber, something like:
> 
>   register u64 pair_hi asm("r14");
>   register u64 pair_lo asm("r15");
> 

Makes sense, can add them in the output operands instead of clobber.

> Also, why using non-volatile registers, forcing GCC to save them and restore
> them ? Why not use r10/r11 instead which are volatile ?
> 

I'll make the switch.

> And do we really need r16/r17 at all ? Can't we reuse the same pair as lqarx
> ?
> 

Did you mean reuse tl/th or r14/r15 for stqcx.? tl/th might not be consecutive
even/odd pairs and r14/r15 contains the value from lqarx that we have to return.

--Nysal
> > +                                                           \
> > +   return r.full;                                          \
> > +}
> > +#endif
> >   __CMPXCHG128(, PPC_ATOMIC_ENTRY_BARRIER, PPC_ATOMIC_EXIT_BARRIER)
> >   __CMPXCHG128(_local, ,)
> 

Reply via email to