lightning
[Top][All Lists]
Advanced

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

[Lightning] Funny behavior


From: Francis McCabe
Subject: [Lightning] Funny behavior
Date: Sun, 07 Mar 2010 21:39:24 -0800

I am trying to track down some funny behavior with lightning (I am using 
version 1.2c)

 When I run the tests in the tests directory, I get expected behavior. For 
example, for the fragment (modified from add.c):

#include <stdio.h>
#include <sys/mman.h>
#include "lightning.h"

typedef int (*pifii)(int, int); /* Pointer to Int Function of Int, Int */

int main()
{
 jit_state pkg_state;

#define _jit          (pkg_state)
 jit_insn *codeBuffer = mmap (NULL, 4096, PROT_EXEC | PROT_READ | PROT_WRITE,
                               MAP_PRIVATE | MAP_ANON, -1, 0);

 printf("R%d, V%d\n",JIT_R_NUM,JIT_V_NUM);

 pifii myFunction= (pifii) (jit_set_ip(codeBuffer).iptr);
 int    ofs;                            /* offset of the argument */

 jit_leaf(2);
 ofs = jit_arg_i();
 jit_getarg_i(JIT_R0, ofs);
 ofs = jit_arg_i();
 jit_getarg_i(JIT_R1, ofs);
 jit_insn *ref =  jit_boaddr_i(jit_forward(), JIT_R0, JIT_R1);
 jit_movr_i(JIT_RET,JIT_R0);
 jit_ret();

 jit_patch(ref);
 jit_movi_i(JIT_RET,800000);
 jit_ret();

 jit_flush_code(codeBuffer, jit_get_ip().ptr);

 /* Call the generated code, passing its size as argument */
#ifdef LIGHTNING_DISASSEMBLE
 disassemble(stderr, codeBuffer, jit_get_ip().ptr);
#endif
#ifndef LIGHTNING_CROSS
 int X = (1<<30)-1;
 printf("%d + %d = %d\n", X,X,X+X);
 printf("%d + %d = %d\n", X, X, myFunction(X, X));
#endif
 return 0;
#undef _jit
}


I get the following contents in codeBuffer from gdb:

x/30i codeBuffer
0x100022000:    push   %rbx
0x100022001:    push   %r12
0x100022003:    push   %r13
0x100022005:    push   %rbp
0x100022006:    mov    %rsp,%rbp
0x100022009:    push   %rbx
0x10002200a:    mov    %edi,%eax
0x10002200c:    mov    %esi,%r10d
0x10002200f:    add    %r10d,%eax
0x100022012:    jo     0x10002201f
0x100022018:    leaveq 
0x100022019:    pop    %r13
0x10002201b:    pop    %r12
0x10002201d:    pop    %rbx
0x10002201e:    retq   
0x10002201f:    mov    $0xc3500,%eax
0x100022024:    leaveq 
0x100022025:    pop    %r13
0x100022027:    pop    %r12
0x100022029:    pop    %rbx
0x10002202a:    retq  

However, I included IDENTICAL code in another project, and I get:

        push   %rbp
0x1000af001:    mov    %esp,%ebp
0x1000af003:    push   %rbx
0x1000af004:    push   %rsi
0x1000af005:    push   %rdi
0x1000af006:    mov    %eax,%eax
0x1000af008:    mov    %esp,%ecx
0x1000af00a:    add    %ecx,%eax
0x1000af00c:    jo     0x1000af012
0x1000af012:    add    $0x0,%eax
0x1000af017:    add    %al,(%rax)
0x1000af019:    add    %al,%bl
0x1000af01b:    mov    $0xc3500,%eax
0x1000af020:    add    %al,(%rax)
0x1000af022:    add    %al,(%rax)
0x1000af024:    pop    %rdi
0x1000af025:    pop    %rsi
0x1000af026:    pop    %rbx
0x1000af027:    pop    %rbp
0x1000af028:    retq   

This latter code does not execute properly on my machine.

I used lightningize (after fixing an issue with Makefile.am) to include 
lightning in this latter project.

Notice that the jo jump at address 

0x1000af00c:    jo     0x1000af012

has not been fixed up properly.

I cannot for the life of me figure out why identical code should operate 
differently.

Some points:

I am using Mac OS X 6.2
I could not use the static _jit because I am doing quite a complex project that 
I do not want to put into one file.
I got some warnings when I compiled my project (not the lightning one):

gcc -DHAVE_CONFIG_H -I. -I../..  -I../../src/Compiler/Headers 
-I../../src/Headers -I../../lightning -I../../lightning/i386 
-I/opt/nar/ooio/include '-DCAFDIR="/opt/caf"'  -std=c99 -g -Wall -MT 
caf-compile.o -MD -MP -MF .deps/caf-compile.Tpo -c -o caf-compile.o `test -f 
'compile.c' || echo './'`compile.c
compile.c: In function ‘compilePkg’:
compile.c:33: warning: value computed is not used
compile.c:33: warning: value computed is not used
compile.c:39: warning: implicit declaration of function ‘compileExp’
compile.c: In function ‘compileAdd’:
compile.c:69: warning: cast from pointer to integer of different size
compile.c:69: warning: value computed is not used
compile.c:69: warning: value computed is not used
compile.c:70: warning: statement with no effect
compile.c: At top level:
../../lightning/core-common.h:51: warning: ‘_jit’ defined but not used

I believe that the issue has something to do with 64bit vs 32bit given the 
instructions being generated. But I cannot figure out how the dependencies are 
set up.

Hope that you'all can shed a little light on this.

Thanks

Frank McCabe



reply via email to

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