public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: gcc-help@gcc.gnu.org
Subject: Inline assembly and value extensions
Date: Sat, 22 Aug 2020 16:30:55 +0100	[thread overview]
Message-ID: <8985cc81-573c-b011-4e02-aa9829524133@gigawatt.nl> (raw)

Hi,

I am trying to port some x86-64 inline assembly to work properly for the 
x32 ABI and I am running into a small problem. The x32 ABI specifies 
that pointers are passed and returned zero-extended to 64 bits. When a 
pointer variable is defined by an inline assembly statement and then 
returned by a function, I do not see a way to inform GCC that the result 
is already zero-extended, that GCC does not need to zero-extend it again.

A silly example:

  void *return_a_pointer(void) {
    void *result;
    asm("movl $0x11223344, %%eax" : "=a"(result));
    return result;
  }

This function gets an extra "movl %eax, %eax" between the hand-written 
movl and the generated ret, which can be seen online at 
<https://godbolt.org/z/T8bGPo>. This extra movl is there to ensure the 
high bits of %rax are zero, but the initial movl already achieves that. 
How can I inform GCC that it does not need to emit that extra movl?

Likewise, is there an easy way to provide an inline assembly statement 
with a zero-extended pointer input? This one I am able to work around, 
as it is possible to instead of passing in a pointer value p, pass in an 
integer value (uint64_t)(uint32_t)p, but the workaround is kind of hard 
to read and I would like to avoid that if possible.

I looked the documentation for either relevant inline assembly 
constraints or relevant variable / type attributes, but was unable to 
find any. The most promising search result was the mode attribute, I was 
hoping it might be possible to give result a mode(DI) attribute, but the 
compiler rejects that.

Is there another approach that I can use instead?

Cheers,
Harald van Dijk

             reply	other threads:[~2020-08-22 15:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-22 15:30 Harald van Dijk [this message]
2020-10-03 20:42 ` Harald van Dijk
2020-10-05 12:53   ` Segher Boessenkool
2020-10-05 13:26     ` Harald van Dijk
2020-10-05 13:29       ` Florian Weimer
2020-10-05 13:39         ` Harald van Dijk

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=8985cc81-573c-b011-4e02-aa9829524133@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=gcc-help@gcc.gnu.org \
    /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).