lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] Order of function arguments on mips


From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] Order of function arguments on mips
Date: Wed, 20 Oct 2010 05:35:29 -0200

Em 20 de outubro de 2010 04:32, Paolo Bonzini <address@hidden> escreveu:
> On 10/20/2010 02:32 AM, Paulo César Pereira de Andrade wrote:
>>
>>   What you suggest to avoid minimal problems with lightning?
>>
>> _jit_prepare("dfii")
>> to be understood as:
>> <unkown_return_type>  function(double, float, int, int);
>
> While it is a bit long, maybe
>
>  jit_prepare_d(1);
>  jit_prepare_f(1);
>  jit_prepare_i(2);
>
> would "just work"?

  If there are no jit_pusharg calls in between, it could be an
option.

  Hopefully to have it easier to understand... an example, like
a minimal version of varargs.tst, that does sscanf and sprintf
calls with interleaved ints and doubles (not a problem for sscanf
ofcourse):

printf("%f %d %f %d\n", 1.0, 2, 3.0, 4);

    prepare 3
    prepare_d 2
        movi_i %r0 4
        pusharg_i %r0
        movi_d %f0 3.0
        pusharg_d %f0
        movi_i %r0 2
        pusharg_i %r0
        movi_d %f0 1.0
        pusharg_d %f0
        movi_p %r0 format
        pusharg_p %r0
    finish @printf

$a0: format
$a1 <- must skip this register
f$12+$f13<- must skip $f12 because pointer goes in $a0 and $f13 to "align"
$sp[0-15] <- skiped stack offsets as up to 4 32 bit arguments go on registers
$a2+$a3 (and $f14+$f15 because does not know if has prototype) "1.0" argument
$sp[16-19] "2" argument
$sp[20-23] <- must skip to align next double
$sp[24-31] "3.0" argument
$sp[32-35] "4" argument
$sp[35-39] <- not used, but exist to ensure stack is 8 bytes aligned

registers used for arguments are $a0,$a1,$a2,$a3 and if with prototype floats
go in $f12,$f13,$f14,$f15

  The problem in the above is that it will skip 1 register to align to the
next register pair, and then, need to add another gap in the stack to
adjust again.

  Most of my knowledge of the abi is from checking objdump from
small C programs...

  I am using the logic I implemented as optional logic with patching
stack alignment on jit_prolog, so, writing to $sp[anything] does not
need patching, but, this is a case where it not only could need patching,
it could need changing the instruction, and keeping information about
all arguments, to push arguments in reverse order (at least instructions
are fixed size, and if not allowing more than 32kb of arguments,
can be patched and change instruction if required...)

  The most obvious solution should be to have some kind of description
of all arguments before the first pusharg (like my suggestion of a format
string, that was the first thing that came to my mind), otherwise, either
assume the user does always push a double with stack aligned, or write
some very complex logic.

> Paolo

Paulo



reply via email to

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