Re: [PATCH 1/7] Fix function argument and return value locations

Hannes Domani
2020-05-25T23:03:07Z

Am Dienstag, 26. Mai 2020, 00:14:36 MESZ hat Simon Marchi <simark@simark.ca> Folgendes geschrieben:

> On 2020-05-25 5:32 p.m., Hannes Domani via Gdb-patches wrote:
> > You're probably right, the thing is, I was only able to test complex float
> > and complex double, because gdb doesn't like complex integral types:
> >
> > complex int complex_int = 5 + 6i;
> >
> > (gdb) p complex_int
> > 'complex_int' has unknown type; cast it to its declared type
> > (gdb) pt complex_int
> > 'complex_int' has unknown type; cast it to its declared type
> >
> > So I guess it should check for target-type float as well:
> >        || (type->code () == TYPE_CODE_COMPLEX
> >            && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_FLT))
> >
> > Do many people use complex int, because I personally wouldn't have expected
> > that this even exists.
>
> Err right that doesn't make sense, let's use floats instead.  I see:
>
>
> $ cat hello.c
> #include <complex.h>
>
> void other(float real, float imag);
> void func (complex float n)
> {
>   other(creal(n), cimag(n));
> }
> $ x86_64-w64-mingw32-gcc hello.c -g3 -O0 -c
> $ x86_64-w64-mingw32-objdump -d hello.o
>
> hello.o:    file format pe-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <func>:
>   0:  55                      push  %rbp
>   1:  48 89 e5                mov    %rsp,%rbp
>   4:  48 83 ec 20            sub    $0x20,%rsp
>   8:  48 89 4d 10            mov    %rcx,0x10(%rbp)
>   c:  f3 0f 10 45 14          movss  0x14(%rbp),%xmm0
>   11:  f3 0f 5a c0            cvtss2sd %xmm0,%xmm0
>   15:  f2 0f 5a c8            cvtsd2ss %xmm0,%xmm1
>   19:  f3 0f 10 45 10          movss  0x10(%rbp),%xmm0
>   1e:  f3 0f 5a c0            cvtss2sd %xmm0,%xmm0
>   22:  f2 0f 5a c0            cvtsd2ss %xmm0,%xmm0
>   26:  e8 00 00 00 00          callq  2b <func+0x2b>
>   2b:  90                      nop
>   2c:  48 83 c4 20            add    $0x20,%rsp
>   30:  5d                      pop    %rbp
>   31:  c3                      retq
>
> Doesn't this suggest that the parameter gets passed through rcx?  I'm not saying you
> are wrong, I'm just trying to understand how things work :).

You're absolutely right again.
The complex arguments didn't work before, so I just tried it with
amd64_windows_passed_by_xmm_register (because that seemed the obvious choice
for me), and then it worked.

But it only worked because in case of XMM register, the argument is also
passed via the integer register:

else if (amd64_windows_passed_by_xmm_register (type))
{
amd64_windows_store_arg_in_reg
(regcache, args[i], AMD64_XMM0_REGNUM + reg_idx);
/* In case of varargs, these parameters must also be
passed via the integer registers.  */
amd64_windows_store_arg_in_reg
(regcache, args[i],
amd64_windows_dummy_call_integer_regs[reg_idx]);
on_stack_p = 0;
reg_idx++;
}

So it actually should be added to amd64_windows_passed_by_integer_register,
and a quick test just now confirms that this also works.

I'm very sorry about that, I should have checked the asm code.

Hannes