public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Kalamatee <kalamatee@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Problem understand optimization with inline asm
Date: Tue, 28 Mar 2023 17:45:45 -0500	[thread overview]
Message-ID: <20230328224545.GN25951@gate.crashing.org> (raw)
In-Reply-To: <CAJWNc-62ebOfM6E=z8H9h3vE=+qfss2kidaHpWH3usWLSO9iuA@mail.gmail.com>

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

      parent reply	other threads:[~2023-03-28 22:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 11:15 Kalamatee
2023-03-28 11:41 ` Andrew Haley
2023-03-28 11:44   ` Andrew Haley
2023-03-28 22:45 ` Segher Boessenkool [this message]

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=20230328224545.GN25951@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=gcc-help@gcc.gnu.org \
    --cc=kalamatee@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).