[Top][All Lists]

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

Re: [Lightning] RFC: Proposal for lightning 2.0

From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] RFC: Proposal for lightning 2.0
Date: Fri, 30 Nov 2012 18:06:32 -0200

2012/11/27 Paolo Bonzini <address@hidden>:
> Il 26/11/2012 21:33, Ludovic Courtès ha scritto:

  Sorry for the delay, I was working on making a "prototype" of
the new code.

  I understand I need to create a lightning 1.0 branch, and that
almost fully overwriting lightning git may not look a good idea,
and this is why I did not commit anything so far...

  The tarball (that may have a short lifetime) is at

>>> >   It needs to be a library mostly due to the IR, with real functions 
>>> > instead
>>> > of all in preprocessor macros, it is easier to write more readable code,
>>> > as well as only export what really is supposed to be visible.
>> I see.  That’s a noticeable change in spirit.
>> It’s probably worth checking what its main “customers” would think,
>> particularly GNU Smalltalk and Racket.
> It's not a problem for me.

  I noticed GNU smalltalk has its own lightning copy as well as Racket.
I am afraid Racket also bypass jit_xyz macros and directly calls backend
macros, I only did overview it, and noticed the calls to (uppercase) macros
in i386/asm.h

> However, another thing I would investigate would be to reuse QEMU's Tiny
> Code Generator as a library.  It supports many backends, and has a
> decent API that is not far from lightning's.

  This for sure should be a very good alternative :-)

  Sample input for the test tool in the "prototype tarball":
$ cat nfibs.tst
.c      "nfibs(%d) = %d\n"

        jmpi main

        arg $in
        getarg_ui %r2 $in       // R2 = n
        movi %r1 1
        blti_u ref %r2 2
        subi %r2 %r2 1
        movi %r0 1
        subi %r2 %r2 1          // decr. counter
        addr %v0 %r0 %r1        // V0 = R0 + R1
        movr %r0 %r1            // R0 = R1
        addi %r1 %v0 1          // R1 = V0 + 1
        bnei loop %r2 0         // if (R2) goto loop
        movr %ret %r1           // RET = R1

        arg $argc
        arg $argv

        getarg_i %r0 $argc
        blei default %r0 1
        getarg %r0 $argv
        addi %r0 %r0 $(__WORDSIZE >> 3)
        ldr %r0 %r0
        prepare 0
                pushargr %r0
        finishi @atoi
        retval %r0
        jmpi call

        movi %r0 36

        movr %v0 %r0
        prepare 0
                pushargr %r0
        finishi nfibs
        retval %r0
        prepare 1
                pushargr %r0
                pushargr %v0
                movi %r0 format
                pushargr %r0
        finishi @printf

and sample execution output:
$ ./lightning nfibs.tst

    jmpi L5
L1: %r10 %rdi
        extr_ui %r11 %rdi
        movi %r10 0x1
    blti_u L3 %r11 0x2
        subi %r11 %r11 0x1
        movi %rax 0x1
L2: %rax %r10
        subi %r11 %r11 0x1
        addr %rbx %rax %r10
        movr %rax %r10
        addi %r10 %rbx 0x1
    bnei L2 %r11 0x0
L3: %r10
        movr %rax %r10
L6: %rsi %rdi
        extr_i %rax %rdi
    blei L7 %rax 0x1
        movr %rax %rsi
        addi %rax %rax 0x8
        ldr_l %rax %rax
        movr %rdi %rax
        movi %rax 0x3801437230
    callr %rax
    jmpi L8
        movi %rax 0x24
L8: %rax
        movr %rbx %rax
        movr %rdi %rax
        movi %rax 0x5047310
    callr %rax
        movr %rdi %rax
        movr %rsi %rbx
        movi %rax 0x0
        movr %rdx %rax
        movi %r10 0x38014513f0
    callr %r10
         0x5432000      jmpq   0x5432068
         0x5432005      nopl   (%rax)
         0x5432008      sub    $0x30,%rsp
         0x543200c      mov    %rbx,0x28(%rsp)
         0x5432011      mov    %rbp,(%rsp)
         0x5432015      mov    %rsp,%rbp
         0x5432018      sub    $0x8,%rsp
         0x543201c      mov    %ebx,%r15d
         0x543201f      mov    $0x1,%r10d
         0x5432025      cmp    $0x2,%r11
         0x5432029      jb     0x5432050
         0x543202f      sub    $0x1,%r11
         0x5432033      mov    $0x1,%eax
         0x5432038      sub    $0x1,%r11
         0x543203c      lea    (%rax,%r10,1),%rbx
         0x5432040      mov    %r10,%rax
         0x5432043      lea    0x1(%rbx),%r10
         0x5432047      test   %r11,%r11
         0x543204a      jne    0x5432038
         0x5432050      mov    %r10,%rax
         0x5432053      mov    %rbp,%rsp
         0x5432056      mov    0x28(%rsp),%rbx
         0x543205b      mov    (%rsp),%rbp
         0x543205f      add    $0x30,%rsp
         0x5432063      retq
         0x5432064      nopl   0x0(%rax)
         0x5432068      sub    $0x30,%rsp
         0x543206c      mov    %rbx,0x28(%rsp)
         0x5432071      mov    %rbp,(%rsp)
         0x5432075      mov    %rsp,%rbp
         0x5432078      sub    $0x8,%rsp
         0x543207c      movslq %edi,%rax
         0x543207f      cmp    $0x1,%rax
         0x5432083      jle    0x54320a8
         0x5432089      mov    %rsi,%rax
         0x543208c      add    $0x8,%rax
         0x5432090      mov    (%rax),%rax
         0x5432093      mov    %rax,%rdi
         0x5432096      movabs $0x3801437230,%rax
         0x54320a0      rex.W callq *%rax
         0x54320a3      jmpq   0x54320b0
         0x54320a8      mov    $0x24,%eax
         0x54320ad      nopl   (%rax)
         0x54320b0      mov    %rax,%rbx
         0x54320b3      mov    %rax,%rdi
         0x54320b6      mov    $0x5432008,%eax
         0x54320bb      rex.W callq *%rax
         0x54320be      mov    %rax,%rdi
         0x54320c1      mov    %rbx,%rsi
         0x54320c4      xor    %rax,%rax
         0x54320c7      mov    %rax,%rdx
         0x54320ca      movabs $0x38014513f0,%r10
         0x54320d4      rex.WB callq *%r10
         0x54320d7      mov    %rbp,%rsp
         0x54320da      mov    0x28(%rsp),%rbx
         0x54320df      mov    (%rsp),%rbp
         0x54320e3      add    $0x30,%rsp
         0x54320e7      retq

  There are 2 dumps, one of the IR and another of the machine code.
Hopefully this should give an idea of how it is supposed to work.

btw, there is a bug and it would pass NULL as format to printf...
but that is why it is not executing code yet :-)


reply via email to

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