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