public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Inline assembly and value extensions
@ 2020-08-22 15:30 Harald van Dijk
  2020-10-03 20:42 ` Harald van Dijk
  0 siblings, 1 reply; 6+ messages in thread
From: Harald van Dijk @ 2020-08-22 15:30 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-05 13:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 15:30 Inline assembly and value extensions Harald van Dijk
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

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).