From: "Nysal Jan K.A." <nysal@linux.ibm.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org,
Jeevitha Palanisamy <jeevitha@linux.ibm.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
"David Hildenbrand (Arm)" <david@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Andreas Larsson <andreas@gaisler.com>,
Usama Arif <usama.arif@linux.dev>,
Kevin Brodsky <kevin.brodsky@arm.com>,
"Kiryl Shutsemau (Meta)" <kas@kernel.org>,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg
Date: Tue, 1 Dec 2026 19:22:06 +0530 [thread overview]
Message-ID: <aw7LJHdBGG1IOY5S@li-398ad3cc-28e7-11b2-a85c-e030a5b10d54.ibm.com> (raw)
In-Reply-To: <20261126112714.021a3e66@pumpkin>
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@linux.ibm.com> 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.
> > + };
> > +};
> > +
> > +#define __CMPXCHG128(name, entry_mb, exit_mb) \
> > +static __always_inline u128 \
> > +__cmpxchg_u128##name(volatile u128 *p, u128 old, u128 new) \
> > +{ \
> > + union __u128_halves tmp, r, o = { .full = (old) }; \
>
> You don't need 'o' in a register pair, it might be better
> to just have two u64 for the two halves.
>
I'll make this change in v2.
> > + \
> > + __asm__ __volatile__ ( \
> > + entry_mb \
> > +"1: lqarx %[r],0,%[ptr]\n" \
> > +" xor %L[t],%L[r],%[ol]\n" \
> > +" xor %[t],%[r],%[oh]\n" \
> > +" or. %[t],%[t],%L[t]\n" \
> > +" bne- 2f\n" \
> > +" mr %L[t],%[n]\n" \
> > +" mr %[t],%L[n]\n" \
> > +" stqcx. %[t],0,%[ptr]\n" \
> > +" bne- 1b\n" \
> > + exit_mb \
> > +"2: mr %[t],%[r]\n" \
> > +" mr %[r],%L[r]\n" \
> > +" mr %L[r],%[t]\n" \
>
> If you leave this exchange to the C code it will likely get
> optimised away.
>
I tried it out on godbolt and it does indeed look better.
> The same is true for the fallback code in the next patch
> where you can use asm("r14") and asm("r15) for the two halves
> of 'r' and then combine them with arithmetic for the return.
>
Makes sense.
> This would all be more readable with slightly longer variable names.
>
> I'm sure the above and the fallback code could be made similar
> enough to avoid the duplication.
>
There were some differences between both paths, I'll see if this is possible.
Thanks for the review.
--Nysal
next prev parent reply other threads:[~2026-12-01 13:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:40 [PATCH 0/3] powerpc: Implement cmpxchg128() Nysal Jan K.A.
2026-11-25 17:40 ` [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg Nysal Jan K.A.
2026-11-25 20:44 ` Nathan Chancellor
2026-11-26 10:12 ` Nysal Jan K.A.
2026-11-26 11:27 ` David Laight
2026-12-01 13:52 ` Nysal Jan K.A. [this message]
2026-11-30 17:58 ` Christophe Leroy (CS GROUP)
2026-11-30 22:01 ` David Laight
2026-12-01 10:34 ` David Laight
2026-12-01 12:52 ` Nysal Jan K.A.
2026-11-25 17:40 ` [PATCH 2/3] powerpc: Implement 128-bit cmpxchg fallback Nysal Jan K.A.
2026-11-30 18:55 ` Christophe Leroy (CS GROUP)
2026-12-01 13:25 ` Nysal Jan K.A.
2026-11-25 17:40 ` [PATCH 3/3] powerpc: Enable lbarx/lharx for Power10 Nysal Jan K.A.
2026-11-25 17:51 ` [PATCH 0/3] powerpc: Implement cmpxchg128() Nick Desaulniers
2026-11-26 10:07 ` Nysal Jan K.A.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aw7LJHdBGG1IOY5S@li-398ad3cc-28e7-11b2-a85c-e030a5b10d54.ibm.com \
--to=nysal@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andreas@gaisler.com \
--cc=chleroy@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=david@kernel.org \
--cc=jeevitha@linux.ibm.com \
--cc=justinstitt@google.com \
--cc=kas@kernel.org \
--cc=kevin.brodsky@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=llvm@lists.linux.dev \
--cc=maddy@linux.ibm.com \
--cc=morbo@google.com \
--cc=mpe@ellerman.id.au \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=npiggin@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=sshegde@linux.ibm.com \
--cc=usama.arif@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®