Re: Problem understand optimization with inline asm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On Tue, Mar 28, 2023 at 12:15:37PM +0100, Kalamatee via Gcc-help wrote:
> Now, I can work around this by using "+" (even though I don't read the
> variable), or initializing the value a second time in the asm block - but
> should I have to? This sounds like the compiler is doing the wrong thing
> based on the assertion/assumption "=" means I will 100% change some
> variable,

Yes, that is what an output contraint means.  From the manual:

  '='
       Means that this operand is written to by this instruction: the
       previous value is discarded and replaced by new data.

If you use "+" it will mean exactly what you want.  "+" means "both an
input and an output operand".

  '+'
       Means that this operand is both read and written by the
       instruction.

If you want the asm to have semantics like
  if (cond)
    x = y;
this can be equivalently written as
  if (cond)
    x = y;
  else
    x = x;
or maybe even
  x = (cond) ? y : x;
and written that way it is clear you really want an in/out constraint
here :-)

HtH,


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux