From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: "Nysal Jan K.A." <nysal@linux.ibm.com>,
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>,
"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: Wed, 2 Dec 2026 12:01:54 +0100 [thread overview]
Message-ID: <4c1987da-92ea-40bd-82c4-22cbd1cd4dcf@kernel.org> (raw)
In-Reply-To: <2b03573f-da09-479c-a87d-6ac41737caa8@kernel.org>
Le 02/12/2026 à 11:13, Christophe Leroy (CS GROUP) a écrit :
>
>
> Le 02/12/2026 à 10:57, David Laight a écrit :
>> On Mon, 30 Nov 2026 18:58:11 +0100
>> "Christophe Leroy (CS GROUP)" <chleroy@kernel.org> wrote:
>>
>>> Why a memory clobber ? Is it to get a barrier ? Otherwise I see no
>>> direct hidden memory modification in the sequence.
>>
>> I found something horrid during testing:
>> The compiler (gcc) will spill the value of a memory operand to stack.
>> So:
>> long f(long *p)
>> {
>> register long x asm("r3");
>>
>> asm( "opcode %[x],%[p]" : [x] "=&r" (x) : [p] "m" (*p));
>> return x;
>> }
>> compiles to:
>> f:
>> ld 9,0(3)
>> std 9,-16(1)
>> ori 2,2,0
>> opcode 3,-16(1)
>> blr
>
> What 'opcode' is that ? Because powerpc is a RISC processor, there is no
> way ALU operation can operate on something else than registers.
>
> With xor as opcode I get:
>
> 11 .previous
> 12 .type f, @function
> 13 .L.f:
> 14 .LFB0:
> 15 ???? 00000010 .cfi_startproc
> 15 00000000
> 15 017A5200
> 15 04784101
> 15 1B0C0100
> 16 ???? E9230000 ld 9,0(3)
> 17 ???? F921FFF0 std 9,-16(1)
> 18 ???? 60420000 ori 2,2,0
> 19 #APP
> 20 # 5 "toto.c" 1
> 21 ???? 7E030278 xor 3,-16(1)
> **** Error: operand out of range (-16 is not between 0 and 31)
> **** Error: syntax error; found `(', expected `,'
> 22 # 0 "" 2
> 23 #NO_APP
> 24 ???? 4E800020 blr
>
>
>> That really isn't what was intended.
>> (I suspect it can also to the same for an output.)
>> The only way I can see to avoid that is to explicitly pass the address
>> in a register and use a memory clobber.
>>
>> I wonder how much asm assumes a "m" operand references the
>> 'obvious' memory area.
>>
>> I'm not sure what the 'ori 2,2,0' is for.
>> I also tried casting the pointer to a struct with a 'char x[]'
>> member - that generated an ICE when it tried to copy it.
>> Using volatile makes no difference.
>>
Wondering what you intent to do exactly. Isn't is something like:
long f(long *p)
{
register long x asm("r3");
asm( "xor %[x],%[p],%[p]" : [x] "=&r" (x) : [p] "r" (*p));
return x;
}
Which gives
0000000000005460 <f>:
5460: 00 00 23 e9 ld r9,0(r3)
5464: 78 4a 23 7d xor r3,r9,r9
5468: 20 00 80 4e blr
Christophe
next prev parent reply other threads:[~2026-12-02 11:02 UTC|newest]
Thread overview: 24+ 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.
2026-12-01 14:48 ` David Laight
2026-12-01 14:58 ` David Laight
2026-12-01 17:09 ` David Laight
2026-12-01 22:20 ` David Laight
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-12-01 14:34 ` David Laight
2026-12-02 9:57 ` David Laight
2026-12-02 10:13 ` Christophe Leroy (CS GROUP)
2026-12-02 11:01 ` Christophe Leroy (CS GROUP) [this message]
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=4c1987da-92ea-40bd-82c4-22cbd1cd4dcf@kernel.org \
--to=chleroy@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andreas@gaisler.com \
--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=nysal@linux.ibm.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