[Top][All Lists]

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

[Lightning] Re: Some questions about minor changes

From: Paulo César Pereira de Andrade
Subject: [Lightning] Re: Some questions about minor changes
Date: Fri, 24 Sep 2010 17:20:13 -0300

Em 24 de setembro de 2010 07:10, Paulo César Pereira de Andrade
<address@hidden> escreveu:
> Em 24 de setembro de 2010 06:49, Paulo César Pereira de Andrade
> <address@hidden> escreveu:
>> Em 24 de setembro de 2010 05:54, Paolo Bonzini <address@hidden> escreveu:
>>> On 09/24/2010 10:16 AM, Paulo César Pereira de Andrade wrote:
>  Sorry for replying to myself...


>>> Can you explain exactly why?
>>  Example of calling a function:
>> prepare 7           <- use 6 gp registers and 1 stack slot
>> prepare_f 3        <- use 3 fp registers
>> prepare_d 9       <- use 5 remaining fp registers and 4 stack slots
>> <<pusharg>>
>> finish function
>> in the first pusharg, it must first pad the stack to align it to 16 bytes,
>> but if the number of stack slots is even, it does not need.
>  And this is actually bogus in the current code, because it should actually
> check for "_jitl.argssize&1" after jit_prolog, jit_prolog_f or jit_prolog_d,
> and pad the stack in the first instruction after those. Without any
> extra changes, it could require an add/sub in the 3 of the above.
> The worst case would be odd integer count in jit_prolog requring a
> "sub 8,%rsp", and then a jit_prolog_d with an odd double count follows,
> and need to "add 8,%rsp", and to make things worse, a jit_prolog_f with
> an odd float count could follow...

  I did a slightly different approach to avoid the need of an api change,
or worse, the need of a (compile time enabled) check before any
jit_xyz call. But it means there are some rules:

o must call jit_arg_x()  for the first received argument, and after calls to
  jit_prolog, jit_prolog_f() and/or jit_prolog_d(), so that it will adjust the
  stack if required
o jit_allocai() should only be called after acknowledging at least one
  argument with jit_arg_x(), otherwise, if there is an odd number of
  arguments, it may misalign the stack
o jit_arg_x() and jit_allocai() cannot be in a branch, i.e. cannot be called
o jit_getarg_x() can be called at any moment, but of course, if receiving
  arguments in registers, must be called before doing a function call

  Previous and somewhat extend rules still apply:
o jit_prolog must be called only once per function, no nested functions
  allowed, it should be called even if receiving zero integer arguments,
  because it must know that it did not receive any arguments, or there
  may be data from a previous jit_prolog there.
o jit_prepare/jit_pusharg_x,jit_finish cannot nest

  Compile time enabled test can be added to generate a runtime assertion.
In jit_prolog, could generate something like:
    jit_andi_i(JIT_R0, JIT_SP, 15);
    stack_is_aligned = jit_beqi_i(jit_forward(), JIT_R0, 0);
and I will probably add this, or a variant, for the tests, but not enabled
even for _ASM_SAFETY.

  The only way to remove some of these limitations would be to store
the code in some intermediate representation, and work on this data
just before jit_flush(), e.g. a peephole optimizer, rework push/pop, etc,
but that should not be done in lightning itself, but I am still working on,
and trying to figure the best way to have external code, somewhat like
a plugin being able to do it...


reply via email to

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