Re: Specifying different registers in inline asm

Segher Boessenkool <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <aR3MojMW9A4VZO_G@gate>
Hi!

On Wed, Nov 19, 2025 at 09:03:53AM +0100, [email protected] wrote:
> Le 2025-11-18 18:10, Segher Boessenkool a écrit :
> > The first copy it into a variable that *is* writable?  This is required
> > for correctness, since your asm *does* modify the reg!
> I'm not sure about this situation, for me there are two sides on this
> matter: a practical one and a theoretical one.
> On the practical side, the instruction does a write back to the register,
> but with the same value

Then, as far as the compiler is concerned, you did *not* write it at
all.  There is no way to see the difference, anyway -- "memory refresh"
is not modeled at all either.

> (because omission of the offset is equal to 0 in
> this instance), so the register does not change value.
> On a theoretical side, I would like to tell the compiler that the register
> is clobbered, that I don't care about the value anymore, but that if the
> compiler needs the value, it cannot rely on the fact that the register still
> contains it. I think it is not possible to specify clobbers for input
> values, but it makes sense to be able to use a non-lvalue here, so I don't
> want to specify it as an output. Is this doable?

A clobber is a write with an unknown value (by definition), so it can
only ever happen to something writable, so an lvalue if modeled in C.

In inline asm you have output operands, input operands, and a clobber
list.  The clobber list cannot validly intersect the output operands
(if it would, you are describing some register is wriiten *twice*,
atomically).

> > > > > destination and the address register should be different (as helpfully
> > > > > mentioned by the assembler: "destination register same as write-back
> > > > > base").
> > > > > The code generator produces "LDRBT R3, [R3]" which is not correct.
> > > > > I would like to specify that I want two distinct registers for %0
> > > > > and %1 (my
> > > > > code is LDRBT %0, [%1]), but I did not find how.
> > > >
> > > > If you want literally what you ask for (but read above), what you want
> > > > is an "earlyclobber".  Written as "&", see the manual.
> > > >
> > > Thank you very much, it is so obviously described, once you know
> > > where to
> > > look.
> > 
> > As always :-)
> > 
> > One thing you can try is "read everything".  I've been trying to do that
> > forever now, and am still not done, but making some progress I hope ;-)
> Nah, the real method is to "read everything an infinite number of times",
> because on each pass you understand something that you have read before, but
> which did not click into place. But as everyone knows eternity is very long,
> especially towards the end.

There are only finitely many (but many) things described in the manual,
so you can read everything by just reading it a finite number of times.
Remembering it can be more tricky of course :-)


Segher
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.