lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] Re: About using lightning on a dynamically typed langua


From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] Re: About using lightning on a dynamically typed language
Date: Thu, 27 May 2010 17:43:53 -0300
User-agent: SquirrelMail/1.4.19

Ludovic Courtès wrote:
> Hi,
>
> Paolo Bonzini <address@hidden> writes:

  I started reworking my vm to add "super instructions", but, diminishing
returns hit too early, and the code becomes a nightmare, so, I am going
to plan B :-)

  The idea is to create several small C functions, for most opcodes, so
that I don't need to (or should not) bother with c99 complex numbers,
tls variables, etc from the jit code, only from the small "callbacks".
Example:
  ld a
  push
  ld b
  add
becomes somewhat like:
-%<-
void vm_load(int i) {
    thread->r = thead->bp[i];
}
void vm_push(void) {
    *thread->sp++ = thread->r;
}
void vm_add(void) {
    thread->r = *--thread->sp + thread->r;
}
-%<-
where thread is a "__thread" global variable, and this is a minimal
example, but should be more complex, due to dynamic type checking, etc.

and the jit generation is somewhat like:
...
  case LOAD:
    ++program;
    jit_prepare(1);
      jit_pusharg_i(*program);
    jit_finish(vm_load);
    break;
...
  case ADD:
    jit_prepare(0);
    jit_finish(vm_add);   /* probably just jit_calli need to check :-) */
    break;
...

  Since the language supports static typing, as a hint for optimizing
loop counters, etc, those can generate better jit code also.

>>>  I understand that it may make it significantly hard to implement as
>>> pure jit, but I was wondering how/if it could be made in a way where
>>> it kind of "cut&paste" blocks of compiled code
>>
>> People tried that but it's very difficult as more optimizations were
>> added to modern GCC. lightning could be used to cut&paste those blocks
>> after you converted them from C to lightning's pseudo-assembly.
>
> I tried something along these lines in the past:
>
>   http://lists.gnu.org/archive/html/lightning/2005-09/msg00000.html
>   
> http://git.savannah.gnu.org/cgit/libchop.git/tree/src/chopper-anchor-based.c#n294

  The concept I am considering will require indirect jumps in jit.
But my tests did not show any difference in a loop with code like:

#if 1
                forward = jit_beqi_ui(jit_forward(), JIT_R0, 0);
                jit_ldi_p(JIT_R1, &labels[program - base + *program]);
                jit_jmpr(JIT_R1);
                jit_patch(forward);
#else
                jit_bnei_ui(labels[program - base + *program], JIT_R0, 0);
#endif

running a few million iterations, but this may not be a good test,
as the address is very predictable in this small test...

  I will need indirect jumps for implementation of 'switch', but the
most important should be because it should generate all the vm code
in a single chunk, so, when starting a new thread, it must do an
indirect jump to the start of thread function.
  Also, try/catch becomes almost trivial with indirect jumps when the
code is in a single chunk. Only limitation is that it will not allow,
at least not easily, to dynamically load some kind of module, but this
was intended since start... i.e. all code/data must be resolved at parse
time.

> It wasn’t conclusive.
>
> Thanks,
> Ludo’.

Paulo




reply via email to

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