tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] x86_64 ABI: mixed structs


From: Pip Cet
Subject: Re: [Tinycc-devel] x86_64 ABI: mixed structs
Date: Sun, 26 Apr 2015 17:27:02 +0000

Okay, here's a first patch that fixes the problem (but I've found
another bug, yet unfixed, in the process), though it's not
particularly pretty code (I tried hard to keep the changes to the
minimum necessary). If we decide to actually get rid of VT_QLONG and
VT_QFLOAT (please, can we?), there are some further simplifications in
tccgen.c that might offset some of the cost of this patch.

The idea is that an integer is no longer enough to describe how an
argument is stored in registers. There are a number of possibilities
(none, integer register, two integer registers, float register, two
float registers, integer register plus float register, float register
plus integer register), and instead of enumerating them I've
introduced a RegArgs type that stores the offsets for each of our
registers (for the other architectures, it's simply an int specifying
the number of registers). If someone strongly prefers an enum, we
could do that instead, but I believe this is a place where keeping
things general is worth it, because this way it should be doable to
add SSE or AVX support.

There is one line in the patch that looks suspicious:

             } else {
                 addr = (addr + align - 1) & -align;
                 param_addr = addr;
                 addr += size;
-                sse_param_index += reg_count;
             }
             break;

However, this actually fixes one half of a bug we have when calling a
function with eight double arguments "interrupted" by a two-double
structure after the seventh double argument:

f(double,double,double,double,double,double,double,struct { double
x,y; },double);

In this case, the last argument should be passed in %xmm7. This patch
fixes the problem in gfunc_prolog, but not the corresponding problem
in gfunc_call, which I'll try tackling next.

On Sat, Apr 25, 2015 at 7:09 PM, Pip Cet <address@hidden> wrote:
> I've just committed two tests for the x86_64 ELF ABI which currently
> fail, because we don't deal properly with mixed structures along the
> lines of
>
> struct {
>     double x;
>     long y;
> };
>
> Such structs should be split and passed in an SSE register plus an
> integer register, which the current approach, assigning VT_QFLOAT or
> VT_QLONG as structure type, fails to deal with.
>
> I think I've got most of what's needed for a fix here, but the change
> involves rewriting a little of the x86_64 code; a less intrusive fix
> would be preferred, I think.
>
> I'll try isolating this from my other changes and coming up with a patch.

Attachment: tcc-fix-mixed-structs.diff
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]