public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Andrew Haley <aph@redhat.com>
Cc: Zdenek Sojka <zsojka@seznam.cz>, gcc-help@gcc.gnu.org
Subject: Re: [x86 inline asm]: width of register arguments
Date: Tue, 02 Jul 2019 15:19:00 -0000	[thread overview]
Message-ID: <20190702151858.GM18316@gate.crashing.org> (raw)
In-Reply-To: <c02cb21c-7b80-3493-72c9-8eb659ab1c95@redhat.com>

On Tue, Jul 02, 2019 at 11:41:35AM +0100, Andrew Haley wrote:
> On 7/2/19 6:37 AM, Zdenek Sojka wrote:
> > Ok, shame - it seems to behave so in my experiments:
> 
> It's more complicated than that. Sometimes the size of the operand is
> in the name of the instruction and sometimes you need to force the
> size yourself.

You also need to consider the mode that is used for the variables.

> For example, with int a, x:
> 
>   asm("mov %1, %0" : "=&r"(a) : "r"(x));
> 
> generates
> 
> 	mov %edx, %eax

and with "short a, x" you get %ax and %dx, and with "char a, x" you get
%al and %dl without needing the %b output modifier.

> I'm a bit paranoid about this stuff because my memory of GCC's inline
> asm goes back decades to when it was far more fragile than it is now.

Oh it still is quite fragile / does unexpected things whenever you try
anything out of the ordinary.  For example, operands do not get the
usual integer promotions, as the example above shows: operands are
treated like lvalues instead, input operands as well.

If you know what mode is used for every operand you use in asm, and/or
you just use operands that are full register size, there aren't many
surprises.

Things get even more interesting if you use multi-register modes, like
DImode with -m32 on x86.  On x86 that says "warning: unsupported size
for integer register", but some other targets have to handle that.
Writing correct asm in such cases of course means that you have to know
what the compiler does.


Segher

  reply	other threads:[~2019-07-02 15:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24 12:19 Zdenek Sojka
2019-06-29 16:10 ` Andrew Haley
2019-07-02  5:37   ` Zdenek Sojka
2019-07-02 10:41     ` Andrew Haley
2019-07-02 15:19       ` Segher Boessenkool [this message]
2019-07-03  7:32         ` Zdenek Sojka
2019-07-03 13:57           ` Segher Boessenkool

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=20190702151858.GM18316@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=aph@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=zsojka@seznam.cz \
    /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).