On Mon, 30 Nov 2026 18:58:11 +0100
"Christophe Leroy (CS GROUP)" <[email protected]> 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
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


Reply via email to