Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg
From: Christophe Leroy (CS GROUP)
Date: Wed Dec 02 2026 - 05:13:38 EST
Le 02/12/2026 à 10:57, David Laight a écrit :
On Mon, 30 Nov 2026 18:58:11 +0100
"Christophe Leroy (CS GROUP)" <chleroy@xxxxxxxxxx> 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.
David
Christophe