Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg
From: David Laight
Date: Tue Dec 01 2026 - 12:09:56 EST
On Tue, 1 Dec 2026 14:58:31 +0000
David Laight <david.laight.linux@xxxxxxxxx> wrote:
> On Tue, 1 Dec 2026 14:48:04 +0000
> David Laight <david.laight.linux@xxxxxxxxx> wrote:
>
> > On Tue, 1 Dec 2026 19:22:06 +0530
> > "Nysal Jan K.A." <nysal@xxxxxxxxxxxxx> wrote:
> >
> > > On Thu, Nov 26, 2026 at 11:27:14AM +0000, David Laight wrote:
> > > > On Wed, 25 Nov 2026 23:10:22 +0530
> > > > "Nysal Jan K.A." <nysal@xxxxxxxxxxxxx> wrote:
> > > >
> > > > >
> > > > > +#ifdef CONFIG_HAVE_CMPXCHG_DOUBLE
> > > > > +union __u128_halves {
> > > > > + u128 full __mode(PTI);
> > > > > + struct {
> > > > > + u64 low, high;
> > > >
> > > > There seems to be a mismatch between the register order that PTI
> > > > assigns and the one that C uses.
> > > > It might be less confusing to swap low and high in the above
> > > > and only use 'full' (probably renamed) in the asm statement.
> > > >
> > >
> > > I can swap high and low here to indicate that it maps to the big-endian
> > > register layout if that makes it less confusing.
> >
> > But AFICT it doesn't (if I believe the AI from google for "ppc64le lq word order".
> > The high bits (from EA + 8) end up in the even register and the low bits
> > (from EA) in the odd register.
>
> But that doesn't match a test I just did on godbolt.
> If the order is backwards then you do need to swap low and high
> and only use 'full' (aka full_partially_be) for the asm constraint.
I'm getting more confused. I don't have a cpu to test this on either.
The above AI says you can do (reg + reg), but godbolt's gcc 16.2.0
will only assemble (reg + const*16).
See https://www.godbolt.org/z/KParbvPa7
(and fiddle with what is assigned to [v])
I also found this comment in a patch to qemu:
+ /* Note that the low part is always in RD+1, even in LE mode. */
+ lo = cpu_gpr[rd + 1];
+ hi = cpu_gpr[rd];
So it might be that gcc is actually getting it wrong.
Needs testing on a physical cpu.
David
>
> David
>
> >
> > I suspect (as in the other email I just sent) that when you do:
> > u128 x;
> >
> > asm(... : "=r" (x))
> > you are getting the register that holds the low bits of 'x'.
> > But you want the one containing the high bits so that you can use L[]
> > to reference the low bits.
> > The code might appear to work because on a function call the lower
> > register contains the low bits; so, if the register isn't reused,
> > L[x] will be the high bits.
> >
> > You might be able to tell which registers gcc thinks are 'live'
> > by adding one to the clobber list.
> > You can't add one that is in use; so it should force an alternative
> > register allocation.
> >
> > David
> >
> >
> >
>