public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: Jeroen Demeyer <jdemeyer@cage.ugent.be>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Inline assembly constraints question
Date: Tue, 19 Aug 2008 16:59:00 -0000	[thread overview]
Message-ID: <m3ej4l7xm2.fsf@google.com> (raw)
In-Reply-To: <48A937FE.30100@cage.ugent.be> (Jeroen Demeyer's message of "Mon\, 18 Aug 2008 10\:51\:10 +0200")

Jeroen Demeyer <jdemeyer@cage.ugent.be> writes:

> I have a C++ program (i386 target) which has a piece of inline
> assembly with the following constraints:
>
> asm(/* Some asm code */
>     : "=&rm" (n0), "=&r" (n1), "=&r" (n2)
>     : "2" (n0), "1" (n1), "g" (n2), "cI" (s)
> );
>
> When compiled with g++ 4.1.2 (CXXFLAGS=-O2 -march=pentium4) the
> operands %0 and %5 get the same memory address, even though they refer
> to distinct variables (n0 and n2).  So, is this a bug in g++ 4.1.2 or
> am I doing something wrong?   g++ 3.4.6 and g++ 4.3.1 generate correct
> code, but that does not really prove anything.

It would help to see the types of the variables.  Is n2 a pointer?
Also it would help to see the actual values that wind up getting
passed in.

With "=%rm" you are telling gcc that it is OK to pass a memory
address.  And "g" accepts any operand.  That gives gcc a lot of
flexibility.  If it does wind up passing in a memory operand for both,
though, it seems to me that they should not overlap.

I think more details would help.  For example, run gcc with the -dg
option, look at FILENAME.xxx.greg, and show us the insn corresponding
to the asm statement.


> In particular I would like to know:
> 1) Is it allowed to put matching (digit) constraints referring to
> different variables?  This is what I do with %2.  The same register is
> used as input for  variable n0 and as output for variable n2.

Yes, that is fine.

> 2) Is there a way to specify some kind of 'earlyclobber' (&) modifier
> with a memory constraint?  How can I prevent gcc from putting an input
> variable and an unrelated output variable in the same memory location?

The simple way is to force one or both of them into registers.

Ian

  reply	other threads:[~2008-08-19 16:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-18 10:34 Jeroen Demeyer
2008-08-19 16:59 ` Ian Lance Taylor [this message]
2008-08-20 13:47   ` Jeroen Demeyer
2008-08-20 19:31     ` Ian Lance Taylor

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=m3ej4l7xm2.fsf@google.com \
    --to=iant@google.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jdemeyer@cage.ugent.be \
    /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).