mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 22:31:12 +02:00
Big merge with new lightning semantics aiming for lightning 2.0.
2012-12-02 Paulo Andrade <pcpa@gnu.org> * tests/Makefile.am, tests/3to2.c, tests/3to2.ok, tests/add.c, tests/add.ok, tests/allocai.c, tests/allocai.ok, tests/bp.c, tests/bp.ok, tests/divi.c, tests/divi.ok, tests/fib.c, tests/fib.ok, tests/fibdelay.c, tests/fibdelay.ok, tests/fibit.c, tests/fibit.ok, tests/funcfp.c, tests/funcfp.ok, tests/incr.c, tests/incr.ok, tests/ldst.c, tests/ldst.ok, tests/ldxi.c, tests/ldxi.ok, tests/modi.c, tests/modi.ok, tests/movi.c, tests/movi.ok, tests/printf.c, tests/printf.ok, tests/printf2.c, tests/printf2.ok, tests/ret.c, tests/ret.ok, tests/rpn.c, tests/rpn.ok, tests/rpnfp.c, tests/rpnfp.ok, tests/sete.c, tests/sete.ok, tests/testfp.c, tests/testfp.ok, tests-run-test: Removed previous test suite, in favor of a newer one in the check subdirectory. * check/3to2.ok, check/3to2.tst, check/add.ok, check/add.tst, check/allocai.ok, check/allocai.tst, check/bp.ok, check/bp.tst, check/divi.ok, check/divi.tst, check/fib.ok, check/fib.tst: New sample input for the new test program, loosely matching several of the previous test cases. * check/Makefile.am: New test suite makefile. * check/check.sh, check/run-test: New wrapper files for the new test suite. * check/lightning.c: New file. The main driver of the new test suite, that compiles to a parser of a very simple assembly like language, generates jit and executes it. * check/all.tst: New file. A generic debug and sample test file with a directive to prevent it from being executed, and useful to read disassembly of all possible instructions, using a fixed set of registers. * include/Makefile.am, include/lightning.h, include/lightning/Makefile.am, include/lightning/jit_arm.h, include/lightning/jit_mips.h, include/lightning/jit_ppc.h, include/lightning/jit_private.h, include/lightning/jit_x86.h, lib/Makefile.am, lib/jit_disasm.c, lib/jit_print.c, lib/jit_x86-cpu.c, lib/jit_x86-sse.c, lib/jit_x86-x87.c, lib/jit_x86.c, lib/lightning.c: New files. These files are written from scratch, only by <pcpa@gnu.org>, and have now copyright assignment to the FSF. This is the core of the new lightning rework. Previously it was integrated in code with a garbage collector and several custom types like vectors and hash tables, so this first code merge with lightning converts that code into a library extracting only the jit bits, and at first only for x86_64 GNU/Linux. * lightning.h, m4/lightning.m4: Removed. These are no longer required in the new lightning code. .gitignore, Makefile.am, configure.ac: Update for the new lightning code.
This commit is contained in:
parent
75d99beb21
commit
7a1c455237
77 changed files with 17194 additions and 8221 deletions
21
.gitignore
vendored
21
.gitignore
vendored
|
@ -1,17 +1,22 @@
|
|||
+*
|
||||
autom4te.cache
|
||||
aclocal.m4
|
||||
depcomp
|
||||
INSTALL
|
||||
Makefile.in
|
||||
config.h.in
|
||||
config.guess
|
||||
config.sub
|
||||
configure
|
||||
m4/config.guess
|
||||
m4/config.sub
|
||||
m4/depcomp
|
||||
m4/install-sh
|
||||
m4/mdate-sh
|
||||
m4/missing
|
||||
m4/texinfo.tex
|
||||
doc/Makefile.in
|
||||
install-sh
|
||||
ltmain.sh
|
||||
missing
|
||||
m4/libtool.m4
|
||||
m4/lt~obsolete.m4
|
||||
m4/ltoptions.m4
|
||||
m4/ltsugar.m4
|
||||
m4/ltversion.m4
|
||||
doc/mdate-sh
|
||||
doc/texinfo.tex
|
||||
lightning/Makefile.in
|
||||
tests/Makefile.in
|
||||
|
|
56
ChangeLog
56
ChangeLog
|
@ -1,3 +1,59 @@
|
|||
2012-12-02 Paulo Andrade <pcpa@gnu.org>
|
||||
|
||||
* tests/Makefile.am, tests/3to2.c, tests/3to2.ok, tests/add.c,
|
||||
tests/add.ok, tests/allocai.c, tests/allocai.ok, tests/bp.c,
|
||||
tests/bp.ok, tests/divi.c, tests/divi.ok, tests/fib.c, tests/fib.ok,
|
||||
tests/fibdelay.c, tests/fibdelay.ok, tests/fibit.c, tests/fibit.ok,
|
||||
tests/funcfp.c, tests/funcfp.ok, tests/incr.c, tests/incr.ok,
|
||||
tests/ldst.c, tests/ldst.ok, tests/ldxi.c, tests/ldxi.ok,
|
||||
tests/modi.c, tests/modi.ok, tests/movi.c, tests/movi.ok,
|
||||
tests/printf.c, tests/printf.ok, tests/printf2.c, tests/printf2.ok,
|
||||
tests/ret.c, tests/ret.ok, tests/rpn.c, tests/rpn.ok, tests/rpnfp.c,
|
||||
tests/rpnfp.ok, tests/sete.c, tests/sete.ok, tests/testfp.c,
|
||||
tests/testfp.ok, tests-run-test: Removed previous test suite, in
|
||||
favor of a newer one in the check subdirectory.
|
||||
|
||||
* check/3to2.ok, check/3to2.tst, check/add.ok, check/add.tst,
|
||||
check/allocai.ok, check/allocai.tst, check/bp.ok, check/bp.tst,
|
||||
check/divi.ok, check/divi.tst, check/fib.ok, check/fib.tst:
|
||||
New sample input for the new test program, loosely matching
|
||||
several of the previous test cases.
|
||||
|
||||
* check/Makefile.am: New test suite makefile.
|
||||
|
||||
* check/check.sh, check/run-test: New wrapper files for the
|
||||
new test suite.
|
||||
|
||||
* check/lightning.c: New file. The main driver of the new test
|
||||
suite, that compiles to a parser of a very simple assembly like
|
||||
language, generates jit and executes it.
|
||||
|
||||
* check/all.tst: New file. A generic debug and sample test file
|
||||
with a directive to prevent it from being executed, and useful to
|
||||
read disassembly of all possible instructions, using a fixed set
|
||||
of registers.
|
||||
|
||||
* include/Makefile.am, include/lightning.h,
|
||||
include/lightning/Makefile.am, include/lightning/jit_arm.h,
|
||||
include/lightning/jit_mips.h, include/lightning/jit_ppc.h,
|
||||
include/lightning/jit_private.h, include/lightning/jit_x86.h,
|
||||
lib/Makefile.am, lib/jit_disasm.c, lib/jit_print.c,
|
||||
lib/jit_x86-cpu.c, lib/jit_x86-sse.c, lib/jit_x86-x87.c,
|
||||
lib/jit_x86.c, lib/lightning.c: New files. These files are
|
||||
written from scratch, only by <pcpa@gnu.org>, and have now
|
||||
copyright assignment to the FSF. This is the core of the new
|
||||
lightning rework. Previously it was integrated in code with
|
||||
a garbage collector and several custom types like vectors and
|
||||
hash tables, so this first code merge with lightning converts
|
||||
that code into a library extracting only the jit bits, and at
|
||||
first only for x86_64 GNU/Linux.
|
||||
|
||||
* lightning.h, m4/lightning.m4: Removed. These are no longer
|
||||
required in the new lightning code.
|
||||
|
||||
.gitignore, Makefile.am, configure.ac: Update for the new
|
||||
lightning code.
|
||||
|
||||
2012-12-02 Paulo Andrade <pcpa@gnu.org>
|
||||
* .cvsignore: Removed for extra cleanup.
|
||||
|
||||
|
|
27
Makefile.am
27
Makefile.am
|
@ -1,10 +1,21 @@
|
|||
# Automake requirements:
|
||||
AUTOMAKE_OPTIONS = 1.8 gnu
|
||||
#
|
||||
# Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
|
||||
#
|
||||
# This is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This software is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = . doc lightning tests
|
||||
|
||||
include_HEADERS = lightning.h
|
||||
|
||||
aclocaldir = $(datadir)/aclocal
|
||||
dist_aclocal_DATA = m4/lightning.m4
|
||||
SUBDIRS = \
|
||||
check \
|
||||
doc \
|
||||
include \
|
||||
lib
|
||||
|
|
22
check/3to2.ok
Normal file
22
check/3to2.ok
Normal file
|
@ -0,0 +1,22 @@
|
|||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
111
check/3to2.tst
Normal file
111
check/3to2.tst
Normal file
|
@ -0,0 +1,111 @@
|
|||
.data 32
|
||||
dfmt:
|
||||
.c "%1.0f\n"
|
||||
ifmt:
|
||||
.c "%d\n"
|
||||
|
||||
.code
|
||||
jmpi main
|
||||
|
||||
#define def_test_double(a, b, c) \
|
||||
test_double_##a##_##b##_##c: \
|
||||
prolog \
|
||||
arg_d $d0 \
|
||||
arg_d $d1 \
|
||||
getarg_d %b $d0 \
|
||||
getarg_d %c $d1 \
|
||||
subr_d %a %b %c \
|
||||
retr_d %a \
|
||||
epilog
|
||||
#define test_double(a, b, c, x, y) \
|
||||
prepare 0 \
|
||||
pushargi_d x \
|
||||
pushargi_d y \
|
||||
finishi test_double_##a##_##b##_##c \
|
||||
prepare 1 \
|
||||
pushargi dfmt \
|
||||
pushargr_d %fret \
|
||||
finishi @printf
|
||||
|
||||
#define def_test_int(a, b, c) \
|
||||
test_int_##a##_##b##_##c: \
|
||||
prolog \
|
||||
arg $i0 \
|
||||
arg $i1 \
|
||||
getarg %b $i0 \
|
||||
getarg %c $i1 \
|
||||
subr %a %b %c \
|
||||
retr %a \
|
||||
epilog
|
||||
#define test_int(a, b, c, x, y) \
|
||||
prepare 0 \
|
||||
pushargi x \
|
||||
pushargi y \
|
||||
finishi test_int_##a##_##b##_##c \
|
||||
prepare 1 \
|
||||
pushargi ifmt \
|
||||
pushargr %ret \
|
||||
finishi @printf
|
||||
|
||||
def_test_double(f0, f0, f0)
|
||||
def_test_double(f0, f0, f1)
|
||||
def_test_double(f0, f1, f0)
|
||||
def_test_double(f0, f1, f2)
|
||||
|
||||
def_test_double(f3, f3, f3)
|
||||
def_test_double(f3, f3, f1)
|
||||
def_test_double(f3, f1, f3)
|
||||
def_test_double(f3, f1, f2)
|
||||
|
||||
def_test_double(f3, f0, f0)
|
||||
def_test_double(f3, f0, f3)
|
||||
def_test_double(f3, f3, f0)
|
||||
|
||||
def_test_int(r0, r0, r0)
|
||||
def_test_int(r0, r0, r1)
|
||||
def_test_int(r0, r1, r0)
|
||||
def_test_int(r0, r1, r2)
|
||||
|
||||
def_test_int(v0, v0, v0)
|
||||
def_test_int(v0, v0, r1)
|
||||
def_test_int(v0, r1, v0)
|
||||
def_test_int(v0, r1, r2)
|
||||
|
||||
def_test_int(v0, r0, r0)
|
||||
def_test_int(v0, r0, v0)
|
||||
def_test_int(v0, v0, r0)
|
||||
|
||||
|
||||
main:
|
||||
prolog
|
||||
|
||||
test_double(f0, f0, f0, 3.0, 2.0)
|
||||
test_double(f0, f0, f1, 3.0, 2.0)
|
||||
test_double(f0, f1, f0, 3.0, 2.0)
|
||||
test_double(f0, f1, f2, 3.0, 2.0)
|
||||
|
||||
test_double(f3, f3, f3, 3.0, 2.0)
|
||||
test_double(f3, f3, f1, 3.0, 2.0)
|
||||
test_double(f3, f1, f3, 3.0, 2.0)
|
||||
test_double(f3, f1, f2, 3.0, 2.0)
|
||||
|
||||
test_double(f3, f0, f0, 3.0, 2.0)
|
||||
test_double(f3, f0, f3, 3.0, 2.0)
|
||||
test_double(f3, f3, f0, 3.0, 2.0)
|
||||
|
||||
test_int(r0, r0, r0, 3, 2)
|
||||
test_int(r0, r0, r1, 3, 2)
|
||||
test_int(r0, r1, r0, 3, 2)
|
||||
test_int(r0, r1, r2, 3, 2)
|
||||
|
||||
test_int(v0, v0, v0, 3, 2)
|
||||
test_int(v0, v0, r1, 3, 2)
|
||||
test_int(v0, r1, v0, 3, 2)
|
||||
test_int(v0, r1, r2, 3, 2)
|
||||
|
||||
test_int(v0, r0, r0, 3, 2)
|
||||
test_int(v0, r0, v0, 3, 2)
|
||||
test_int(v0, v0, r0, 3, 2)
|
||||
|
||||
ret
|
||||
epilog
|
43
check/Makefile.am
Normal file
43
check/Makefile.am
Normal file
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# Copyright 2012 Free Software Foundation, Inc.
|
||||
#
|
||||
# This is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This software is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
|
||||
AM_CFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE
|
||||
|
||||
check_PROGRAMS = lightning
|
||||
|
||||
lightning_LDADD = $(top_srcdir)/lib/liblightning.la -ldl
|
||||
|
||||
lightning_SOURCES = \
|
||||
lightning.c
|
||||
|
||||
EXTRA_DIST = \
|
||||
3to2.tst 3to2.ok \
|
||||
add.tst add.ok \
|
||||
allocai.tst allocai.ok \
|
||||
bp.tst bp.ok \
|
||||
divi.tst divi.ok \
|
||||
fib.tst fib.ok \
|
||||
all.tst
|
||||
|
||||
TESTS = 3to2 add allocai bp divi fib
|
||||
|
||||
# Not so pretty but good for a prototype
|
||||
$(TESTS): check.sh
|
||||
$(LN_S) check.sh $@
|
||||
|
||||
TESTS_ENVIRONMENT=$(srcdir)/run-test
|
||||
|
||||
debug: $(check_PROGRAMS)
|
||||
$(LIBTOOL) --mode=execute gdb $(check_PROGRAMS)
|
||||
|
31
check/add.tst
Normal file
31
check/add.tst
Normal file
|
@ -0,0 +1,31 @@
|
|||
.data 32
|
||||
fmt:
|
||||
.c "%d + %d = %d\n"
|
||||
|
||||
.code
|
||||
jmpi main
|
||||
|
||||
test:
|
||||
prolog
|
||||
arg $i0
|
||||
arg $i1
|
||||
getarg %r0 $i0
|
||||
getarg %r1 $i1
|
||||
addr %ret %r0 %r1
|
||||
ret
|
||||
epilog
|
||||
|
||||
main:
|
||||
prolog
|
||||
prepare 0
|
||||
pushargi 5
|
||||
pushargi 4
|
||||
finishi test
|
||||
prepare 1
|
||||
pushargi fmt
|
||||
pushargi 5
|
||||
pushargi 4
|
||||
pushargr %r0
|
||||
finishi @printf
|
||||
ret
|
||||
epilog
|
384
check/all.tst
Normal file
384
check/all.tst
Normal file
|
@ -0,0 +1,384 @@
|
|||
.disasm // only disassemble
|
||||
.code
|
||||
prolog
|
||||
allocai 32 $buf
|
||||
arg $c
|
||||
arg $uc
|
||||
arg $s
|
||||
arg $us
|
||||
arg $i
|
||||
arg $ui
|
||||
arg $l
|
||||
getarg_c %r0 $c
|
||||
getarg_uc %r0 $uc
|
||||
getarg_s %r0 $s
|
||||
getarg_us %r0 $us
|
||||
getarg_i %r0 $i
|
||||
getarg_ui %r0 $ui
|
||||
getarg_l %r0 $l
|
||||
addr %r0 %r1 %r2
|
||||
addi %r0 %r1 2
|
||||
addxr %r0 %r1 %r2
|
||||
addxi %r0 %r1 2
|
||||
addcr %r0 %r1 %r2
|
||||
addci %r0 %r1 2
|
||||
subr %r0 %r1 %r2
|
||||
subi %r0 %r1 2
|
||||
subxr %r0 %r1 %r2
|
||||
subxi %r0 %r1 2
|
||||
subcr %r0 %r1 %r2
|
||||
subci %r0 %r1 2
|
||||
mulr %r0 %r1 %r2
|
||||
muli %r0 %r1 2
|
||||
divr %r0 %r1 %r2
|
||||
divi %r0 %r1 2
|
||||
divr_u %r0 %r1 %r2
|
||||
divi_u %r0 %r1 2
|
||||
remr %r0 %r1 %r2
|
||||
remi %r0 %r1 2
|
||||
remr_u %r0 %r1 %r2
|
||||
remi_u %r0 %r1 2
|
||||
andr %r0 %r1 %r2
|
||||
andi %r0 %r1 2
|
||||
orr %r0 %r1 %r2
|
||||
ori %r0 %r1 2
|
||||
xorr %r0 %r1 %r2
|
||||
xori %r0 %r1 2
|
||||
lshr %r0 %r1 %r2
|
||||
lshi %r0 %r1 2
|
||||
rshr %r0 %r1 %r2
|
||||
rshi %r0 %r1 2
|
||||
rshr_u %r0 %r1 %r2
|
||||
rshi_u %r0 %r1 2
|
||||
negr %r0 %r1
|
||||
comr %r0 %r1
|
||||
ltr %r0 %r1 %r2
|
||||
lti %r0 %r1 2
|
||||
ltr_u %r0 %r1 %r2
|
||||
lti_u %r0 %r1 2
|
||||
ler %r0 %r1 %r2
|
||||
lei %r0 %r1 2
|
||||
ler_u %r0 %r1 %r2
|
||||
lei_u %r0 %r1 2
|
||||
eqr %r0 %r1 %r2
|
||||
eqi %r0 %r1 2
|
||||
ger %r0 %r1 %r2
|
||||
gei %r0 %r1 2
|
||||
ger_u %r0 %r1 %r2
|
||||
gei_u %r0 %r1 2
|
||||
gtr %r0 %r1 %r2
|
||||
gti %r0 %r1 2
|
||||
gtr_u %r0 %r1 %r2
|
||||
gti_u %r0 %r1 2
|
||||
ner %r0 %r1 %r2
|
||||
nei %r0 %r1 2
|
||||
movr %r0 %r1
|
||||
movi %r0 1
|
||||
extr_c %r0 %r1
|
||||
extr_uc %r0 %r1
|
||||
extr_s %r0 %r1
|
||||
extr_us %r0 %r1
|
||||
extr_i %r0 %r1
|
||||
extr_ui %r0 %r1
|
||||
htonr %r0 %r1
|
||||
ntohr %r0 %r1
|
||||
ldr_c %r0 %r1
|
||||
ldi_c %r0 0x80000000
|
||||
ldr_uc %r0 %r1
|
||||
ldi_uc %r0 0x80000000
|
||||
ldr_s %r0 %r1
|
||||
ldi_s %r0 0x80000000
|
||||
ldr_us %r0 %r1
|
||||
ldi_us %r0 0x80000000
|
||||
ldr_i %r0 %r1
|
||||
ldi_i %r0 0x80000000
|
||||
ldr_ui %r0 %r1
|
||||
ldi_ui %r0 0x80000000
|
||||
ldr_l %r0 %r1
|
||||
ldi_l %r0 0x80000000
|
||||
ldxr_c %r0 %r1 %r2
|
||||
ldxi_c %r0 %r1 1
|
||||
ldxr_uc %r0 %r1 %r2
|
||||
ldxi_uc %r0 %r1 1
|
||||
ldxr_s %r0 %r1 %r2
|
||||
ldxi_s %r0 %r1 2
|
||||
ldxr_us %r0 %r1 %r2
|
||||
ldxi_us %r0 %r1 2
|
||||
ldxr_i %r0 %r1 %r2
|
||||
ldxi_i %r0 %r1 4
|
||||
ldxr_ui %r0 %r1 %r2
|
||||
ldxi_ui %r0 %r1 4
|
||||
ldxr_l %r0 %r1 %r2
|
||||
ldxi_l %r0 %r1 8
|
||||
str_c %r1 %r0
|
||||
sti_c 0x80000000 %r1
|
||||
str_s %r1 %r0
|
||||
sti_s 0x80000000 %r1
|
||||
str_i %r1 %r0
|
||||
sti_i 0x80000000 %r1
|
||||
str_l %r1 %r0
|
||||
sti_l 0x80000000 %r1
|
||||
stxr_c %r2 %r1 %r0
|
||||
stxi_c 1 %r1 %r0
|
||||
stxr_s %r2 %r1 %r0
|
||||
stxi_s 2 %r1 %r0
|
||||
stxr_i %r2 %r1 %r0
|
||||
stxi_i 4 %r1 %r0
|
||||
stxr_l %r2 %r1 %r0
|
||||
stxi_l 8 %r1 %r0
|
||||
cond:
|
||||
bltr cond %r0 %r1
|
||||
condi:
|
||||
blti condi %r0 1
|
||||
condu:
|
||||
bltr_u condu %r0 %r1
|
||||
condiu:
|
||||
blti_u condiu %r0 1
|
||||
bler cond %r0 %r1
|
||||
blei condi %r0 1
|
||||
bler_u condu %r0 %r1
|
||||
blei_u condiu %r0 1
|
||||
bool:
|
||||
beqr bool %r0 %r1
|
||||
booli:
|
||||
beqi booli %r0 1
|
||||
bger cond %r0 %r1
|
||||
bgei condi %r0 1
|
||||
bger_u condu %r0 %r1
|
||||
bgei_u condiu %r0 1
|
||||
bgtr cond %r0 %r1
|
||||
bgti condi %r0 1
|
||||
bgtr_u condu %r0 %r1
|
||||
bgti_u condiu %r0 1
|
||||
bner bool %r0 %r1
|
||||
bnei booli %r0 1
|
||||
mask:
|
||||
bmsr mask %r0 %r1
|
||||
maski:
|
||||
bmsi maski %r0 1
|
||||
bmcr mask %r0 %r1
|
||||
bmci maski %r0 1
|
||||
as:
|
||||
boaddr as %r0 %r1
|
||||
asi:
|
||||
boaddi asi %r0 1
|
||||
asu:
|
||||
boaddr_u as %r0 %r1
|
||||
boaddi_u asi %r0 1
|
||||
bxaddr as %r0 %r1
|
||||
bxaddi asi %r0 1
|
||||
bxaddr_u as %r0 %r1
|
||||
bxaddi_u asi %r0 1
|
||||
bosubr as %r0 %r1
|
||||
bosubi asi %r0 1
|
||||
bosubr_u as %r0 %r1
|
||||
bosubi_u asi %r0 1
|
||||
bxsubr as %r0 %r1
|
||||
bxsubi asi %r0 1
|
||||
bxsubr_u as %r0 %r1
|
||||
bxsubi_u asi %r0 1
|
||||
label:
|
||||
jmpr %r0
|
||||
jmpi label
|
||||
callr %r0
|
||||
calli label
|
||||
prepare 0
|
||||
pushargr %r0
|
||||
finishr %r0
|
||||
prepare 1
|
||||
pushargi 1
|
||||
finishi 0x80000000
|
||||
ret
|
||||
retr %r1
|
||||
reti 2
|
||||
retval_c %r1
|
||||
retval_uc %r1
|
||||
retval_s %r1
|
||||
retval_us %r1
|
||||
retval_i %r1
|
||||
retval_ui %r1
|
||||
retval_l %r1
|
||||
arg_f $f
|
||||
getarg_f %f1 $f
|
||||
addr_f %f0 %f1 %f2
|
||||
addi_f %f0 %f1 0.5
|
||||
subr_f %f0 %f1 %f2
|
||||
subi_f %f0 %f1 0.5
|
||||
mulr_f %f0 %f1 %f2
|
||||
muli_f %f0 %f1 0.5
|
||||
divr_f %f0 %f1 %f2
|
||||
divi_f %f0 %f1 0.5
|
||||
negr_f %f0 %f1
|
||||
absr_f %f0 %f1
|
||||
sqrtr_f %f0 %f1
|
||||
ltr_f %r0 %f0 %f1
|
||||
lti_f %r0 %f0 0.5
|
||||
ler_f %r0 %f0 %f1
|
||||
lei_f %r0 %f0 0.5
|
||||
eqr_f %r0 %f0 %f1
|
||||
eqi_f %r0 %f0 0.5
|
||||
ger_f %r0 %f0 %f1
|
||||
gei_f %r0 %f0 0.5
|
||||
gtr_f %r0 %f0 %f1
|
||||
gti_f %r0 %f0 0.5
|
||||
ner_f %r0 %f0 %f1
|
||||
nei_f %r0 %f0 0.5
|
||||
unltr_f %r0 %f0 %f1
|
||||
unlti_f %r0 %f0 0.5
|
||||
unler_f %r0 %f0 %f1
|
||||
unlei_f %r0 %f0 0.5
|
||||
uneqr_f %r0 %f0 %f1
|
||||
uneqi_f %r0 %f0 0.5
|
||||
unger_f %r0 %f0 %f1
|
||||
ungei_f %r0 %f0 0.5
|
||||
ungtr_f %r0 %f0 %f1
|
||||
ungti_f %r0 %f0 0.5
|
||||
ltgtr_f %r0 %f0 %f1
|
||||
ltgti_f %r0 %f0 0.5
|
||||
ordr_f %r0 %f0 %f1
|
||||
ordi_f %r0 %f0 0.5
|
||||
unordr_f %r0 %f0 %f1
|
||||
unordi_f %r0 %f0 0.5
|
||||
truncr_f_i %r0 %f0
|
||||
truncr_f_l %r0 %f0
|
||||
extr_f %f0 %r0
|
||||
extr_d_f %f0 %f1
|
||||
movr_f %f0 %f1
|
||||
movi_f %f0 1.5
|
||||
ldr_f %f0 %r0
|
||||
ldi_f %f0 0x80000000
|
||||
ldxr_f %f0 %r0 %r1
|
||||
ldxi_f %f0 %r0 4
|
||||
str_f %r0 %f0
|
||||
sti_f 0x80000000 %f0
|
||||
stxr_f %r1 %r0 %f0
|
||||
stxi_f 4 %r0 %f0
|
||||
ord:
|
||||
bltr_f ord %f0 %f1
|
||||
ordi:
|
||||
blti_f ordi %f0 0.5
|
||||
bler_f ord %f0 %f1
|
||||
blei_f ordi %f0 0.5
|
||||
beqr_f ord %f0 %f1
|
||||
beqi_f ordi %f0 0.5
|
||||
bger_f ord %f0 %f1
|
||||
bgei_f ordi %f0 0.5
|
||||
bgtr_f ord %f0 %f1
|
||||
bgti_f ordi %f0 0.5
|
||||
bner_f ord %f0 %f1
|
||||
bnei_f ordi %f0 0.5
|
||||
unord:
|
||||
bunltr_f unord %f0 %f1
|
||||
unordi:
|
||||
bunlti_f unordi %f0 0.5
|
||||
bunler_f unord %f0 %f1
|
||||
bunlei_f unordi %f0 0.5
|
||||
buneqr_f unord %f0 %f1
|
||||
buneqi_f unordi %f0 0.5
|
||||
bunger_f unord %f0 %f1
|
||||
bungei_f unordi %f0 0.5
|
||||
bungtr_f unord %f0 %f1
|
||||
bungti_f unordi %f0 0.5
|
||||
bltgtr_f unord %f0 %f1
|
||||
bltgti_f unordi %f0 0.5
|
||||
bordr_f unord %f0 %f1
|
||||
bordi_f unordi %f0 0.5
|
||||
bunordr_f unord %f0 %f1
|
||||
bunordi_f unordi %f0 0.5
|
||||
prepare 0
|
||||
pushargr_f %f1
|
||||
pushargi_f 0.5
|
||||
finishi 0x80000000
|
||||
retr_f %f1
|
||||
reti_f 0.5
|
||||
retval_f %f1
|
||||
arg_d $f
|
||||
getarg_d %f1 $f
|
||||
addr_d %f0 %f1 %f2
|
||||
addi_d %f0 %f1 0.5
|
||||
subr_d %f0 %f1 %f2
|
||||
subi_d %f0 %f1 0.5
|
||||
mulr_d %f0 %f1 %f2
|
||||
muli_d %f0 %f1 0.5
|
||||
divr_d %f0 %f1 %f2
|
||||
divi_d %f0 %f1 0.5
|
||||
negr_d %f0 %f1
|
||||
absr_d %f0 %f1
|
||||
sqrtr_d %f0 %f1
|
||||
ltr_d %r0 %f0 %f1
|
||||
lti_d %r0 %f0 0.5
|
||||
ler_d %r0 %f0 %f1
|
||||
lei_d %r0 %f0 0.5
|
||||
eqr_d %r0 %f0 %f1
|
||||
eqi_d %r0 %f0 0.5
|
||||
ger_d %r0 %f0 %f1
|
||||
gei_d %r0 %f0 0.5
|
||||
gtr_d %r0 %f0 %f1
|
||||
gti_d %r0 %f0 0.5
|
||||
ner_d %r0 %f0 %f1
|
||||
nei_d %r0 %f0 0.5
|
||||
unltr_d %r0 %f0 %f1
|
||||
unlti_d %r0 %f0 0.5
|
||||
unler_d %r0 %f0 %f1
|
||||
unlei_d %r0 %f0 0.5
|
||||
uneqr_d %r0 %f0 %f1
|
||||
uneqi_d %r0 %f0 0.5
|
||||
unger_d %r0 %f0 %f1
|
||||
ungei_d %r0 %f0 0.5
|
||||
ungtr_d %r0 %f0 %f1
|
||||
ungti_d %r0 %f0 0.5
|
||||
ltgtr_d %r0 %f0 %f1
|
||||
ltgti_d %r0 %f0 0.5
|
||||
ordr_d %r0 %f0 %f1
|
||||
ordi_d %r0 %f0 0.5
|
||||
unordr_d %r0 %f0 %f1
|
||||
unordi_d %r0 %f0 0.5
|
||||
truncr_d_i %r0 %f0
|
||||
truncr_d_l %r0 %f0
|
||||
extr_d %f0 %r0
|
||||
extr_f_d %f0 %f1
|
||||
movr_d %f0 %f1
|
||||
movi_d %f0 1.5
|
||||
ldr_d %f0 %r0
|
||||
ldi_d %f0 0x80000000
|
||||
ldxr_d %f0 %r0 %r1
|
||||
ldxi_d %f0 %r0 8
|
||||
str_d %r0 %f0
|
||||
sti_d 0x80000000 %f0
|
||||
stxr_d %r1 %r0 %f0
|
||||
stxi_d 8 %r0 %f0
|
||||
bltr_d ord %f0 %f1
|
||||
blti_d ordi %f0 0.5
|
||||
bler_d ord %f0 %f1
|
||||
blei_d ordi %f0 0.5
|
||||
beqr_d ord %f0 %f1
|
||||
beqi_d ordi %f0 0.5
|
||||
bger_d ord %f0 %f1
|
||||
bgei_d ordi %f0 0.5
|
||||
bgtr_d ord %f0 %f1
|
||||
bgti_d ordi %f0 0.5
|
||||
bner_d ord %f0 %f1
|
||||
bnei_d ordi %f0 0.5
|
||||
bunltr_d unord %f0 %f1
|
||||
bunlti_d unordi %f0 0.5
|
||||
bunler_d unord %f0 %f1
|
||||
bunlei_d unordi %f0 0.5
|
||||
buneqr_d unord %f0 %f1
|
||||
buneqi_d unordi %f0 0.5
|
||||
bunger_d unord %f0 %f1
|
||||
bungei_d unordi %f0 0.5
|
||||
bungtr_d unord %f0 %f1
|
||||
bungti_d unordi %f0 0.5
|
||||
bltgtr_d unord %f0 %f1
|
||||
bltgti_d unordi %f0 0.5
|
||||
bordr_d unord %f0 %f1
|
||||
bordi_d unordi %f0 0.5
|
||||
bunordr_d unord %f0 %f1
|
||||
bunordi_d unordi %f0 0.5
|
||||
prepare 0
|
||||
pushargr_d %f1
|
||||
pushargi_d 0.5
|
||||
finishi 0x80000000
|
||||
retr_d %f1
|
||||
reti_d 0.5
|
||||
retval_d %f1
|
92
check/allocai.tst
Normal file
92
check/allocai.tst
Normal file
|
@ -0,0 +1,92 @@
|
|||
.data 128
|
||||
idfmt:
|
||||
.c "received %d\n"
|
||||
failure_message:
|
||||
.c "numbers don't add up to zero\n"
|
||||
report_message:
|
||||
.c "failed: got %i instead of %i\n"
|
||||
succeeded_message:
|
||||
.c "succeeded\n"
|
||||
|
||||
.code
|
||||
jmpi main
|
||||
|
||||
/*
|
||||
static int
|
||||
identity (int arg)
|
||||
{
|
||||
printf ("received %i\n", arg);
|
||||
return arg;
|
||||
}
|
||||
*/
|
||||
identify:
|
||||
prolog
|
||||
arg $i
|
||||
getarg %v0 $i
|
||||
prepare 1
|
||||
pushargi idfmt
|
||||
pushargr %v0
|
||||
finishi @printf
|
||||
retr %v0
|
||||
epilog
|
||||
|
||||
identity_func:
|
||||
prolog
|
||||
arg $i
|
||||
getarg %r1 $i
|
||||
|
||||
/* Store the argument on the stack. */
|
||||
allocai $(__WORDSIZE >> 3) $off
|
||||
stxi $off %fp %r1
|
||||
|
||||
/* Store the negative of the argument on the stack. */
|
||||
allocai $(__WORDSIZE >> 3) $neg
|
||||
negr %r2 %r1
|
||||
stxi $neg %fp %r2
|
||||
|
||||
/* Invoke FUNC. */
|
||||
prepare 0
|
||||
pushargr %r1
|
||||
finishi identify
|
||||
|
||||
/* Ignore the result. */
|
||||
|
||||
/* Restore the negative and the argument from the stack. */
|
||||
ldxi %r2 %fp $neg
|
||||
ldxi %v1 %fp $off
|
||||
|
||||
/* Make sure they still add to zero. */
|
||||
addr %r0 %v1 %r2
|
||||
bnei branch %r0 0
|
||||
|
||||
/* Return it. */
|
||||
retr %v1
|
||||
|
||||
/* Display a failure message. */
|
||||
branch:
|
||||
prepare 1
|
||||
pushargi failure_message
|
||||
finishi @printf
|
||||
|
||||
/* Leave. */
|
||||
retr %v1
|
||||
epilog
|
||||
|
||||
main:
|
||||
prolog
|
||||
prepare 0
|
||||
pushargi 7777
|
||||
finishi identity_func
|
||||
beqi succeeded %ret 7777
|
||||
prepare 1
|
||||
pushargi report_message
|
||||
pushargr %ret
|
||||
pushargi 7777
|
||||
finishi @printf
|
||||
reti 1
|
||||
succeeded:
|
||||
prepare 1
|
||||
pushargi succeeded_message
|
||||
finishi @printf
|
||||
reti 0
|
||||
epilog
|
44
check/bp.tst
Normal file
44
check/bp.tst
Normal file
|
@ -0,0 +1,44 @@
|
|||
.data 32
|
||||
fmt:
|
||||
.c "nfibs(%d) = %d\n"
|
||||
|
||||
.code
|
||||
jmpi main
|
||||
|
||||
rfibs:
|
||||
prolog
|
||||
arg $in
|
||||
getarg %v0 $in /* V0 = N */
|
||||
|
||||
blti_u out %v0 2
|
||||
subi %v1 %v0 1 /* V1 = N-1 */
|
||||
subi %v2 %v0 2 /* V1 = N-2 */
|
||||
prepare 0
|
||||
pushargr %v1
|
||||
finishi rfibs
|
||||
retval %v1 /* V1 = rfibs(N-1) */
|
||||
prepare 0
|
||||
pushargr %v2
|
||||
finishi rfibs
|
||||
retval %v2 /* V2 = rfibs(N-2) */
|
||||
addi %v1 %v1 1
|
||||
addr %ret %v1 %v2
|
||||
ret
|
||||
out:
|
||||
movi %ret 1
|
||||
ret
|
||||
epilog
|
||||
|
||||
main:
|
||||
prolog
|
||||
prepare 0
|
||||
pushargi 32
|
||||
finishi rfibs
|
||||
retval %v0
|
||||
prepare 1
|
||||
pushargi fmt
|
||||
pushargi 32
|
||||
pushargr %v0
|
||||
finishi @printf
|
||||
ret
|
||||
epilog
|
2
check/check.sh
Executable file
2
check/check.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
./lightning `basename $0`
|
79
check/divi.tst
Normal file
79
check/divi.tst
Normal file
|
@ -0,0 +1,79 @@
|
|||
.data 128
|
||||
small_ops:
|
||||
.i 40 64 80
|
||||
large_ops:
|
||||
.i 98304 65536 163840
|
||||
fmt:
|
||||
.c "%i/%i = %i (expected %i)\n"
|
||||
x:
|
||||
.c "%d\n"
|
||||
.code
|
||||
jmpi main
|
||||
|
||||
#define generate_divider(operand) \
|
||||
divider_##operand: \
|
||||
prolog \
|
||||
arg $i \
|
||||
getarg %r1 $i \
|
||||
divi %r2 %r1 operand \
|
||||
retr %r2 \
|
||||
epilog
|
||||
generate_divider(8)
|
||||
generate_divider(32768)
|
||||
|
||||
#define generate_test_divider(divisor) \
|
||||
test_divider_##divisor: \
|
||||
prolog \
|
||||
allocai 4 $loc \
|
||||
arg $p \
|
||||
arg $c \
|
||||
getarg %v0 $p \
|
||||
getarg %v1 $c \
|
||||
muli %v1 %v1 4 \
|
||||
addr %v1 %v0 %v1 \
|
||||
loop_##divisor: \
|
||||
bger done_##divisor %v0 %v1 \
|
||||
ldr_i %v2 %v0 \
|
||||
prepare 0 \
|
||||
pushargr %v2 \
|
||||
finishi divider_##divisor \
|
||||
retval %v2 \
|
||||
ldr_i %r2 %v0 \
|
||||
divi %r0 %r2 divisor \
|
||||
/* save div result */ \
|
||||
stxi_i $loc %fp %r0 \
|
||||
prepare 1 \
|
||||
pushargi fmt \
|
||||
pushargr %r2 \
|
||||
pushargi divisor \
|
||||
pushargr %v2 \
|
||||
pushargr %r0 \
|
||||
finishi @printf \
|
||||
addi %v0 %v0 4 \
|
||||
/* reload div result */ \
|
||||
ldxi_i %r0 %fp $loc \
|
||||
beqr loop_##divisor %r0 %v2 \
|
||||
/* return if failed */ \
|
||||
reti 1 \
|
||||
done_##divisor: \
|
||||
reti 0 \
|
||||
epilog
|
||||
generate_test_divider(8)
|
||||
generate_test_divider(32768)
|
||||
|
||||
main:
|
||||
prolog
|
||||
prepare 0
|
||||
pushargi small_ops
|
||||
pushargi 3
|
||||
finishi test_divider_8
|
||||
bnei fail %ret 0
|
||||
prepare 0
|
||||
pushargi large_ops
|
||||
pushargi 3
|
||||
finishi test_divider_32768
|
||||
bnei fail %ret 0
|
||||
reti 0
|
||||
fail:
|
||||
reti 1
|
||||
epilog
|
58
check/fib.tst
Normal file
58
check/fib.tst
Normal file
|
@ -0,0 +1,58 @@
|
|||
.data 32
|
||||
format:
|
||||
.c "nfibs(%d) = %d\n"
|
||||
|
||||
.code
|
||||
jmpi main
|
||||
|
||||
nfibs:
|
||||
prolog
|
||||
arg $in
|
||||
getarg_ui %r2 $in // R2 = n
|
||||
movi %r1 1
|
||||
blti_u ref %r2 2
|
||||
subi %r2 %r2 1
|
||||
movi %r0 1
|
||||
loop:
|
||||
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
|
||||
ref:
|
||||
movr %ret %r1 // RET = R1
|
||||
ret
|
||||
epilog
|
||||
|
||||
main:
|
||||
prolog
|
||||
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
|
||||
|
||||
default:
|
||||
movi %r0 32
|
||||
|
||||
call:
|
||||
movr %v0 %r0
|
||||
prepare 0
|
||||
pushargr %r0
|
||||
finishi nfibs
|
||||
retval %r0
|
||||
prepare 1
|
||||
pushargi format
|
||||
pushargr %v0
|
||||
pushargr %r0
|
||||
finishi @printf
|
||||
ret
|
||||
epilog
|
3859
check/lightning.c
Normal file
3859
check/lightning.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,6 @@
|
|||
#! /bin/sh
|
||||
|
||||
./$1 | tr -d \\r > $1.log
|
||||
if test $? = 77; then
|
||||
exit 77
|
||||
fi
|
||||
|
||||
./lightning $1.tst | tr -d \\r > $1.log
|
||||
if cmp -s $srcdir/$1.ok $1.log; then
|
||||
rm $1.log
|
||||
else
|
124
configure.ac
124
configure.ac
|
@ -1,70 +1,76 @@
|
|||
dnl Hey Emacs, I want this in -*- autoconf -*- mode, please.
|
||||
|
||||
dnl Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
dnl Please see COPYING for a description your rights and responsibilities
|
||||
dnl with this software.
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
dnl ----------------------------- HOST SYSTEM -----------------------------------
|
||||
|
||||
AC_PREREQ(2.54)
|
||||
AC_INIT([GNU lightning], 1.2c, bonzini@gnu.org, lightning)
|
||||
AC_CONFIG_AUX_DIR(m4)
|
||||
AC_CONFIG_MACRO_DIR(m4)
|
||||
AC_CONFIG_SRCDIR([lightning.h])
|
||||
dnl
|
||||
dnl Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
|
||||
dnl
|
||||
dnl This is free software; you can redistribute it and/or modify
|
||||
dnl it under the terms of the GNU General Public License as published by
|
||||
dnl the Free Software Foundation; either version 3 of the License, or
|
||||
dnl (at your option) any later version.
|
||||
dnl
|
||||
dnl This software is distributed in the hope that it will be useful,
|
||||
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
dnl GNU General Public License for more details.
|
||||
dnl
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([GNU lightning], 2.0, pcpa@gnu.org, lightning)
|
||||
AC_CANONICAL_TARGET
|
||||
AC_CONFIG_HEADERS(config.h)
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_SRCDIR([Makefile.am])
|
||||
AM_INIT_AUTOMAKE([dist-bzip2])
|
||||
AC_CONFIG_MACRO_DIR(m4)
|
||||
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CPP
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_RANLIB
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PATH_PROG(INSTALL_INFO, install-info, :, $PATH:/sbin)
|
||||
AC_EXEEXT
|
||||
AC_PROG_LIBTOOL
|
||||
|
||||
BACKENDS="LIGHTNING_BACKENDS"
|
||||
AC_SUBST(BACKENDS)
|
||||
AC_CHECK_LIB(gmp, __gmpz_init, ,
|
||||
[AC_MSG_ERROR([GNU MP not found, see http://gmplib.org/])])
|
||||
|
||||
case "$target_cpu" in
|
||||
i?86) LIGHTNING_TARGET=LIGHTNING_I386 ;;
|
||||
x86_64) LIGHTNING_TARGET=LIGHTNING_X86_64 ;;
|
||||
sparc*) LIGHTNING_TARGET=LIGHTNING_SPARC ;;
|
||||
powerpc) LIGHTNING_TARGET=LIGHTNING_PPC ;;
|
||||
*) ;;
|
||||
esac
|
||||
LIGHTNING_CONFIGURE_LINKS(
|
||||
[AC_DEFINE_UNQUOTED(LIGHTNING_TARGET, [AS_TR_CPP([$LIGHTNING_TARGET])],
|
||||
[Used to pick the appropriate disassembler, for debugging])],
|
||||
[AC_MSG_ERROR([cpu $target_cpu not supported])])
|
||||
|
||||
AC_SUBST(cpu)
|
||||
AM_CONDITIONAL(LIGHTNING_MAIN, :)
|
||||
|
||||
AM_CONDITIONAL(REGRESSION_TESTING, test "$host_cpu" = "$target_cpu")
|
||||
|
||||
dnl ---------------------------- COMMAND LINE ---------------------------------
|
||||
|
||||
AC_ARG_ENABLE( assertions,
|
||||
[ --enable-assertions perform internal consistency checks],
|
||||
, enable_assertions=no)
|
||||
|
||||
if test "$enable_assertions" != no; then
|
||||
AC_DEFINE(_ASM_SAFETY, 1, [Define to enable assertions])
|
||||
AC_ARG_ENABLE(disassembler,
|
||||
AS_HELP_STRING([--enable-disassembler],
|
||||
[Enable jit disassembler using binutils]),
|
||||
[DISASSEMBLER=$enableval], [DISASSEMBLER=auto])
|
||||
if test "x$DISASSEMBLER" != "xno"; then
|
||||
# FIXME need to check for libiberty first or will fail to link
|
||||
AC_CHECK_LIB(iberty, htab_try_create, ,
|
||||
[HAVE_IBERTY="no"])
|
||||
AC_CHECK_LIB(bfd, bfd_init, ,
|
||||
[HAVE_BFD="no"])
|
||||
AC_CHECK_LIB(opcodes, init_disassemble_info, ,
|
||||
[HAVE_OPCODES="no"])
|
||||
if test "x$HAVE_IBERTY" = "xno" -o \
|
||||
"x$HAVE_BFD" = "xno" -o \
|
||||
"x$HAVE_OPCODES" = "xno"; then
|
||||
if test "x$DISASSEMBLER" != "xauto"; then
|
||||
AC_MSG_ERROR([binutils not found, see http://www.gnu.org/software/binutils/])
|
||||
else
|
||||
AC_MSG_WARN([binutils not found, see http://www.gnu.org/software/binutils/])
|
||||
DISASSEMBLER="no"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(with_disassembler, [test "x$DISASSEMBLER" != "xno"])
|
||||
if test "x$DISASSEMBLER" != "xno"; then
|
||||
LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DDISASSEMBLER=1"
|
||||
fi
|
||||
|
||||
dnl --------------------------- PRODUCE OUTPUT --------------------------------
|
||||
cpu=
|
||||
case "$target_cpu" in
|
||||
i?x86|x86_64) cpu=x86 ;;
|
||||
*) ;;
|
||||
esac
|
||||
if test x$cpu = x; then
|
||||
AC_MSG_ERROR([cpu $target_cpu not supported])
|
||||
fi
|
||||
AM_CONDITIONAL(cpu_x86, [test cpu-$cpu = cpu-x86])
|
||||
|
||||
AC_CONFIG_FILES(Makefile doc/Makefile tests/Makefile
|
||||
lightning/Makefile)
|
||||
AC_SUBST([LIGHTNING_CFLAGS])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
# A small sanity check
|
||||
echo "#include <stdio.h>" > confdefs.h # dummy input file
|
||||
CPPFLAGS="$CPPFLAGS -I. -I$srcdir -I$srcdir/lightning/$cpu"
|
||||
AC_TRY_COMPILE([#include "lightning.h"], , ,
|
||||
AC_MSG_WARN(the compiler that was found could not compile GNU lightning))
|
||||
AC_OUTPUT([Makefile
|
||||
doc/Makefile
|
||||
include/Makefile
|
||||
include/lightning/Makefile
|
||||
lib/Makefile
|
||||
check/Makefile])
|
||||
|
|
17
include/Makefile.am
Normal file
17
include/Makefile.am
Normal file
|
@ -0,0 +1,17 @@
|
|||
#
|
||||
# Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
|
||||
#
|
||||
# This is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This software is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
|
||||
include_HEADERS = lightning.h
|
||||
SUBDIRS = \
|
||||
lightning
|
852
include/lightning.h
Normal file
852
include/lightning.h
Normal file
|
@ -0,0 +1,852 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#ifndef _lightning_h
|
||||
#define _lightning_h
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef __WORDSIZE
|
||||
# define __WORDSIZE WORDSIZE
|
||||
#endif
|
||||
#ifndef __BYTE_ORDER
|
||||
# define __BYTE_ORDER BYTE_ORDER
|
||||
#endif
|
||||
#ifndef __LITTLE_ENDIAN
|
||||
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#endif
|
||||
#ifndef __BIG_ENDIAN
|
||||
# define __BIG_ENDIAN BIG_ENDIAN
|
||||
#endif
|
||||
|
||||
typedef signed char jit_int8_t;
|
||||
typedef unsigned char jit_uint8_t;
|
||||
typedef signed short jit_int16_t;
|
||||
typedef unsigned short jit_uint16_t;
|
||||
typedef signed int jit_int32_t;
|
||||
typedef unsigned int jit_uint32_t;
|
||||
#if __WORDSIZE == 32
|
||||
typedef signed long long jit_int64_t;
|
||||
typedef unsigned long long jit_uint64_t;
|
||||
typedef jit_int32_t jit_word_t;
|
||||
typedef jit_uint32_t jit_uword_t;
|
||||
#else
|
||||
typedef signed long jit_int64_t;
|
||||
typedef unsigned long jit_uint64_t;
|
||||
typedef jit_int64_t jit_word_t;
|
||||
typedef jit_uint64_t jit_uword_t;
|
||||
#endif
|
||||
typedef float jit_float32_t;
|
||||
typedef double jit_float64_t;
|
||||
typedef void* jit_pointer_t;
|
||||
typedef jit_int32_t jit_bool_t;
|
||||
typedef jit_int32_t jit_gpr_t;
|
||||
typedef jit_int32_t jit_fpr_t;
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
# include <lightning/jit_x86.h>
|
||||
#elif defined(__mips__)
|
||||
# include <lightning/jit_mips.h>
|
||||
#elif defined(__arm__)
|
||||
# include <lightning/jit_arm.h>
|
||||
#elif defined(__ppc__)
|
||||
# include <lightning/jit_ppc.h>
|
||||
#endif
|
||||
|
||||
#define jit_flag_node 0x00000001 /* patch node not absolute */
|
||||
#define jit_flag_patch 0x00000002 /* jump already patched */
|
||||
#define jit_flag_data 0x00000004 /* data in the constant pool */
|
||||
#define jit_flag_use 0x00000008 /* do not remove marker label */
|
||||
#define jit_flag_head 0x00100000 /* label reached by normal flow */
|
||||
|
||||
#define JIT_R(index) jit_r(index)
|
||||
#define JIT_V(index) jit_v(index)
|
||||
#define JIT_F(index) jit_f(index)
|
||||
#define JIT_R_NUM jit_r_num()
|
||||
#define JIT_V_NUM jit_v_num()
|
||||
#define JIT_F_NUM jit_f_num()
|
||||
|
||||
#define jit_class_chk 0x02000000 /* just checking */
|
||||
#define jit_class_arg 0x08000000 /* argument register */
|
||||
#define jit_class_sav 0x10000000 /* callee save */
|
||||
#define jit_class_gpr 0x20000000 /* general purpose */
|
||||
#define jit_class_fpr 0x40000000 /* float */
|
||||
#define jit_class(reg) ((reg) & 0xffff0000)
|
||||
#define jit_regno(reg) ((reg) & 0x00007fff)
|
||||
|
||||
#define jit_call_default 0
|
||||
/* assume only varags functions called are printf like, that is,
|
||||
* without a declared float/double argument */
|
||||
/* FIXME currently no way to create a varargs (or non varargs) jit function
|
||||
* if calling sequence changes for float/double arguments */
|
||||
#define jit_call_varargs 1
|
||||
|
||||
typedef struct jit_node jit_node_t;
|
||||
typedef struct jit_state jit_state_t;
|
||||
|
||||
typedef enum {
|
||||
#define jit_data(u,v) _jit_data(_jit,u,v)
|
||||
jit_code_data,
|
||||
jit_code_save, jit_code_load,
|
||||
#define jit_note(u) jit_new_node_ww(jit_code_note,0,(jit_word_t)u)
|
||||
#define jit_label() _jit_label(_jit)
|
||||
#define jit_forward() _jit_forward(_jit)
|
||||
#define jit_link(u) _jit_link(_jit,u)
|
||||
jit_code_note, jit_code_label,
|
||||
|
||||
#define jit_prolog() _jit_prolog(_jit)
|
||||
jit_code_prolog,
|
||||
|
||||
#define jit_allocai(u) _jit_allocai(_jit,u)
|
||||
|
||||
#define jit_arg() _jit_arg(_jit)
|
||||
#define jit_getarg_c(u,v) _jit_getarg_c(_jit,u,v)
|
||||
#define jit_getarg_uc(u,v) _jit_getarg_uc(_jit,u,v)
|
||||
#define jit_getarg_s(u,v) _jit_getarg_s(_jit,u,v)
|
||||
#define jit_getarg_us(u,v) _jit_getarg_us(_jit,u,v)
|
||||
#define jit_getarg_i(u,v) _jit_getarg_i(_jit,u,v)
|
||||
/* >> 64 bit */
|
||||
#define jit_getarg_ui(u,v) _jit_getarg_ui(_jit,u,v)
|
||||
#define jit_getarg_l(u,v) _jit_getarg_l(_jit,u,v)
|
||||
/* << 64 bit */
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_getarg(u,v) jit_getarg_i(u,v)
|
||||
#else
|
||||
# define jit_getarg(u,v) jit_getarg_l(u,v)
|
||||
#endif
|
||||
|
||||
#define jit_addr(u,v,w) jit_new_node_www(jit_code_addr,u,v,w)
|
||||
#define jit_addi(u,v,w) jit_new_node_www(jit_code_addi,u,v,w)
|
||||
jit_code_addr, jit_code_addi,
|
||||
#define jit_addxr(u,v,w) jit_new_node_www(jit_code_addxr,u,v,w)
|
||||
#define jit_addxi(u,v,w) jit_new_node_www(jit_code_addxi,u,v,w)
|
||||
jit_code_addxr, jit_code_addxi,
|
||||
#define jit_addcr(u,v,w) jit_new_node_www(jit_code_addcr,u,v,w)
|
||||
#define jit_addci(u,v,w) jit_new_node_www(jit_code_addci,u,v,w)
|
||||
jit_code_addcr, jit_code_addci,
|
||||
#define jit_subr(u,v,w) jit_new_node_www(jit_code_subr,u,v,w)
|
||||
#define jit_subi(u,v,w) jit_new_node_www(jit_code_subi,u,v,w)
|
||||
jit_code_subr, jit_code_subi,
|
||||
#define jit_subxr(u,v,w) jit_new_node_www(jit_code_subxr,u,v,w)
|
||||
#define jit_subxi(u,v,w) jit_new_node_www(jit_code_subxi,u,v,w)
|
||||
jit_code_subxr, jit_code_subxi,
|
||||
#define jit_subcr(u,v,w) jit_new_node_www(jit_code_subcr,u,v,w)
|
||||
#define jit_subci(u,v,w) jit_new_node_www(jit_code_subci,u,v,w)
|
||||
jit_code_subcr, jit_code_subci,
|
||||
|
||||
#define jit_mulr(u,v,w) jit_new_node_www(jit_code_mulr,u,v,w)
|
||||
#define jit_muli(u,v,w) jit_new_node_www(jit_code_muli,u,v,w)
|
||||
jit_code_mulr, jit_code_muli,
|
||||
#define jit_divr(u,v,w) jit_new_node_www(jit_code_divr,u,v,w)
|
||||
#define jit_divi(u,v,w) jit_new_node_www(jit_code_divi,u,v,w)
|
||||
jit_code_divr, jit_code_divi,
|
||||
#define jit_divr_u(u,v,w) jit_new_node_www(jit_code_divr_u,u,v,w)
|
||||
#define jit_divi_u(u,v,w) jit_new_node_www(jit_code_divi_u,u,v,w)
|
||||
jit_code_divr_u, jit_code_divi_u,
|
||||
#define jit_remr(u,v,w) jit_new_node_www(jit_code_remr,u,v,w)
|
||||
#define jit_remi(u,v,w) jit_new_node_www(jit_code_remi,u,v,w)
|
||||
jit_code_remr, jit_code_remi,
|
||||
#define jit_remr_u(u,v,w) jit_new_node_www(jit_code_remr_u,u,v,w)
|
||||
#define jit_remi_u(u,v,w) jit_new_node_www(jit_code_remi_u,u,v,w)
|
||||
jit_code_remr_u, jit_code_remi_u,
|
||||
|
||||
#define jit_andr(u,v,w) jit_new_node_www(jit_code_andr,u,v,w)
|
||||
#define jit_andi(u,v,w) jit_new_node_www(jit_code_andi,u,v,w)
|
||||
jit_code_andr, jit_code_andi,
|
||||
#define jit_orr(u,v,w) jit_new_node_www(jit_code_orr,u,v,w)
|
||||
#define jit_ori(u,v,w) jit_new_node_www(jit_code_ori,u,v,w)
|
||||
jit_code_orr, jit_code_ori,
|
||||
#define jit_xorr(u,v,w) jit_new_node_www(jit_code_xorr,u,v,w)
|
||||
#define jit_xori(u,v,w) jit_new_node_www(jit_code_xori,u,v,w)
|
||||
jit_code_xorr, jit_code_xori,
|
||||
|
||||
#define jit_lshr(u,v,w) jit_new_node_www(jit_code_lshr,u,v,w)
|
||||
#define jit_lshi(u,v,w) jit_new_node_www(jit_code_lshi,u,v,w)
|
||||
jit_code_lshr, jit_code_lshi,
|
||||
#define jit_rshr(u,v,w) jit_new_node_www(jit_code_rshr,u,v,w)
|
||||
#define jit_rshi(u,v,w) jit_new_node_www(jit_code_rshi,u,v,w)
|
||||
jit_code_rshr, jit_code_rshi,
|
||||
#define jit_rshr_u(u,v,w) jit_new_node_www(jit_code_rshr_u,u,v,w)
|
||||
#define jit_rshi_u(u,v,w) jit_new_node_www(jit_code_rshi_u,u,v,w)
|
||||
jit_code_rshr_u, jit_code_rshi_u,
|
||||
|
||||
#define jit_negr(u,v) jit_new_node_ww(jit_code_negr,u,v)
|
||||
#define jit_comr(u,v) jit_new_node_ww(jit_code_comr,u,v)
|
||||
jit_code_negr, jit_code_comr,
|
||||
|
||||
#define jit_ltr(u,v,w) jit_new_node_www(jit_code_ltr,u,v,w)
|
||||
#define jit_lti(u,v,w) jit_new_node_www(jit_code_lti,u,v,w)
|
||||
jit_code_ltr, jit_code_lti,
|
||||
#define jit_ltr_u(u,v,w) jit_new_node_www(jit_code_ltr_u,u,v,w)
|
||||
#define jit_lti_u(u,v,w) jit_new_node_www(jit_code_lti_u,u,v,w)
|
||||
jit_code_ltr_u, jit_code_lti_u,
|
||||
#define jit_ler(u,v,w) jit_new_node_www(jit_code_ler,u,v,w)
|
||||
#define jit_lei(u,v,w) jit_new_node_www(jit_code_lei,u,v,w)
|
||||
jit_code_ler, jit_code_lei,
|
||||
#define jit_ler_u(u,v,w) jit_new_node_www(jit_code_ler_u,u,v,w)
|
||||
#define jit_lei_u(u,v,w) jit_new_node_www(jit_code_lei_u,u,v,w)
|
||||
jit_code_ler_u, jit_code_lei_u,
|
||||
#define jit_eqr(u,v,w) jit_new_node_www(jit_code_eqr,u,v,w)
|
||||
#define jit_eqi(u,v,w) jit_new_node_www(jit_code_eqi,u,v,w)
|
||||
jit_code_eqr, jit_code_eqi,
|
||||
#define jit_ger(u,v,w) jit_new_node_www(jit_code_ger,u,v,w)
|
||||
#define jit_gei(u,v,w) jit_new_node_www(jit_code_gei,u,v,w)
|
||||
jit_code_ger, jit_code_gei,
|
||||
#define jit_ger_u(u,v,w) jit_new_node_www(jit_code_ger_u,u,v,w)
|
||||
#define jit_gei_u(u,v,w) jit_new_node_www(jit_code_gei_u,u,v,w)
|
||||
jit_code_ger_u, jit_code_gei_u,
|
||||
#define jit_gtr(u,v,w) jit_new_node_www(jit_code_gtr,u,v,w)
|
||||
#define jit_gti(u,v,w) jit_new_node_www(jit_code_gti,u,v,w)
|
||||
jit_code_gtr, jit_code_gti,
|
||||
#define jit_gtr_u(u,v,w) jit_new_node_www(jit_code_gtr_u,u,v,w)
|
||||
#define jit_gti_u(u,v,w) jit_new_node_www(jit_code_gti_u,u,v,w)
|
||||
jit_code_gtr_u, jit_code_gti_u,
|
||||
#define jit_ner(u,v,w) jit_new_node_www(jit_code_ner,u,v,w)
|
||||
#define jit_nei(u,v,w) jit_new_node_www(jit_code_nei,u,v,w)
|
||||
jit_code_ner, jit_code_nei,
|
||||
|
||||
#define jit_movr(u,v) jit_new_node_ww(jit_code_movr,u,v)
|
||||
#define jit_movi(u,v) jit_new_node_ww(jit_code_movi,u,v)
|
||||
jit_code_movr, jit_code_movi,
|
||||
#define jit_extr_c(u,v) jit_new_node_ww(jit_code_extr_c,u,v)
|
||||
#define jit_extr_uc(u,v) jit_new_node_ww(jit_code_extr_uc,u,v)
|
||||
jit_code_extr_c, jit_code_extr_uc,
|
||||
#define jit_extr_s(u,v) jit_new_node_ww(jit_code_extr_s,u,v)
|
||||
#define jit_extr_us(u,v) jit_new_node_ww(jit_code_extr_us,u,v)
|
||||
jit_code_extr_s, jit_code_extr_us,
|
||||
/* >> 64 bit */
|
||||
#define jit_extr_i(u,v) jit_new_node_ww(jit_code_extr_i,u,v)
|
||||
#define jit_extr_ui(u,v) jit_new_node_ww(jit_code_extr_ui,u,v)
|
||||
jit_code_extr_i, jit_code_extr_ui,
|
||||
/* << 64 bit */
|
||||
#define jit_htonr(u,v) jit_new_node_ww(jit_code_htonr,u,v)
|
||||
#define jit_ntohr(u,v) jit_new_node_ww(jit_code_htonr,u,v)
|
||||
jit_code_htonr,
|
||||
|
||||
#define jit_ldr_c(u,v) jit_new_node_ww(jit_code_ldr_c,u,v)
|
||||
#define jit_ldi_c(u,v) jit_new_node_ww(jit_code_ldi_c,u,v)
|
||||
jit_code_ldr_c, jit_code_ldi_c,
|
||||
#define jit_ldr_uc(u,v) jit_new_node_ww(jit_code_ldr_uc,u,v)
|
||||
#define jit_ldi_uc(u,v) jit_new_node_ww(jit_code_ldi_uc,u,v)
|
||||
jit_code_ldr_uc, jit_code_ldi_uc,
|
||||
#define jit_ldr_s(u,v) jit_new_node_ww(jit_code_ldr_s,u,v)
|
||||
#define jit_ldi_s(u,v) jit_new_node_ww(jit_code_ldi_s,u,v)
|
||||
jit_code_ldr_s, jit_code_ldi_s,
|
||||
#define jit_ldr_us(u,v) jit_new_node_ww(jit_code_ldr_us,u,v)
|
||||
#define jit_ldi_us(u,v) jit_new_node_ww(jit_code_ldi_us,u,v)
|
||||
jit_code_ldr_us, jit_code_ldi_us,
|
||||
#define jit_ldr_i(u,v) jit_new_node_ww(jit_code_ldr_i,u,v)
|
||||
#define jit_ldi_i(u,v) jit_new_node_ww(jit_code_ldi_i,u,v)
|
||||
jit_code_ldr_i, jit_code_ldi_i,
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_ldr(u,v) jit_ldr_i(u,v)
|
||||
# define jit_ldi(u,v) jit_ldi_i(u,v)
|
||||
#else
|
||||
# define jit_ldr(u,v) jit_ldr_l(u,v)
|
||||
# define jit_ldi(u,v) jit_ldi_l(u,v)
|
||||
#endif
|
||||
/* >> 64 bit */
|
||||
#define jit_ldr_ui(u,v) jit_new_node_ww(jit_code_ldr_ui,u,v)
|
||||
#define jit_ldi_ui(u,v) jit_new_node_ww(jit_code_ldi_ui,u,v)
|
||||
jit_code_ldr_ui, jit_code_ldi_ui,
|
||||
#define jit_ldr_l(u,v) jit_new_node_ww(jit_code_ldr_l,u,v)
|
||||
#define jit_ldi_l(u,v) jit_new_node_ww(jit_code_ldi_l,u,v)
|
||||
jit_code_ldr_l, jit_code_ldi_l,
|
||||
/* << 64 bit */
|
||||
|
||||
#define jit_ldxr_c(u,v,w) jit_new_node_www(jit_code_ldxr_c,u,v,w)
|
||||
#define jit_ldxi_c(u,v,w) jit_new_node_www(jit_code_ldxi_c,u,v,w)
|
||||
jit_code_ldxr_c, jit_code_ldxi_c,
|
||||
#define jit_ldxr_uc(u,v,w) jit_new_node_www(jit_code_ldxr_uc,u,v,w)
|
||||
#define jit_ldxi_uc(u,v,w) jit_new_node_www(jit_code_ldxi_uc,u,v,w)
|
||||
jit_code_ldxr_uc, jit_code_ldxi_uc,
|
||||
#define jit_ldxr_s(u,v,w) jit_new_node_www(jit_code_ldxr_s,u,v,w)
|
||||
#define jit_ldxi_s(u,v,w) jit_new_node_www(jit_code_ldxi_s,u,v,w)
|
||||
jit_code_ldxr_s, jit_code_ldxi_s,
|
||||
#define jit_ldxr_us(u,v,w) jit_new_node_www(jit_code_ldxr_us,u,v,w)
|
||||
#define jit_ldxi_us(u,v,w) jit_new_node_www(jit_code_ldxi_us,u,v,w)
|
||||
jit_code_ldxr_us, jit_code_ldxi_us,
|
||||
#define jit_ldxr_i(u,v,w) jit_new_node_www(jit_code_ldxr_i,u,v,w)
|
||||
#define jit_ldxi_i(u,v,w) jit_new_node_www(jit_code_ldxi_i,u,v,w)
|
||||
jit_code_ldxr_i, jit_code_ldxi_i,
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_ldxr(u,v,w) jit_ldxr_i(u,v,w)
|
||||
# define jit_ldxi(u,v,w) jit_ldxi_i(u,v,w)
|
||||
#else
|
||||
# define jit_ldxr_ui(u,v,w) jit_new_node_www(jit_code_ldxr_ui,u,v,w)
|
||||
# define jit_ldxi_ui(u,v,w) jit_new_node_www(jit_code_ldxi_ui,u,v,w)
|
||||
# define jit_ldxr_l(u,v,w) jit_new_node_www(jit_code_ldxr_l,u,v,w)
|
||||
# define jit_ldxi_l(u,v,w) jit_new_node_www(jit_code_ldxi_l,u,v,w)
|
||||
# define jit_ldxr(u,v,w) jit_ldxr_l(u,v,w)
|
||||
# define jit_ldxi(u,v,w) jit_ldxi_l(u,v,w)
|
||||
#endif
|
||||
jit_code_ldxr_ui, jit_code_ldxi_ui,
|
||||
jit_code_ldxr_l, jit_code_ldxi_l,
|
||||
|
||||
#define jit_str_c(u,v) jit_new_node_ww(jit_code_str_c,u,v)
|
||||
#define jit_sti_c(u,v) jit_new_node_ww(jit_code_sti_c,u,v)
|
||||
jit_code_str_c, jit_code_sti_c,
|
||||
#define jit_str_s(u,v) jit_new_node_ww(jit_code_str_s,u,v)
|
||||
#define jit_sti_s(u,v) jit_new_node_ww(jit_code_sti_s,u,v)
|
||||
jit_code_str_s, jit_code_sti_s,
|
||||
#define jit_str_i(u,v) jit_new_node_ww(jit_code_str_i,u,v)
|
||||
#define jit_sti_i(u,v) jit_new_node_ww(jit_code_sti_i,u,v)
|
||||
jit_code_str_i, jit_code_sti_i,
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_str(u,v) jit_str_i(u,v)
|
||||
# define jit_sti(u,v) jit_sti_i(u,v)
|
||||
#else
|
||||
#define jit_str(u,v) jit_str_l(u,v)
|
||||
#define jit_sti(u,v) jit_sti_l(u,v)
|
||||
#endif
|
||||
/* >> 64 bit */
|
||||
#define jit_str_l(u,v) jit_new_node_ww(jit_code_str_l,u,v)
|
||||
#define jit_sti_l(u,v) jit_new_node_ww(jit_code_sti_l,u,v)
|
||||
jit_code_str_l, jit_code_sti_l,
|
||||
/* << 64 bit */
|
||||
|
||||
#define jit_stxr_c(u,v,w) jit_new_node_www(jit_code_stxr_c,u,v,w)
|
||||
#define jit_stxi_c(u,v,w) jit_new_node_www(jit_code_stxi_c,u,v,w)
|
||||
jit_code_stxr_c, jit_code_stxi_c,
|
||||
#define jit_stxr_s(u,v,w) jit_new_node_www(jit_code_stxr_s,u,v,w)
|
||||
#define jit_stxi_s(u,v,w) jit_new_node_www(jit_code_stxi_s,u,v,w)
|
||||
jit_code_stxr_s, jit_code_stxi_s,
|
||||
#define jit_stxr_i(u,v,w) jit_new_node_www(jit_code_stxr_i,u,v,w)
|
||||
#define jit_stxi_i(u,v,w) jit_new_node_www(jit_code_stxi_i,u,v,w)
|
||||
jit_code_stxr_i, jit_code_stxi_i,
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_stxr(u,v,w) jit_stxr_i(u,v,w)
|
||||
# define jit_stxi(u,v,w) jit_stxi_i(u,v,w)
|
||||
#else
|
||||
# define jit_stxr_l(u,v,w) jit_new_node_www(jit_code_stxr_l,u,v,w)
|
||||
# define jit_stxi_l(u,v,w) jit_new_node_www(jit_code_stxi_l,u,v,w)
|
||||
#endif
|
||||
/* >> 64 bit */
|
||||
#define jit_stxr(u,v,w) jit_stxr_l(u,v,w)
|
||||
#define jit_stxi(u,v,w) jit_stxi_l(u,v,w)
|
||||
jit_code_stxr_l, jit_code_stxi_l,
|
||||
/* << 64 bit */
|
||||
|
||||
#define jit_bltr(v,w) jit_new_node_pww(jit_code_bltr,NULL,v,w)
|
||||
#define jit_blti(v,w) jit_new_node_pww(jit_code_blti,NULL,v,w)
|
||||
jit_code_bltr, jit_code_blti,
|
||||
#define jit_bltr_u(v,w) jit_new_node_pww(jit_code_bltr_u,NULL,v,w)
|
||||
#define jit_blti_u(v,w) jit_new_node_pww(jit_code_blti_u,NULL,v,w)
|
||||
jit_code_bltr_u, jit_code_blti_u,
|
||||
#define jit_bler(v,w) jit_new_node_pww(jit_code_bler,NULL,v,w)
|
||||
#define jit_blei(v,w) jit_new_node_pww(jit_code_blei,NULL,v,w)
|
||||
jit_code_bler, jit_code_blei,
|
||||
#define jit_bler_u(v,w) jit_new_node_pww(jit_code_bler_u,NULL,v,w)
|
||||
#define jit_blei_u(v,w) jit_new_node_pww(jit_code_blei_u,NULL,v,w)
|
||||
jit_code_bler_u, jit_code_blei_u,
|
||||
#define jit_beqr(v,w) jit_new_node_pww(jit_code_beqr,NULL,v,w)
|
||||
#define jit_beqi(v,w) jit_new_node_pww(jit_code_beqi,NULL,v,w)
|
||||
jit_code_beqr, jit_code_beqi,
|
||||
#define jit_bger(v,w) jit_new_node_pww(jit_code_bger,NULL,v,w)
|
||||
#define jit_bgei(v,w) jit_new_node_pww(jit_code_bgei,NULL,v,w)
|
||||
jit_code_bger, jit_code_bgei,
|
||||
#define jit_bger_u(v,w) jit_new_node_pww(jit_code_bger_u,NULL,v,w)
|
||||
#define jit_bgei_u(v,w) jit_new_node_pww(jit_code_bgei_u,NULL,v,w)
|
||||
jit_code_bger_u, jit_code_bgei_u,
|
||||
#define jit_bgtr(v,w) jit_new_node_pww(jit_code_bgtr,NULL,v,w)
|
||||
#define jit_bgti(v,w) jit_new_node_pww(jit_code_bgti,NULL,v,w)
|
||||
jit_code_bgtr, jit_code_bgti,
|
||||
#define jit_bgtr_u(v,w) jit_new_node_pww(jit_code_bgtr_u,NULL,v,w)
|
||||
#define jit_bgti_u(v,w) jit_new_node_pww(jit_code_bgti_u,NULL,v,w)
|
||||
jit_code_bgtr_u, jit_code_bgti_u,
|
||||
#define jit_bner(v,w) jit_new_node_pww(jit_code_bner,NULL,v,w)
|
||||
#define jit_bnei(v,w) jit_new_node_pww(jit_code_bnei,NULL,v,w)
|
||||
jit_code_bner, jit_code_bnei,
|
||||
|
||||
#define jit_bmsr(v,w) jit_new_node_pww(jit_code_bmsr,NULL,v,w)
|
||||
#define jit_bmsi(v,w) jit_new_node_pww(jit_code_bmsi,NULL,v,w)
|
||||
jit_code_bmsr, jit_code_bmsi,
|
||||
#define jit_bmcr(v,w) jit_new_node_pww(jit_code_bmcr,NULL,v,w)
|
||||
#define jit_bmci(v,w) jit_new_node_pww(jit_code_bmci,NULL,v,w)
|
||||
jit_code_bmcr, jit_code_bmci,
|
||||
|
||||
#define jit_boaddr(v,w) jit_new_node_pww(jit_code_boaddr,NULL,v,w)
|
||||
#define jit_boaddi(v,w) jit_new_node_pww(jit_code_boaddi,NULL,v,w)
|
||||
jit_code_boaddr, jit_code_boaddi,
|
||||
#define jit_boaddr_u(v,w) jit_new_node_pww(jit_code_boaddr_u,NULL,v,w)
|
||||
#define jit_boaddi_u(v,w) jit_new_node_pww(jit_code_boaddi_u,NULL,v,w)
|
||||
jit_code_boaddr_u, jit_code_boaddi_u,
|
||||
#define jit_bxaddr(v,w) jit_new_node_pww(jit_code_bxaddr,NULL,v,w)
|
||||
#define jit_bxaddi(v,w) jit_new_node_pww(jit_code_bxaddi,NULL,v,w)
|
||||
jit_code_bxaddr, jit_code_bxaddi,
|
||||
#define jit_bxaddr_u(v,w) jit_new_node_pww(jit_code_bxaddr_u,NULL,v,w)
|
||||
#define jit_bxaddi_u(v,w) jit_new_node_pww(jit_code_bxaddi_u,NULL,v,w)
|
||||
jit_code_bxaddr_u, jit_code_bxaddi_u,
|
||||
#define jit_bosubr(v,w) jit_new_node_pww(jit_code_bosubr,NULL,v,w)
|
||||
#define jit_bosubi(v,w) jit_new_node_pww(jit_code_bosubi,NULL,v,w)
|
||||
jit_code_bosubr, jit_code_bosubi,
|
||||
#define jit_bosubr_u(v,w) jit_new_node_pww(jit_code_bosubr_u,NULL,v,w)
|
||||
#define jit_bosubi_u(v,w) jit_new_node_pww(jit_code_bosubi_u,NULL,v,w)
|
||||
jit_code_bosubr_u, jit_code_bosubi_u,
|
||||
#define jit_bxsubr(v,w) jit_new_node_pww(jit_code_bxsubr,NULL,v,w)
|
||||
#define jit_bxsubi(v,w) jit_new_node_pww(jit_code_bxsubi,NULL,v,w)
|
||||
jit_code_bxsubr, jit_code_bxsubi,
|
||||
#define jit_bxsubr_u(v,w) jit_new_node_pww(jit_code_bxsubr_u,NULL,v,w)
|
||||
#define jit_bxsubi_u(v,w) jit_new_node_pww(jit_code_bxsubi_u,NULL,v,w)
|
||||
jit_code_bxsubr_u, jit_code_bxsubi_u,
|
||||
|
||||
#define jit_jmpr(u) jit_new_node_w(jit_code_jmpr,u)
|
||||
#define jit_jmpi() jit_new_node_p(jit_code_jmpi,NULL)
|
||||
jit_code_jmpr, jit_code_jmpi,
|
||||
#define jit_callr(u) jit_new_node_w(jit_code_callr,u)
|
||||
#define jit_calli(u) jit_new_node_p(jit_code_calli,u)
|
||||
jit_code_callr, jit_code_calli,
|
||||
|
||||
#define jit_prepare(u) _jit_prepare(_jit,u)
|
||||
#define jit_pushargr(u) _jit_pushargr(_jit,u)
|
||||
#define jit_pushargi(u) _jit_pushargi(_jit,u)
|
||||
#define jit_finishr(u) _jit_finishr(_jit,u)
|
||||
#define jit_finishi(u) _jit_finishi(_jit,u)
|
||||
#define jit_ret() _jit_ret(_jit)
|
||||
#define jit_retr(u) _jit_retr(_jit,u)
|
||||
#define jit_reti(u) _jit_reti(_jit,u)
|
||||
#define jit_retval_c(u) _jit_retval_c(_jit,u)
|
||||
#define jit_retval_uc(u) _jit_retval_uc(_jit,u)
|
||||
#define jit_retval_s(u) _jit_retval_s(_jit,u)
|
||||
#define jit_retval_us(u) _jit_retval_us(_jit,u)
|
||||
#define jit_retval_i(u) _jit_retval_i(_jit,u)
|
||||
/* >> 64 bit */
|
||||
#define jit_retval_ui(u) _jit_retval_ui(_jit,u)
|
||||
#define jit_retval_l(u) _jit_retval_l(_jit,u)
|
||||
/* << 64 bit */
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_retval(u) jit_retval_i(u)
|
||||
#else
|
||||
# define jit_retval(u) jit_retval_l(u)
|
||||
#endif
|
||||
/* Usually should not need to call directly, but useful if need
|
||||
* to get a label just before a jit_prolog() call */
|
||||
#define jit_epilog() _jit_epilog(_jit)
|
||||
jit_code_epilog,
|
||||
|
||||
#define jit_arg_f() _jit_arg_f(_jit)
|
||||
#define jit_getarg_f(u,v) _jit_getarg_f(_jit,u,v)
|
||||
|
||||
#define jit_addr_f(u,v,w) jit_new_node_www(jit_code_addr_f,u,v,w)
|
||||
#define jit_addi_f(u,v,w) jit_new_node_wwf(jit_code_addi_f,u,v,w)
|
||||
jit_code_addr_f, jit_code_addi_f,
|
||||
#define jit_subr_f(u,v,w) jit_new_node_www(jit_code_subr_f,u,v,w)
|
||||
#define jit_subi_f(u,v,w) jit_new_node_wwf(jit_code_subi_f,u,v,w)
|
||||
jit_code_subr_f, jit_code_subi_f,
|
||||
#define jit_mulr_f(u,v,w) jit_new_node_www(jit_code_mulr_f,u,v,w)
|
||||
#define jit_muli_f(u,v,w) jit_new_node_wwf(jit_code_muli_f,u,v,w)
|
||||
jit_code_mulr_f, jit_code_muli_f,
|
||||
#define jit_divr_f(u,v,w) jit_new_node_www(jit_code_divr_f,u,v,w)
|
||||
#define jit_divi_f(u,v,w) jit_new_node_wwf(jit_code_divi_f,u,v,w)
|
||||
jit_code_divr_f, jit_code_divi_f,
|
||||
#define jit_negr_f(u,v) jit_new_node_ww(jit_code_negr_f,u,v)
|
||||
#define jit_absr_f(u,v) jit_new_node_ww(jit_code_absr_f,u,v)
|
||||
#define jit_sqrtr_f(u,v) jit_new_node_ww(jit_code_sqrtr_f,u,v)
|
||||
jit_code_negr_f, jit_code_absr_f, jit_code_sqrtr_f,
|
||||
|
||||
#define jit_ltr_f(u,v,w) jit_new_node_www(jit_code_ltr_f,u,v,w)
|
||||
#define jit_lti_f(u,v,w) jit_new_node_wwf(jit_code_lti_f,u,v,w)
|
||||
jit_code_ltr_f, jit_code_lti_f,
|
||||
#define jit_ler_f(u,v,w) jit_new_node_www(jit_code_ler_f,u,v,w)
|
||||
#define jit_lei_f(u,v,w) jit_new_node_wwf(jit_code_lei_f,u,v,w)
|
||||
jit_code_ler_f, jit_code_lei_f,
|
||||
#define jit_eqr_f(u,v,w) jit_new_node_www(jit_code_eqr_f,u,v,w)
|
||||
#define jit_eqi_f(u,v,w) jit_new_node_wwf(jit_code_eqi_f,u,v,w)
|
||||
jit_code_eqr_f, jit_code_eqi_f,
|
||||
#define jit_ger_f(u,v,w) jit_new_node_www(jit_code_ger_f,u,v,w)
|
||||
#define jit_gei_f(u,v,w) jit_new_node_wwf(jit_code_gei_f,u,v,w)
|
||||
jit_code_ger_f, jit_code_gei_f,
|
||||
#define jit_gtr_f(u,v,w) jit_new_node_www(jit_code_gtr_f,u,v,w)
|
||||
#define jit_gti_f(u,v,w) jit_new_node_wwf(jit_code_gti_f,u,v,w)
|
||||
jit_code_gtr_f, jit_code_gti_f,
|
||||
#define jit_ner_f(u,v,w) jit_new_node_www(jit_code_ner_f,u,v,w)
|
||||
#define jit_nei_f(u,v,w) jit_new_node_wwf(jit_code_nei_f,u,v,w)
|
||||
jit_code_ner_f, jit_code_nei_f,
|
||||
#define jit_unltr_f(u,v,w) jit_new_node_www(jit_code_unltr_f,u,v,w)
|
||||
#define jit_unlti_f(u,v,w) jit_new_node_wwf(jit_code_unlti_f,u,v,w)
|
||||
jit_code_unltr_f, jit_code_unlti_f,
|
||||
#define jit_unler_f(u,v,w) jit_new_node_www(jit_code_unler_f,u,v,w)
|
||||
#define jit_unlei_f(u,v,w) jit_new_node_wwf(jit_code_unlei_f,u,v,w)
|
||||
jit_code_unler_f, jit_code_unlei_f,
|
||||
#define jit_uneqr_f(u,v,w) jit_new_node_www(jit_code_uneqr_f,u,v,w)
|
||||
#define jit_uneqi_f(u,v,w) jit_new_node_wwf(jit_code_uneqi_f,u,v,w)
|
||||
jit_code_uneqr_f, jit_code_uneqi_f,
|
||||
#define jit_unger_f(u,v,w) jit_new_node_www(jit_code_unger_f,u,v,w)
|
||||
#define jit_ungei_f(u,v,w) jit_new_node_wwf(jit_code_ungei_f,u,v,w)
|
||||
jit_code_unger_f, jit_code_ungei_f,
|
||||
#define jit_ungtr_f(u,v,w) jit_new_node_www(jit_code_ungtr_f,u,v,w)
|
||||
#define jit_ungti_f(u,v,w) jit_new_node_wwf(jit_code_ungti_f,u,v,w)
|
||||
jit_code_ungtr_f, jit_code_ungti_f,
|
||||
#define jit_ltgtr_f(u,v,w) jit_new_node_www(jit_code_ltgtr_f,u,v,w)
|
||||
#define jit_ltgti_f(u,v,w) jit_new_node_wwf(jit_code_ltgti_f,u,v,w)
|
||||
jit_code_ltgtr_f, jit_code_ltgti_f,
|
||||
#define jit_ordr_f(u,v,w) jit_new_node_www(jit_code_ordr_f,u,v,w)
|
||||
#define jit_ordi_f(u,v,w) jit_new_node_wwf(jit_code_ordi_f,u,v,w)
|
||||
jit_code_ordr_f, jit_code_ordi_f,
|
||||
#define jit_unordr_f(u,v,w) jit_new_node_www(jit_code_unordr_f,u,v,w)
|
||||
#define jit_unordi_f(u,v,w) jit_new_node_wwf(jit_code_unordi_f,u,v,w)
|
||||
jit_code_unordr_f, jit_code_unordi_f,
|
||||
|
||||
#define jit_truncr_f_i(u,v) jit_new_node_ww(jit_code_truncr_f_i,u,v)
|
||||
jit_code_truncr_f_i,
|
||||
#if __WODSIZE == 32
|
||||
# define jit_truncr_f(u,v) jit_truncr_f_i(u,v)
|
||||
#else
|
||||
# define jit_truncr_f(u,v) jit_truncr_f_l(u,v)
|
||||
#endif
|
||||
/* >> 64 bit */
|
||||
#define jit_truncr_f_l(u,v) jit_new_node_ww(jit_code_truncr_f_l,u,v)
|
||||
jit_code_truncr_f_l,
|
||||
/* << 64 bit */
|
||||
#define jit_extr_f(u,v) jit_new_node_ww(jit_code_extr_f,u,v)
|
||||
#define jit_extr_d_f(u,v) jit_new_node_ww(jit_code_extr_d_f,u,v)
|
||||
jit_code_extr_f, jit_code_extr_d_f,
|
||||
#define jit_movr_f(u,v) jit_new_node_ww(jit_code_movr_f,u,v)
|
||||
#define jit_movi_f(u,v) jit_new_node_wf(jit_code_movi_f,u,v)
|
||||
jit_code_movr_f, jit_code_movi_f,
|
||||
|
||||
#define jit_ldr_f(u,v) jit_new_node_ww(jit_code_ldr_f,u,v)
|
||||
#define jit_ldi_f(u,v) jit_new_node_ww(jit_code_ldi_f,u,v)
|
||||
jit_code_ldr_f, jit_code_ldi_f,
|
||||
#define jit_ldxr_f(u,v,w) jit_new_node_www(jit_code_ldxr_f,u,v,w)
|
||||
#define jit_ldxi_f(u,v,w) jit_new_node_www(jit_code_ldxi_f,u,v,w)
|
||||
jit_code_ldxr_f, jit_code_ldxi_f,
|
||||
#define jit_str_f(u,v) jit_new_node_ww(jit_code_str_f,u,v)
|
||||
#define jit_sti_f(u,v) jit_new_node_ww(jit_code_sti_f,u,v)
|
||||
jit_code_str_f, jit_code_sti_f,
|
||||
#define jit_stxr_f(u,v,w) jit_new_node_www(jit_code_stxr_f,u,v,w)
|
||||
#define jit_stxi_f(u,v,w) jit_new_node_www(jit_code_stxi_f,u,v,w)
|
||||
jit_code_stxr_f, jit_code_stxi_f,
|
||||
|
||||
#define jit_bltr_f(v,w) jit_new_node_pww(jit_code_bltr_f,NULL,v,w)
|
||||
#define jit_blti_f(v,w) jit_new_node_pwf(jit_code_blti_f,NULL,v,w)
|
||||
jit_code_bltr_f, jit_code_blti_f,
|
||||
#define jit_bler_f(v,w) jit_new_node_pww(jit_code_bler_f,NULL,v,w)
|
||||
#define jit_blei_f(v,w) jit_new_node_pwf(jit_code_blei_f,NULL,v,w)
|
||||
jit_code_bler_f, jit_code_blei_f,
|
||||
#define jit_beqr_f(v,w) jit_new_node_pww(jit_code_beqr_f,NULL,v,w)
|
||||
#define jit_beqi_f(v,w) jit_new_node_pwf(jit_code_beqi_f,NULL,v,w)
|
||||
jit_code_beqr_f, jit_code_beqi_f,
|
||||
#define jit_bger_f(v,w) jit_new_node_pww(jit_code_bger_f,NULL,v,w)
|
||||
#define jit_bgei_f(v,w) jit_new_node_pwf(jit_code_bgei_f,NULL,v,w)
|
||||
jit_code_bger_f, jit_code_bgei_f,
|
||||
#define jit_bgtr_f(v,w) jit_new_node_pww(jit_code_bgtr_f,NULL,v,w)
|
||||
#define jit_bgti_f(v,w) jit_new_node_pwf(jit_code_bgti_f,NULL,v,w)
|
||||
jit_code_bgtr_f, jit_code_bgti_f,
|
||||
#define jit_bner_f(v,w) jit_new_node_pww(jit_code_bner_f,NULL,v,w)
|
||||
#define jit_bnei_f(v,w) jit_new_node_pwf(jit_code_bnei_f,NULL,v,w)
|
||||
jit_code_bner_f, jit_code_bnei_f,
|
||||
#define jit_bunltr_f(v,w) jit_new_node_pww(jit_code_bunltr_f,NULL,v,w)
|
||||
#define jit_bunlti_f(v,w) jit_new_node_pwf(jit_code_bunlti_f,NULL,v,w)
|
||||
jit_code_bunltr_f, jit_code_bunlti_f,
|
||||
#define jit_bunler_f(v,w) jit_new_node_pww(jit_code_bunler_f,NULL,v,w)
|
||||
#define jit_bunlei_f(v,w) jit_new_node_pwf(jit_code_bunlei_f,NULL,v,w)
|
||||
jit_code_bunler_f, jit_code_bunlei_f,
|
||||
#define jit_buneqr_f(v,w) jit_new_node_pww(jit_code_buneqr_f,NULL,v,w)
|
||||
#define jit_buneqi_f(v,w) jit_new_node_pwf(jit_code_buneqi_f,NULL,v,w)
|
||||
jit_code_buneqr_f, jit_code_buneqi_f,
|
||||
#define jit_bunger_f(v,w) jit_new_node_pww(jit_code_bunger_f,NULL,v,w)
|
||||
#define jit_bungei_f(v,w) jit_new_node_pwf(jit_code_bungei_f,NULL,v,w)
|
||||
jit_code_bunger_f, jit_code_bungei_f,
|
||||
#define jit_bungtr_f(v,w) jit_new_node_pww(jit_code_bungtr_f,NULL,v,w)
|
||||
#define jit_bungti_f(v,w) jit_new_node_pwf(jit_code_bungti_f,NULL,v,w)
|
||||
jit_code_bungtr_f, jit_code_bungti_f,
|
||||
#define jit_bltgtr_f(v,w) jit_new_node_pww(jit_code_bltgtr_f,NULL,v,w)
|
||||
#define jit_bltgti_f(v,w) jit_new_node_pwf(jit_code_bltgti_f,NULL,v,w)
|
||||
jit_code_bltgtr_f, jit_code_bltgti_f,
|
||||
#define jit_bordr_f(v,w) jit_new_node_pww(jit_code_bordr_f,NULL,v,w)
|
||||
#define jit_bordi_f(v,w) jit_new_node_pwf(jit_code_bordi_f,NULL,v,w)
|
||||
jit_code_bordr_f, jit_code_bordi_f,
|
||||
#define jit_bunordr_f(v,w) jit_new_node_pww(jit_code_bunordr_f,NULL,v,w)
|
||||
#define jit_bunordi_f(v,w) jit_new_node_pwf(jit_code_bunordi_f,NULL,v,w)
|
||||
jit_code_bunordr_f, jit_code_bunordi_f,
|
||||
|
||||
#define jit_pushargr_f(u) _jit_pushargr_f(_jit,u)
|
||||
#define jit_pushargi_f(u) _jit_pushargi_f(_jit,u)
|
||||
#define jit_retr_f(u) _jit_retr_f(_jit,u)
|
||||
#define jit_reti_f(u) _jit_reti_f(_jit,u)
|
||||
#define jit_retval_f(u) _jit_retval_f(_jit,u)
|
||||
jit_code_retval_f,
|
||||
|
||||
#define jit_arg_d() _jit_arg_d(_jit)
|
||||
#define jit_getarg_d(u,v) _jit_getarg_d(_jit,u,v)
|
||||
|
||||
#define jit_addr_d(u,v,w) jit_new_node_www(jit_code_addr_d,u,v,w)
|
||||
#define jit_addi_d(u,v,w) jit_new_node_wwd(jit_code_addi_d,u,v,w)
|
||||
jit_code_addr_d, jit_code_addi_d,
|
||||
#define jit_subr_d(u,v,w) jit_new_node_www(jit_code_subr_d,u,v,w)
|
||||
#define jit_subi_d(u,v,w) jit_new_node_wwd(jit_code_subi_d,u,v,w)
|
||||
jit_code_subr_d, jit_code_subi_d,
|
||||
#define jit_mulr_d(u,v,w) jit_new_node_www(jit_code_mulr_d,u,v,w)
|
||||
#define jit_muli_d(u,v,w) jit_new_node_wwd(jit_code_muli_d,u,v,w)
|
||||
jit_code_mulr_d, jit_code_muli_d,
|
||||
#define jit_divr_d(u,v,w) jit_new_node_www(jit_code_divr_d,u,v,w)
|
||||
#define jit_divi_d(u,v,w) jit_new_node_wwd(jit_code_divi_d,u,v,w)
|
||||
jit_code_divr_d, jit_code_divi_d,
|
||||
|
||||
#define jit_negr_d(u,v) jit_new_node_ww(jit_code_negr_d,u,v)
|
||||
#define jit_absr_d(u,v) jit_new_node_ww(jit_code_absr_d,u,v)
|
||||
#define jit_sqrtr_d(u,v) jit_new_node_ww(jit_code_sqrtr_d,u,v)
|
||||
jit_code_negr_d, jit_code_absr_d, jit_code_sqrtr_d,
|
||||
|
||||
#define jit_ltr_d(u,v,w) jit_new_node_www(jit_code_ltr_d,u,v,w)
|
||||
#define jit_lti_d(u,v,w) jit_new_node_wwd(jit_code_lti_d,u,v,w)
|
||||
jit_code_ltr_d, jit_code_lti_d,
|
||||
#define jit_ler_d(u,v,w) jit_new_node_www(jit_code_ler_d,u,v,w)
|
||||
#define jit_lei_d(u,v,w) jit_new_node_wwd(jit_code_lei_d,u,v,w)
|
||||
jit_code_ler_d, jit_code_lei_d,
|
||||
#define jit_eqr_d(u,v,w) jit_new_node_www(jit_code_eqr_d,u,v,w)
|
||||
#define jit_eqi_d(u,v,w) jit_new_node_wwd(jit_code_eqi_d,u,v,w)
|
||||
jit_code_eqr_d, jit_code_eqi_d,
|
||||
#define jit_ger_d(u,v,w) jit_new_node_www(jit_code_ger_d,u,v,w)
|
||||
#define jit_gei_d(u,v,w) jit_new_node_wwd(jit_code_gei_d,u,v,w)
|
||||
jit_code_ger_d, jit_code_gei_d,
|
||||
#define jit_gtr_d(u,v,w) jit_new_node_www(jit_code_gtr_d,u,v,w)
|
||||
#define jit_gti_d(u,v,w) jit_new_node_wwd(jit_code_gti_d,u,v,w)
|
||||
jit_code_gtr_d, jit_code_gti_d,
|
||||
#define jit_ner_d(u,v,w) jit_new_node_www(jit_code_ner_d,u,v,w)
|
||||
#define jit_nei_d(u,v,w) jit_new_node_wwd(jit_code_nei_d,u,v,w)
|
||||
jit_code_ner_d, jit_code_nei_d,
|
||||
#define jit_unltr_d(u,v,w) jit_new_node_www(jit_code_unltr_d,u,v,w)
|
||||
#define jit_unlti_d(u,v,w) jit_new_node_wwd(jit_code_unlti_d,u,v,w)
|
||||
jit_code_unltr_d, jit_code_unlti_d,
|
||||
#define jit_unler_d(u,v,w) jit_new_node_www(jit_code_unler_d,u,v,w)
|
||||
#define jit_unlei_d(u,v,w) jit_new_node_wwd(jit_code_unlei_d,u,v,w)
|
||||
jit_code_unler_d, jit_code_unlei_d,
|
||||
#define jit_uneqr_d(u,v,w) jit_new_node_www(jit_code_uneqr_d,u,v,w)
|
||||
#define jit_uneqi_d(u,v,w) jit_new_node_wwd(jit_code_uneqi_d,u,v,w)
|
||||
jit_code_uneqr_d, jit_code_uneqi_d,
|
||||
#define jit_unger_d(u,v,w) jit_new_node_www(jit_code_unger_d,u,v,w)
|
||||
#define jit_ungei_d(u,v,w) jit_new_node_wwd(jit_code_ungei_d,u,v,w)
|
||||
jit_code_unger_d, jit_code_ungei_d,
|
||||
#define jit_ungtr_d(u,v,w) jit_new_node_www(jit_code_ungtr_d,u,v,w)
|
||||
#define jit_ungti_d(u,v,w) jit_new_node_wwd(jit_code_ungti_d,u,v,w)
|
||||
jit_code_ungtr_d, jit_code_ungti_d,
|
||||
#define jit_ltgtr_d(u,v,w) jit_new_node_www(jit_code_ltgtr_d,u,v,w)
|
||||
#define jit_ltgti_d(u,v,w) jit_new_node_wwd(jit_code_ltgti_d,u,v,w)
|
||||
jit_code_ltgtr_d, jit_code_ltgti_d,
|
||||
#define jit_ordr_d(u,v,w) jit_new_node_www(jit_code_ordr_d,u,v,w)
|
||||
#define jit_ordi_d(u,v,w) jit_new_node_wwd(jit_code_ordi_d,u,v,w)
|
||||
jit_code_ordr_d, jit_code_ordi_d,
|
||||
#define jit_unordr_d(u,v,w) jit_new_node_www(jit_code_unordr_d,u,v,w)
|
||||
#define jit_unordi_d(u,v,w) jit_new_node_wwd(jit_code_unordi_d,u,v,w)
|
||||
jit_code_unordr_d, jit_code_unordi_d,
|
||||
|
||||
#define jit_truncr_d_i(u,v) jit_new_node_ww(jit_code_truncr_d_i,u,v)
|
||||
jit_code_truncr_d_i,
|
||||
#if __WODSIZE == 32
|
||||
# define jit_truncr_d(u,v) jit_truncr_d_i(u,v)
|
||||
#else
|
||||
# define jit_truncr_d(u,v) jit_truncr_d_l(u,v)
|
||||
#endif
|
||||
/* >> 64 bit */
|
||||
#define jit_truncr_d_l(u,v) jit_new_node_ww(jit_code_truncr_d_l,u,v)
|
||||
jit_code_truncr_d_l,
|
||||
/* << 64 bit */
|
||||
#define jit_extr_d(u,v) jit_new_node_ww(jit_code_extr_f,u,v)
|
||||
#define jit_extr_f_d(u,v) jit_new_node_ww(jit_code_extr_f_d,u,v)
|
||||
jit_code_extr_d, jit_code_extr_f_d,
|
||||
#define jit_movr_d(u,v) jit_new_node_ww(jit_code_movr_d,u,v)
|
||||
#define jit_movi_d(u,v) jit_new_node_wd(jit_code_movi_d,u,v)
|
||||
jit_code_movr_d, jit_code_movi_d,
|
||||
|
||||
#define jit_ldr_d(u,v) jit_new_node_ww(jit_code_ldr_d,u,v)
|
||||
#define jit_ldi_d(u,v) jit_new_node_ww(jit_code_ldi_d,u,v)
|
||||
jit_code_ldr_d, jit_code_ldi_d,
|
||||
#define jit_ldxr_d(u,v,w) jit_new_node_www(jit_code_ldxr_d,u,v,w)
|
||||
#define jit_ldxi_d(u,v,w) jit_new_node_www(jit_code_ldxi_d,u,v,w)
|
||||
jit_code_ldxr_d, jit_code_ldxi_d,
|
||||
#define jit_str_d(u,v) jit_new_node_ww(jit_code_str_d,u,v)
|
||||
#define jit_sti_d(u,v) jit_new_node_ww(jit_code_sti_d,u,v)
|
||||
jit_code_str_d, jit_code_sti_d,
|
||||
#define jit_stxr_d(u,v,w) jit_new_node_www(jit_code_stxr_d,u,v,w)
|
||||
#define jit_stxi_d(u,v,w) jit_new_node_www(jit_code_stxi_d,u,v,w)
|
||||
jit_code_stxr_d, jit_code_stxi_d,
|
||||
|
||||
#define jit_bltr_d(v,w) jit_new_node_pww(jit_code_bltr_d,NULL,v,w)
|
||||
#define jit_blti_d(v,w) jit_new_node_pwd(jit_code_blti_d,NULL,v,w)
|
||||
jit_code_bltr_d, jit_code_blti_d,
|
||||
#define jit_bler_d(v,w) jit_new_node_pww(jit_code_bler_d,NULL,v,w)
|
||||
#define jit_blei_d(v,w) jit_new_node_pwd(jit_code_blei_d,NULL,v,w)
|
||||
jit_code_bler_d, jit_code_blei_d,
|
||||
#define jit_beqr_d(v,w) jit_new_node_pww(jit_code_beqr_d,NULL,v,w)
|
||||
#define jit_beqi_d(v,w) jit_new_node_pwd(jit_code_beqi_d,NULL,v,w)
|
||||
jit_code_beqr_d, jit_code_beqi_d,
|
||||
#define jit_bger_d(v,w) jit_new_node_pww(jit_code_bger_d,NULL,v,w)
|
||||
#define jit_bgei_d(v,w) jit_new_node_pwd(jit_code_bgei_d,NULL,v,w)
|
||||
jit_code_bger_d, jit_code_bgei_d,
|
||||
#define jit_bgtr_d(v,w) jit_new_node_pww(jit_code_bgtr_d,NULL,v,w)
|
||||
#define jit_bgti_d(v,w) jit_new_node_pwd(jit_code_bgti_d,NULL,v,w)
|
||||
jit_code_bgtr_d, jit_code_bgti_d,
|
||||
#define jit_bner_d(v,w) jit_new_node_pww(jit_code_bner_d,NULL,v,w)
|
||||
#define jit_bnei_d(v,w) jit_new_node_pwd(jit_code_bnei_d,NULL,v,w)
|
||||
jit_code_bner_d, jit_code_bnei_d,
|
||||
#define jit_bunltr_d(v,w) jit_new_node_pww(jit_code_bunltr_d,NULL,v,w)
|
||||
#define jit_bunlti_d(v,w) jit_new_node_pwd(jit_code_bunlti_d,NULL,v,w)
|
||||
jit_code_bunltr_d, jit_code_bunlti_d,
|
||||
#define jit_bunler_d(v,w) jit_new_node_pww(jit_code_bunler_d,NULL,v,w)
|
||||
#define jit_bunlei_d(v,w) jit_new_node_pwd(jit_code_bunlei_d,NULL,v,w)
|
||||
jit_code_bunler_d, jit_code_bunlei_d,
|
||||
#define jit_buneqr_d(v,w) jit_new_node_pww(jit_code_buneqr_d,NULL,v,w)
|
||||
#define jit_buneqi_d(v,w) jit_new_node_pwd(jit_code_buneqi_d,NULL,v,w)
|
||||
jit_code_buneqr_d, jit_code_buneqi_d,
|
||||
#define jit_bunger_d(v,w) jit_new_node_pww(jit_code_bunger_d,NULL,v,w)
|
||||
#define jit_bungei_d(v,w) jit_new_node_pwd(jit_code_bungei_d,NULL,v,w)
|
||||
jit_code_bunger_d, jit_code_bungei_d,
|
||||
#define jit_bungtr_d(v,w) jit_new_node_pww(jit_code_bungtr_d,NULL,v,w)
|
||||
#define jit_bungti_d(v,w) jit_new_node_pwd(jit_code_bungti_d,NULL,v,w)
|
||||
jit_code_bungtr_d, jit_code_bungti_d,
|
||||
#define jit_bltgtr_d(v,w) jit_new_node_pww(jit_code_bltgtr_d,NULL,v,w)
|
||||
#define jit_bltgti_d(v,w) jit_new_node_pwd(jit_code_bltgti_d,NULL,v,w)
|
||||
jit_code_bltgtr_d, jit_code_bltgti_d,
|
||||
#define jit_bordr_d(v,w) jit_new_node_pww(jit_code_bordr_d,NULL,v,w)
|
||||
#define jit_bordi_d(v,w) jit_new_node_pwd(jit_code_bordi_d,NULL,v,w)
|
||||
jit_code_bordr_d, jit_code_bordi_d,
|
||||
#define jit_bunordr_d(v,w) jit_new_node_pww(jit_code_bunordr_d,NULL,v,w)
|
||||
#define jit_bunordi_d(v,w) jit_new_node_pwd(jit_code_bunordi_d,NULL,v,w)
|
||||
jit_code_bunordr_d, jit_code_bunordi_d,
|
||||
|
||||
#define jit_pushargr_d(u) _jit_pushargr_d(_jit,u)
|
||||
#define jit_pushargi_d(u) _jit_pushargi_d(_jit,u)
|
||||
#define jit_retr_d(u) _jit_retr_d(_jit,u)
|
||||
#define jit_reti_d(u) _jit_reti_d(_jit,u)
|
||||
#define jit_retval_d(u) _jit_retval_d(_jit,u)
|
||||
jit_code_retval_d,
|
||||
} jit_code_t;
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
extern void init_jit(void);
|
||||
extern void finish_jit(void);
|
||||
|
||||
extern jit_state_t *jit_new_state(void);
|
||||
|
||||
extern jit_node_t *_jit_data(jit_state_t*, jit_pointer_t, jit_word_t);
|
||||
extern jit_node_t *_jit_note(jit_state_t*, jit_pointer_t);
|
||||
|
||||
extern jit_node_t *_jit_label(jit_state_t*);
|
||||
extern jit_node_t *_jit_forward(jit_state_t*);
|
||||
extern void _jit_link(jit_state_t*, jit_node_t*);
|
||||
|
||||
extern void _jit_prolog(jit_state_t*);
|
||||
|
||||
extern jit_int32_t _jit_allocai(jit_state_t*, jit_int32_t);
|
||||
|
||||
extern jit_int32_t _jit_arg(jit_state_t*);
|
||||
extern void _jit_getarg_c(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
extern void _jit_getarg_uc(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
extern void _jit_getarg_s(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
extern void _jit_getarg_us(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
extern void _jit_getarg_i(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
#if __WORDSIZE == 64
|
||||
extern void _jit_getarg_ui(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
extern void _jit_getarg_l(jit_state_t*, jit_gpr_t, jit_int32_t);
|
||||
#endif
|
||||
|
||||
extern void _jit_prepare(jit_state_t*, jit_int32_t);
|
||||
extern void _jit_pushargr(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_pushargi(jit_state_t*, jit_word_t);
|
||||
extern void _jit_finishr(jit_state_t*, jit_gpr_t);
|
||||
extern jit_node_t *_jit_finishi(jit_state_t*, jit_pointer_t);
|
||||
extern void _jit_ret(jit_state_t*);
|
||||
extern void _jit_retr(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_reti(jit_state_t*, jit_word_t);
|
||||
extern void _jit_retval_c(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_retval_uc(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_retval_s(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_retval_us(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_retval_i(jit_state_t*, jit_gpr_t);
|
||||
#if __WORDSIZE == 64
|
||||
extern void _jit_retval_ui(jit_state_t*, jit_gpr_t);
|
||||
extern void _jit_retval_l(jit_state_t*, jit_gpr_t);
|
||||
#endif
|
||||
extern void _jit_epilog(jit_state_t*);
|
||||
|
||||
#define jit_patch(u) _jit_patch(_jit,u)
|
||||
extern void _jit_patch(jit_state_t*, jit_node_t*);
|
||||
#define jit_patch_at(u,v) _jit_patch_at(_jit,u,v)
|
||||
extern void _jit_patch_at(jit_state_t*, jit_node_t*, jit_node_t*);
|
||||
#define jit_patch_abs(u,v) _jit_patch_abs(_jit,u,v)
|
||||
extern void _jit_patch_abs(jit_state_t*, jit_node_t*, jit_pointer_t);
|
||||
#define jit_emit() _jit_emit(_jit)
|
||||
extern jit_pointer_t _jit_emit(jit_state_t*);
|
||||
|
||||
#define jit_print() _jit_print(_jit)
|
||||
extern void _jit_print(jit_state_t*);
|
||||
|
||||
extern jit_int32_t _jit_arg_f(jit_state_t*);
|
||||
extern void _jit_getarg_f(jit_state_t*, jit_fpr_t, jit_int32_t);
|
||||
|
||||
extern void _jit_pushargr_f(jit_state_t*, jit_fpr_t);
|
||||
extern void _jit_pushargi_f(jit_state_t*, jit_float32_t);
|
||||
extern void _jit_retr_f(jit_state_t*, jit_fpr_t);
|
||||
extern void _jit_reti_f(jit_state_t*, jit_float32_t);
|
||||
extern void _jit_retval_f(jit_state_t*, jit_fpr_t);
|
||||
|
||||
extern jit_int32_t _jit_arg_d(jit_state_t*);
|
||||
extern void _jit_getarg_d(jit_state_t*, jit_fpr_t, jit_int32_t);
|
||||
|
||||
extern void _jit_pushargr_d(jit_state_t*, jit_fpr_t);
|
||||
extern void _jit_pushargi_d(jit_state_t*, jit_float64_t);
|
||||
extern void _jit_retr_d(jit_state_t*, jit_fpr_t);
|
||||
extern void _jit_reti_d(jit_state_t*, jit_float64_t);
|
||||
extern void _jit_retval_d(jit_state_t*, jit_fpr_t);
|
||||
|
||||
#define jit_new_node(c) _jit_new_node(_jit,c)
|
||||
extern jit_node_t *_jit_new_node(jit_state_t*, jit_code_t);
|
||||
#define jit_new_node_w(c,u) _jit_new_node_w(_jit,c,u)
|
||||
extern jit_node_t *_jit_new_node_w(jit_state_t*, jit_code_t,
|
||||
jit_word_t);
|
||||
#define jit_new_node_p(c,u) _jit_new_node_p(_jit,c,u)
|
||||
extern jit_node_t *_jit_new_node_p(jit_state_t*, jit_code_t,
|
||||
jit_pointer_t);
|
||||
#define jit_new_node_ww(c,u,v) _jit_new_node_ww(_jit,c,u,v)
|
||||
extern jit_node_t *_jit_new_node_ww(jit_state_t*,jit_code_t,
|
||||
jit_word_t, jit_word_t);
|
||||
#define jit_new_node_wf(c,u,v) _jit_new_node_wf(_jit,c,u,v)
|
||||
extern jit_node_t *_jit_new_node_wf(jit_state_t*, jit_code_t,
|
||||
jit_word_t, jit_float32_t);
|
||||
#define jit_new_node_wd(c,u,v) _jit_new_node_wd(_jit,c,u,v)
|
||||
extern jit_node_t *_jit_new_node_wd(jit_state_t*, jit_code_t,
|
||||
jit_word_t, jit_float64_t);
|
||||
#define jit_new_node_www(c,u,v,w) _jit_new_node_www(_jit,c,u,v,w)
|
||||
extern jit_node_t *_jit_new_node_www(jit_state_t*, jit_code_t,
|
||||
jit_word_t, jit_word_t, jit_word_t);
|
||||
#define jit_new_node_wwf(c,u,v,w) _jit_new_node_wwf(_jit,c,u,v,w)
|
||||
extern jit_node_t *_jit_new_node_wwf(jit_state_t*, jit_code_t,
|
||||
jit_word_t, jit_word_t, jit_float32_t);
|
||||
#define jit_new_node_wwd(c,u,v,w) _jit_new_node_wwd(_jit,c,u,v,w)
|
||||
extern jit_node_t *_jit_new_node_wwd(jit_state_t*, jit_code_t,
|
||||
jit_word_t, jit_word_t, jit_float64_t);
|
||||
#define jit_new_node_pww(c,u,v,w) _jit_new_node_pww(_jit,c,u,v,w)
|
||||
extern jit_node_t *_jit_new_node_pww(jit_state_t*, jit_code_t,
|
||||
jit_pointer_t, jit_word_t, jit_word_t);
|
||||
#define jit_new_node_pwf(c,u,v,w) _jit_new_node_pwf(_jit,c,u,v,w)
|
||||
extern jit_node_t *_jit_new_node_pwf(jit_state_t*, jit_code_t,
|
||||
jit_pointer_t, jit_word_t, jit_float32_t);
|
||||
#define jit_new_node_pwd(c,u,v,w) _jit_new_node_pwd(_jit,c,u,v,w)
|
||||
extern jit_node_t *_jit_new_node_pwd(jit_state_t*, jit_code_t,
|
||||
jit_pointer_t, jit_word_t, jit_float64_t);
|
||||
|
||||
#define jit_disassemble() _jit_disassemble(_jit)
|
||||
extern void _jit_disassemble(jit_state_t*);
|
||||
|
||||
#endif /* _lightning_h */
|
23
include/lightning/Makefile.am
Normal file
23
include/lightning/Makefile.am
Normal file
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
|
||||
#
|
||||
# This is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This software is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
|
||||
includedir = $(includedir)/lightning
|
||||
|
||||
EXTRA_DIST = \
|
||||
jit_private.h
|
||||
|
||||
if cpu_x86
|
||||
include_HEADERS = \
|
||||
jit_x86.h
|
||||
endif
|
147
include/lightning/jit_arm.h
Normal file
147
include/lightning/jit_arm.h
Normal file
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#ifndef _jit_arm_h
|
||||
#define _jit_arm_h
|
||||
|
||||
#define JIT_HASH_CONSTS 0
|
||||
#define JIT_NUM_OPERANDS 3
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
#define jit_swf_p() (jit_cpu.vfp == 0)
|
||||
#define jit_hardfp_p() jit_cpu.abi
|
||||
|
||||
#define JIT_RET _R0
|
||||
#define JIT_SP _R13
|
||||
#define JIT_FP _R11
|
||||
typedef enum {
|
||||
#define jit_arg_reg_p(i) ((i) >= 0 && (i) < 4)
|
||||
#define jit_r(i) (_R4 + (i))
|
||||
#define jit_r_num() 3
|
||||
#define jit_v(i) (_R7 + (i))
|
||||
#define jit_v_num() 3
|
||||
#define jit_arg_f_reg_p(i) ((i) >= 0 && (i) < 4)
|
||||
#define jit_f(i) (jit_cpu.abi ? _D8 + (i) : _D7 + (i))
|
||||
#define jit_f_num() (jit_cpu.vfp ? 16 : 8)
|
||||
_R12, /* ip - temporary */
|
||||
#define JIT_R0 _R4
|
||||
#define JIT_R1 _R5
|
||||
#define JIT_R2 _R6
|
||||
_R4, /* r4 - variable */
|
||||
_R5, /* r5 - variable */
|
||||
_R6, /* r6 - variable */
|
||||
#define JIT_V0 _R7
|
||||
#define JIT_V1 _R8
|
||||
#define JIT_V2 _R9
|
||||
_R7, /* r7 - variable */
|
||||
_R8, /* r8 - variable */
|
||||
_R9, /* r9 - variable */
|
||||
_R10, /* sl - stack limit */
|
||||
_R11, /* fp - frame pointer */
|
||||
_R13, /* sp - stack pointer */
|
||||
_R14, /* lr - link register */
|
||||
_R15, /* pc - program counter */
|
||||
#define JIT_RA0 _R0
|
||||
#define JIT_RA1 _R1
|
||||
#define JIT_RA2 _R2
|
||||
#define JIT_RA3 _R3
|
||||
_R3, /* r3 - argument/result */
|
||||
_R2, /* r2 - argument/result */
|
||||
_R1, /* r1 - argument/result */
|
||||
_R0, /* r0 - argument/result */
|
||||
#if defined(__ARM_PCS_VFP)
|
||||
# define JIT_FRET _D0
|
||||
#else
|
||||
# define JIT_FRET _R0
|
||||
#endif
|
||||
#define JIT_F0 (jit_hardfp_p() ? _D8 : _D0)
|
||||
#define JIT_F1 (jit_hardfp_p() ? _D9 : _D1)
|
||||
#define JIT_F2 (jit_hardfp_p() ? _D10 : _D2)
|
||||
#define JIT_F3 (jit_hardfp_p() ? _D11 : _D3)
|
||||
#define JIT_F4 (jit_hardfp_p() ? _D12 : _D4)
|
||||
#define JIT_F5 (jit_hardfp_p() ? _D13 : _D5)
|
||||
#define JIT_F6 (jit_hardfp_p() ? _D14 : _D6)
|
||||
#define JIT_F7 (jit_hardfp_p() ? _D15 : _D7)
|
||||
_S16, _D8 = _S16, _Q4 = _D8,
|
||||
_S17,
|
||||
_S18, _D9 = _S18,
|
||||
_S19,
|
||||
_S20, _D10 = _S20, _Q5 = _D10,
|
||||
_S21,
|
||||
_S22, _D11 = _S22,
|
||||
_S23,
|
||||
_S24, _D12 = _S24, _Q6 = _D12,
|
||||
_S25,
|
||||
_S26, _D13 = _S26,
|
||||
_S27,
|
||||
_S28, _D14 = _S28, _Q7 = _D14,
|
||||
_S29,
|
||||
_S30, _D15 = _S30,
|
||||
_S31,
|
||||
#define JIT_FA0 _D0
|
||||
#define JIT_FA1 _D1
|
||||
#define JIT_FA2 _D2
|
||||
#define JIT_FA3 _D3
|
||||
#define JIT_FA4 _D4
|
||||
#define JIT_FA5 _D5
|
||||
#define JIT_FA6 _D6
|
||||
#define JIT_FA7 _D7
|
||||
_S15,
|
||||
_S14, _D7 = _S14,
|
||||
_S13,
|
||||
_S12, _D6 = _S12, _Q3 = _D6,
|
||||
_S11,
|
||||
_S10, _D5 = _S10,
|
||||
_S9,
|
||||
_S8, _D4 = _S8, _Q2 = _D4,
|
||||
_S7,
|
||||
_S6, _D3 = _S6,
|
||||
_S5,
|
||||
_S4, _D2 = _S4, _Q1 = _D2,
|
||||
_S3,
|
||||
_S2, _D1 = _S2,
|
||||
_S1,
|
||||
_S0, _D0 = _S0, _Q0 = _D0,
|
||||
_NOREG,
|
||||
#define JIT_NOREG _NOREG
|
||||
} jit_reg_t;
|
||||
|
||||
typedef struct {
|
||||
jit_uint32_t version : 4;
|
||||
jit_uint32_t extend : 1;
|
||||
/* only generate thumb instructions for thumb2 */
|
||||
jit_uint32_t thumb : 1;
|
||||
jit_uint32_t vfp : 3;
|
||||
jit_uint32_t neon : 1;
|
||||
jit_uint32_t abi : 2;
|
||||
} jit_cpu_t;
|
||||
|
||||
typedef struct {
|
||||
/* prevent using thumb instructions that set flags? */
|
||||
jit_uint32_t no_set_flags : 1;
|
||||
} jit_flags_t;
|
||||
|
||||
typedef jit_int64_t jit_regset_t;
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
extern jit_cpu_t jit_cpu;
|
||||
|
||||
#endif /* _jit_arm_h */
|
98
include/lightning/jit_mips.h
Normal file
98
include/lightning/jit_mips.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#ifndef _jit_mips_h
|
||||
#define _jit_mips_h
|
||||
|
||||
#define JIT_HASH_CONSTS 1
|
||||
#define JIT_NUM_OPERANDS 3
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
#define JIT_RET _V0
|
||||
#define JIT_FRET _F0
|
||||
#define JIT_SP _SP
|
||||
#define JIT_FP _FP
|
||||
typedef enum {
|
||||
#define jit_arg_reg_p(i) ((i) >= 0 && (i) < 4)
|
||||
#define jit_r(i) (_V0 + (i))
|
||||
#define jit_r_num() 12
|
||||
#define jit_v(i) (_S0 + (i))
|
||||
#define jit_r_num() 8
|
||||
#define jit_arg_reg_p(i) ((i) >= 0 && (i) < 4)
|
||||
#define jit_f(i) (_F0 + (i))
|
||||
#define jit_f_num() 14
|
||||
_AT,
|
||||
#define JIT_R0 _V0
|
||||
#define JIT_R1 _V1
|
||||
#define JIT_R2 _T0
|
||||
#define JIT_R3 _T1
|
||||
#define JIT_R4 _T2
|
||||
#define JIT_R5 _T3
|
||||
#define JIT_R6 _T4
|
||||
#define JIT_R7 _T5
|
||||
#define JIT_R8 _T6
|
||||
#define JIT_R9 _T7
|
||||
#define JIT_R10 _T8
|
||||
#define JIT_R11 _T9 /* must point to PIC function */
|
||||
_V0, _V1, _T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9,
|
||||
#define JIT_V0 _S0
|
||||
#define JIT_V1 _S1
|
||||
#define JIT_V2 _S2
|
||||
#define JIT_V3 _S3
|
||||
#define JIT_V4 _S4
|
||||
#define JIT_V5 _S5
|
||||
#define JIT_V6 _S6
|
||||
#define JIT_V7 _S7
|
||||
_S0, _S1, _S2, _S3, _S4, _S5, _S6, _S7,
|
||||
_ZERO, _K0, _K1, _RA,
|
||||
_GP, /* FIXME use to point to jit data */
|
||||
_SP, _FP,
|
||||
# define JIT_RA0 _A0
|
||||
# define JIT_RA1 _A1
|
||||
# define JIT_RA2 _A2
|
||||
# define JIT_RA3 _A3
|
||||
_A3, _A2, _A1, _A0,
|
||||
|
||||
#define JIT_F0 _F0
|
||||
#define JIT_F1 _F2
|
||||
#define JIT_F2 _F4
|
||||
#define JIT_F3 _F6
|
||||
#define JIT_F4 _F8
|
||||
#define JIT_F5 _F10
|
||||
_F0, _F2, _F4, _F6, _F8, _F10,
|
||||
/* callee save float registers */
|
||||
#define JIT_FS0 _F16
|
||||
#define JIT_FS1 _F18
|
||||
#define JIT_FS2 _F20
|
||||
#define JIT_FS3 _F22
|
||||
#define JIT_FS4 _F24
|
||||
#define JIT_FS5 _F26
|
||||
#define JIT_FS6 _F28
|
||||
#define JIT_FS7 _F30
|
||||
_F16, _F18, _F20, _F22, _F24, _F26, _F28, _F30,
|
||||
#define JIT_FA0 _F12
|
||||
#define JIT_FA1 _F14
|
||||
_F12, _F14,
|
||||
#define JIT_NOREG _NOREG
|
||||
_NOREG,
|
||||
} jit_reg_t;
|
||||
|
||||
typedef jit_int64_t jit_regset_t;
|
||||
|
||||
#endif /* _jit_mips_h */
|
120
include/lightning/jit_ppc.h
Normal file
120
include/lightning/jit_ppc.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#ifndef _jit_ppc_h
|
||||
#define _jit_ppc_h
|
||||
|
||||
#define JIT_HASH_CONSTS 1
|
||||
#define JIT_NUM_OPERANDS 3
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
typedef enum {
|
||||
#define jit_arg_reg_p(i) ((i) >= 0 && (i) < 8)
|
||||
#define jit_r(i) (_R11 + (i))
|
||||
#define jit_r_num() 3
|
||||
#define jit_v(i) (_R30 - (i))
|
||||
#define jit_r_num() 17
|
||||
#define jit_arg_f_reg_p(i) ((i) >= 0 && (i) < 8)
|
||||
#define jit_f(i) (_F0 + (i))
|
||||
#define jit_f_num() 6
|
||||
_R0,
|
||||
#define JIT_R0 _R11
|
||||
#define JIT_R1 _R12
|
||||
#define JIT_R2 _R13
|
||||
#define JIT_R3 _R2
|
||||
_R11, _R12, _R13, _R2,
|
||||
#define JIT_V0 _R30
|
||||
#define JIT_V1 _R29
|
||||
#define JIT_V2 _R28
|
||||
#define JIT_V3 _R28
|
||||
#define JIT_V4 _R26
|
||||
#define JIT_V5 _R25
|
||||
#define JIT_V6 _R24
|
||||
#define JIT_V7 _R23
|
||||
#define JIT_V8 _R22
|
||||
#define JIT_V9 _R21
|
||||
#define JIT_V10 _R20
|
||||
#define JIT_V11 _R19
|
||||
#define JIT_V12 _R18
|
||||
#define JIT_V13 _R17
|
||||
#define JIT_V14 _R16
|
||||
#define JIT_V15 _R15
|
||||
#define JIT_V16 _R14
|
||||
_R14, _R15, _R16, _R17, _R18, _R19, _R20, _R21,
|
||||
_R22, _R23, _R24, _R25, _R26, _R27, _R28, _R29,
|
||||
_R30,
|
||||
#define JIT_SP _R1
|
||||
_R1,
|
||||
#define JIT_FP _R31
|
||||
_R31,
|
||||
#define JIT_RET _R3
|
||||
#define JIT_RA0 _R3
|
||||
#define JIT_RA1 _R4
|
||||
#define JIT_RA2 _R5
|
||||
#define JIT_RA3 _R6
|
||||
#define JIT_RA4 _R7
|
||||
#define JIT_RA5 _R8
|
||||
#define JIT_RA6 _R9
|
||||
#define JIT_RA7 _R10
|
||||
_R10, _R9, _R8, _R7, _R6, _R5, _R4, _R3,
|
||||
# define JIT_F0 _F0
|
||||
# define JIT_F1 _F8
|
||||
# define JIT_F2 _F9
|
||||
# define JIT_F3 _F10
|
||||
# define JIT_F4 _F11
|
||||
# define JIT_F5 _F12
|
||||
_F0, _F9, _F10, _F11, _F12, _F13,
|
||||
#define JIT_FS0 _F14
|
||||
#define JIT_FS1 _F15
|
||||
#define JIT_FS2 _F16
|
||||
#define JIT_FS3 _F17
|
||||
#define JIT_FS4 _F18
|
||||
#define JIT_FS5 _F19
|
||||
#define JIT_FS6 _F20
|
||||
#define JIT_FS7 _F21
|
||||
#define JIT_FS8 _F22
|
||||
#define JIT_FS9 _F23
|
||||
#define JIT_FS10 _F24
|
||||
#define JIT_FS11 _F25
|
||||
#define JIT_FS12 _F26
|
||||
#define JIT_FS13 _F27
|
||||
#define JIT_FS14 _F28
|
||||
#define JIT_FS15 _F29
|
||||
#define JIT_FS16 _F30
|
||||
#define JIT_FS17 _F31
|
||||
_F14, _F15, _F16, _F17, _F18, _F19, _F20,
|
||||
_F21, _F22, _F23, _F24, _F25, _F26, _F27,
|
||||
_F28, _F29, _F30, _F31,
|
||||
#define JIT_FRET _F1
|
||||
#define JIT_FA0 _F1
|
||||
#define JIT_FA1 _F2
|
||||
#define JIT_FA2 _F3
|
||||
#define JIT_FA3 _F4
|
||||
#define JIT_FA4 _F5
|
||||
#define JIT_FA5 _F6
|
||||
#define JIT_FA6 _F7
|
||||
#define JIT_FA7 _F8
|
||||
_F8, _F7, _F6, _F5, _F4, _F3, _F2, _F1,
|
||||
_NOREG,
|
||||
#define JIT_NOREG _NOREG
|
||||
} jit_reg_t;
|
||||
|
||||
typedef jit_int64_t jit_regset_t;
|
||||
|
||||
#endif /* _jit_ppc_h */
|
363
include/lightning/jit_private.h
Normal file
363
include/lightning/jit_private.h
Normal file
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#ifndef _jit_private_h
|
||||
#define _jit_private_h
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define maybe_unused __attribute__ ((unused))
|
||||
# define unlikely(exprn) __builtin_expect(!!(exprn), 0)
|
||||
# define likely(exprn) __builtin_expect(!!(exprn), 1)
|
||||
# if (__GNUC__ >= 4)
|
||||
# define PUBLIC __attribute__ ((visibility("default")))
|
||||
# define HIDDEN __attribute__ ((visibility("hidden")))
|
||||
# else
|
||||
# define PUBLIC /**/
|
||||
# define HIDDEN /**/
|
||||
# endif
|
||||
#else
|
||||
# define maybe_unused /**/
|
||||
# define unlikely(exprn) exprn
|
||||
# define likely(exprn) exprn
|
||||
# define PUBLIC /**/
|
||||
# define HIDDEN /**/
|
||||
#endif
|
||||
|
||||
#define jit_size(vector) (sizeof(vector) / sizeof((vector)[0]))
|
||||
|
||||
/*
|
||||
* Private jit_class bitmasks
|
||||
*/
|
||||
#define jit_class_nospill 0x00800000 /* hint to fail if need spill */
|
||||
#define jit_class_sft 0x01000000 /* not a hardware register */
|
||||
#define jit_class_rg8 0x04000000 /* x86 8 bits */
|
||||
#define jit_class_xpr 0x80000000 /* float / vector */
|
||||
#define jit_regno_patch 0x00008000 /* this is a register
|
||||
* returned by a "user" call
|
||||
* to jit_get_reg() */
|
||||
|
||||
#define jit_kind_register 1
|
||||
#define jit_kind_code 2
|
||||
#define jit_kind_word 3
|
||||
#define jit_kind_float32 4
|
||||
#define jit_kind_float64 5
|
||||
|
||||
#define jit_cc_a0_reg 0x00000001 /* arg0 is a register */
|
||||
#define jit_cc_a0_chg 0x00000002 /* arg0 is modified */
|
||||
#define jit_cc_a0_jmp 0x00000004 /* arg0 is a jump target */
|
||||
#define jit_cc_a0_int 0x00000010 /* arg0 is immediate word */
|
||||
#define jit_cc_a0_flt 0x00000020 /* arg0 is immediate float */
|
||||
#define jit_cc_a0_dbl 0x00000040 /* arg0 is immediate double */
|
||||
#define jit_cc_a1_reg 0x00000100 /* arg1 is a register */
|
||||
#define jit_cc_a1_chg 0x00000200 /* arg1 is modified */
|
||||
#define jit_cc_a1_int 0x00001000 /* arg1 is immediate word */
|
||||
#define jit_cc_a1_flt 0x00002000 /* arg1 is immediate float */
|
||||
#define jit_cc_a1_dbl 0x00004000 /* arg1 is immediate double */
|
||||
#define jit_cc_a2_reg 0x00010000 /* arg2 is a register */
|
||||
#define jit_cc_a2_chg 0x00020000 /* arg2 is modified */
|
||||
#define jit_cc_a2_int 0x00100000 /* arg2 is immediate word */
|
||||
#define jit_cc_a2_flt 0x00200000 /* arg2 is immediate float */
|
||||
#define jit_cc_a2_dbl 0x00400000 /* arg2 is immediate double */
|
||||
|
||||
#define jit_regset_com(u, v) ((u) = ~(v))
|
||||
#define jit_regset_and(u, v, w) ((u) = (v) & (w))
|
||||
#define jit_regset_ior(u, v, w) ((u) = (v) | (w))
|
||||
#define jit_regset_xor(u, v, w) ((u) = (v) ^ (w))
|
||||
#define jit_regset_set(u, v) ((u) = (v))
|
||||
#define jit_regset_cmp_ui(u, v) ((u) != (v))
|
||||
#define jit_regset_set_ui(u, v) ((u) = (v))
|
||||
#define jit_regset_set_p(set) (set)
|
||||
#if DEBUG
|
||||
# define jit_regset_clrbit(set, bit) \
|
||||
(assert(bit >= 0 && bit < (sizeof(jit_regset_t) << 3)), \
|
||||
(set) &= ~(1LL << (bit)))
|
||||
# define jit_regset_setbit(set, bit) \
|
||||
(assert(bit >= 0 && bit < (sizeof(jit_regset_t) << 3)), \
|
||||
(set) |= 1LL << (bit))
|
||||
# define jit_regset_tstbit(set, bit) \
|
||||
(assert(bit >= 0 && bit < (sizeof(jit_regset_t) << 3)), \
|
||||
(set) & (1LL << (bit)))
|
||||
#else
|
||||
# define jit_regset_clrbit(set, bit) ((set) &= ~(1LL << (bit)))
|
||||
# define jit_regset_setbit(set, bit) ((set) |= 1LL << (bit))
|
||||
# define jit_regset_tstbit(set, bit) ((set) & (1LL << (bit)))
|
||||
#endif
|
||||
#define jit_regset_new(set) ((set) = 0)
|
||||
#define jit_regset_del(set) ((set) = 0)
|
||||
extern unsigned long
|
||||
jit_regset_scan1(jit_regset_t, jit_int32_t);
|
||||
|
||||
#define jit_reglive_setup() \
|
||||
do { \
|
||||
jit_regset_set_ui(_jit->reglive, 0); \
|
||||
jit_regset_set_ui(_jit->regmask, 0); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
typedef union jit_data jit_data_t;
|
||||
typedef struct jit_block jit_block_t;
|
||||
typedef struct jit_value jit_value_t;
|
||||
typedef struct jit_function jit_function_t;
|
||||
typedef struct jit_register jit_register_t;
|
||||
#if __arm__
|
||||
# if DISASSEMBLER
|
||||
typedef struct jit_data_info jit_data_info_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
union jit_data {
|
||||
struct {
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
jit_int32_t l;
|
||||
jit_int32_t h;
|
||||
#else
|
||||
jit_int32_t h;
|
||||
jit_int32_t l;
|
||||
#endif
|
||||
} pair;
|
||||
jit_word_t w;
|
||||
jit_float32_t f;
|
||||
jit_float64_t d;
|
||||
jit_pointer_t p;
|
||||
jit_node_t *n;
|
||||
};
|
||||
|
||||
struct jit_node {
|
||||
jit_node_t *next;
|
||||
jit_code_t code;
|
||||
jit_int32_t flag;
|
||||
jit_data_t u;
|
||||
jit_data_t v;
|
||||
jit_data_t w;
|
||||
jit_node_t *link;
|
||||
};
|
||||
|
||||
struct jit_block {
|
||||
jit_node_t *label;
|
||||
jit_regset_t reglive;
|
||||
jit_regset_t regmask;
|
||||
};
|
||||
|
||||
struct jit_value {
|
||||
jit_int32_t kind;
|
||||
jit_code_t code;
|
||||
jit_data_t base;
|
||||
jit_data_t disp;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
jit_word_t inst;
|
||||
jit_node_t *node;
|
||||
} jit_patch_t;
|
||||
|
||||
#if __arm__ && DISASSEMBLER
|
||||
struct jit_data_info {
|
||||
jit_uword_t code; /* pointer in code buffer */
|
||||
jit_word_t length; /* length of constant vector */
|
||||
};
|
||||
#endif
|
||||
|
||||
struct jit_function {
|
||||
struct {
|
||||
jit_int32_t argi;
|
||||
jit_int32_t argf;
|
||||
jit_int32_t size;
|
||||
jit_int32_t aoff;
|
||||
jit_int32_t alen;
|
||||
} self;
|
||||
struct {
|
||||
jit_int32_t argi;
|
||||
jit_int32_t argf;
|
||||
jit_int32_t size;
|
||||
jit_int32_t kind;
|
||||
} call;
|
||||
jit_node_t *prolog;
|
||||
jit_node_t *epilog;
|
||||
jit_int32_t *regoff;
|
||||
jit_regset_t regset;
|
||||
jit_int32_t stack;
|
||||
};
|
||||
|
||||
struct jit_state {
|
||||
union {
|
||||
jit_uint8_t *uc;
|
||||
jit_uint16_t *us;
|
||||
jit_uint32_t *ui;
|
||||
jit_uint64_t *ul;
|
||||
jit_word_t w;
|
||||
} pc;
|
||||
jit_node_t *head;
|
||||
jit_node_t *tail;
|
||||
jit_uint32_t emit : 1; /* emit state entered */
|
||||
jit_uint32_t again : 1; /* start over emiting function */
|
||||
jit_int32_t reglen; /* number of registers */
|
||||
jit_regset_t regarg; /* cannot allocate */
|
||||
jit_regset_t regsav; /* automatic spill only once */
|
||||
jit_regset_t reglive; /* known live registers at some point */
|
||||
jit_regset_t regmask; /* register mask to update reglive */
|
||||
mpz_t blockmask; /* mask of visited basic blocks */
|
||||
struct {
|
||||
jit_uint8_t *ptr;
|
||||
jit_word_t length;
|
||||
} code;
|
||||
struct {
|
||||
jit_uint8_t *ptr; /* constant pool */
|
||||
jit_node_t **table; /* very simple hash table */
|
||||
jit_word_t size; /* number of vectors in table */
|
||||
jit_word_t count; /* number of hash table entries */
|
||||
jit_word_t offset; /* offset in bytes in ptr */
|
||||
jit_word_t length; /* length in bytes of ptr */
|
||||
} data;
|
||||
jit_node_t **spill;
|
||||
jit_int32_t *gen; /* ssa like "register version" */
|
||||
jit_value_t *values; /* temporary jit_value_t vector */
|
||||
struct {
|
||||
jit_block_t *ptr;
|
||||
jit_word_t offset;
|
||||
jit_word_t length;
|
||||
} blocks; /* basic blocks */
|
||||
struct {
|
||||
jit_patch_t *ptr;
|
||||
jit_word_t offset;
|
||||
jit_word_t length;
|
||||
} patches; /* forward patch information */
|
||||
jit_function_t *function; /* current function */
|
||||
struct {
|
||||
jit_function_t *ptr;
|
||||
jit_word_t offset;
|
||||
jit_word_t length;
|
||||
} functions; /* prolog/epilogue offsets in code */
|
||||
struct {
|
||||
jit_node_t **ptr;
|
||||
jit_word_t offset;
|
||||
jit_word_t length;
|
||||
} pool;
|
||||
jit_node_t *list;
|
||||
#if __arm__
|
||||
# if DISASSEMBLER
|
||||
struct {
|
||||
jit_data_info_t *ptr;
|
||||
it_word_t offset;
|
||||
jit_word_t length;
|
||||
} data_info; /* constant pools information */
|
||||
# endif
|
||||
struct {
|
||||
jit_uint8_t *data; /* pointer to code */
|
||||
jit_word_t size; /* size data */
|
||||
jit_word_t offset; /* pending patches */
|
||||
jit_word_t length; /* number of pending constants */
|
||||
jit_int32_t values[1024]; /* pending constants */
|
||||
jit_word_t patches[2048];
|
||||
} consts;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct jit_register {
|
||||
jit_reg_t spec;
|
||||
char *name;
|
||||
};
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
extern void jit_get_cpu(void);
|
||||
|
||||
#define jit_init() _jit_init(_jit)
|
||||
extern void _jit_init(jit_state_t*);
|
||||
|
||||
#define jit_new_node_no_link(u) _jit_new_node_no_link(_jit, u)
|
||||
extern jit_node_t *_jit_new_node_no_link(jit_state_t*, jit_code_t);
|
||||
|
||||
#define jit_link_node(u) _jit_link_node(_jit, u)
|
||||
extern void _jit_link_node(jit_state_t*, jit_node_t*);
|
||||
|
||||
#define jit_link_label(l) _jit_link_label(_jit,l)
|
||||
extern void
|
||||
_jit_link_label(jit_state_t*,jit_node_t*);
|
||||
|
||||
#define jit_reglive(node) _jit_reglive(_jit, node)
|
||||
extern void
|
||||
_jit_reglive(jit_state_t*, jit_node_t*);
|
||||
|
||||
#define jit_regarg_set(n,v) _jit_regarg_set(_jit,n,v)
|
||||
extern void
|
||||
_jit_regarg_set(jit_state_t*, jit_node_t*, jit_int32_t);
|
||||
|
||||
#define jit_regarg_clr(n,v) _jit_regarg_clr(_jit,n,v)
|
||||
extern void
|
||||
_jit_regarg_clr(jit_state_t*, jit_node_t*, jit_int32_t);
|
||||
|
||||
#define jit_get_reg(s) _jit_get_reg(_jit,s)
|
||||
extern jit_int32_t
|
||||
_jit_get_reg(jit_state_t*, jit_int32_t);
|
||||
|
||||
#define jit_unget_reg(r) _jit_unget_reg(_jit,r)
|
||||
extern void
|
||||
_jit_unget_reg(jit_state_t*, jit_int32_t);
|
||||
|
||||
#define jit_save(reg) _jit_save(_jit, reg)
|
||||
extern void
|
||||
_jit_save(jit_state_t*, jit_int32_t);
|
||||
|
||||
#define jit_load(reg) _jit_load(_jit, reg)
|
||||
extern void
|
||||
_jit_load(jit_state_t*, jit_int32_t);
|
||||
|
||||
#define jit_optimize() _jit_optimize(_jit)
|
||||
extern void
|
||||
_jit_optimize(jit_state_t*);
|
||||
|
||||
#define jit_classify(code) _jit_classify(_jit, code)
|
||||
extern jit_int32_t
|
||||
_jit_classify(jit_state_t*, jit_code_t);
|
||||
|
||||
#define jit_regarg_p(n, r) _jit_regarg_p(_jit, n, r)
|
||||
extern jit_bool_t
|
||||
_jit_regarg_p(jit_state_t*, jit_node_t*, jit_int32_t);
|
||||
|
||||
#define emit_ldxi(r0, r1, i0) _emit_ldxi(_jit, r0, r1, i0)
|
||||
extern void
|
||||
_emit_ldxi(jit_state_t*, jit_int32_t, jit_int32_t, jit_word_t);
|
||||
|
||||
#define emit_stxi(i0, r0, r1) _emit_stxi(_jit, i0, r0, r1)
|
||||
extern void
|
||||
_emit_stxi(jit_state_t*, jit_word_t, jit_int32_t, jit_int32_t);
|
||||
|
||||
#define emit_ldxi_d(r0, r1, i0) _emit_ldxi_d(_jit, r0, r1, i0)
|
||||
extern void
|
||||
_emit_ldxi_d(jit_state_t*, jit_int32_t, jit_int32_t, jit_word_t);
|
||||
|
||||
#define emit_stxi_d(i0, r0, r1) _emit_stxi(_jit, i0, r0, r1)
|
||||
extern void
|
||||
_emit_stxi_d(jit_state_t*, jit_word_t, jit_int32_t, jit_int32_t);
|
||||
|
||||
extern void jit_init_debug();
|
||||
extern void jit_finish_debug();
|
||||
|
||||
/*
|
||||
* Externs
|
||||
*/
|
||||
extern jit_register_t _rvs[];
|
||||
|
||||
#endif /* _jit_private_h */
|
166
include/lightning/jit_x86.h
Normal file
166
include/lightning/jit_x86.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#ifndef _jit_x86_h
|
||||
#define _jit_x86_h
|
||||
|
||||
#define JIT_HASH_CONSTS 1
|
||||
#define JIT_NUM_OPERANDS 2
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
#define jit_sse2_p() jit_cpu.sse2
|
||||
#define jit_x87_reg_p(reg) ((reg) >= _ST0 && (reg) <= _ST7)
|
||||
|
||||
#define JIT_RET _RAX
|
||||
#define JIT_SP _RSP
|
||||
#define JIT_FP _RBP
|
||||
typedef enum {
|
||||
#if __WORDSIZE == 32
|
||||
# define jit_arg_reg_p(i) 0
|
||||
# define jit_r(i) (_RAX + (i))
|
||||
# define jit_r_num() 3
|
||||
# define jit_v(i) (_RBX + (i))
|
||||
# define jit_v_num() 3
|
||||
# define jit_arg_reg_p(i) 0
|
||||
# define jit_f(i) (jit_cpu.sse2 ? _XMM0 + (i) : _ST0 + (i))
|
||||
# define jit_f_num() (jit_cpu.sse2 ? 8 : 6)
|
||||
# define JIT_FRET _ST0
|
||||
# define JIT_R0 _RAX
|
||||
# define JIT_R1 _RCX
|
||||
# define JIT_R2 _RDX
|
||||
_RAX, _RCX, _RDX,
|
||||
# define JIT_V0 _RBX
|
||||
# define JIT_V1 _RSI
|
||||
# define JIT_V2 _RDI
|
||||
_RBX, _RSI, _RDI,
|
||||
_RSP, _RBP,
|
||||
# define JIT_F0 (jit_sse2_p() ? _XMM0 : _ST0)
|
||||
# define JIT_F1 (jit_sse2_p() ? _XMM1 : _ST1)
|
||||
# define JIT_F2 (jit_sse2_p() ? _XMM2 : _ST2)
|
||||
# define JIT_F3 (jit_sse2_p() ? _XMM3 : _ST3)
|
||||
# define JIT_F4 (jit_sse2_p() ? _XMM4 : _ST4)
|
||||
# define JIT_F5 (jit_sse2_p() ? _XMM5 : _ST5)
|
||||
# define JIT_F6 (jit_sse2_p() ? _XMM6 : _ST6)
|
||||
# define JIT_F7 (jit_sse2_p() ? _XMM7 : _ST7)
|
||||
_XMM0, _XMM1, _XMM2, _XMM3, _XMM4, _XMM5, _XMM6, _XMM7,
|
||||
# define jit_sse_reg_p(reg) ((reg) >= _XMM0 && (reg) <= _XMM7)
|
||||
#else
|
||||
# define jit_arg_reg_p(i) ((i) >= 0 && (i) < 6)
|
||||
# define jit_r(i) (_RAX + (i))
|
||||
# define jit_r_num() 4
|
||||
# define jit_v(i) (_RBX + (i))
|
||||
# define jit_v_num() 4
|
||||
# define jit_arg_f_reg_p(i) ((i) >= 0 && (i) < 8)
|
||||
# define jit_f(index) (_XMM0 + (index))
|
||||
# define jit_f_num() 8
|
||||
# define JIT_FRET _XMM0
|
||||
# define JIT_R0 _RAX
|
||||
# define JIT_R1 _R10
|
||||
# define JIT_R2 _R11
|
||||
# define JIT_R3 _R12
|
||||
_RAX, _R10, _R11, _R12,
|
||||
# define JIT_V0 _RBX
|
||||
# define JIT_V1 _R13
|
||||
# define JIT_V2 _R14
|
||||
# define JIT_V3 _R15
|
||||
_RBX, _R13, _R14, _R15,
|
||||
# define JIT_RA0 _RDI
|
||||
# define JIT_RA1 _RSI
|
||||
# define JIT_RA2 _RDX
|
||||
# define JIT_RA3 _RCX
|
||||
# define JIT_RA4 _R8
|
||||
# define JIT_RA5 _R9
|
||||
_R9, _R8, _RCX, _RDX, _RSI, _RDI,
|
||||
_RSP, _RBP,
|
||||
# define JIT_F0 _XMM8
|
||||
# define JIT_F1 _XMM9
|
||||
# define JIT_F2 _XMM10
|
||||
# define JIT_F3 _XMM11
|
||||
# define JIT_F4 _XMM12
|
||||
# define JIT_F5 _XMM13
|
||||
# define JIT_F6 _XMM14
|
||||
# define JIT_F7 _XMM15
|
||||
_XMM8, _XMM9, _XMM10, _XMM11, _XMM12, _XMM13, _XMM14, _XMM15,
|
||||
# define JIT_FA0 _XMM0
|
||||
# define JIT_FA1 _XMM1
|
||||
# define JIT_FA2 _XMM2
|
||||
# define JIT_FA3 _XMM3
|
||||
# define JIT_FA4 _XMM4
|
||||
# define JIT_FA5 _XMM5
|
||||
# define JIT_FA6 _XMM6
|
||||
# define JIT_FA7 _XMM7
|
||||
_XMM7, _XMM6, _XMM5, _XMM4, _XMM3, _XMM2, _XMM1, _XMM0,
|
||||
# define jit_sse_reg_p(reg) ((reg) >= _XMM8 && (reg) <= _XMM0)
|
||||
#endif
|
||||
_ST0, _ST1, _ST2, _ST3, _ST4, _ST5, _ST6, _ST7,
|
||||
# define JIT_NOREG _NOREG
|
||||
_NOREG,
|
||||
} jit_reg_t;
|
||||
|
||||
typedef struct {
|
||||
/* x87 present */
|
||||
jit_uint32_t fpu : 1;
|
||||
/* cmpxchg8b instruction */
|
||||
jit_uint32_t cmpxchg8b : 1;
|
||||
/* cmov and fcmov branchless conditional mov */
|
||||
jit_uint32_t cmov : 1;
|
||||
/* mmx registers/instructions available */
|
||||
jit_uint32_t mmx : 1;
|
||||
/* sse registers/instructions available */
|
||||
jit_uint32_t sse : 1;
|
||||
/* sse2 registers/instructions available */
|
||||
jit_uint32_t sse2 : 1;
|
||||
/* sse3 instructions available */
|
||||
jit_uint32_t sse3 : 1;
|
||||
/* pcmulqdq instruction */
|
||||
jit_uint32_t pclmulqdq : 1;
|
||||
/* ssse3 suplemental sse3 instructions available */
|
||||
jit_uint32_t ssse3 : 1;
|
||||
/* fused multiply/add using ymm state */
|
||||
jit_uint32_t fma : 1;
|
||||
/* cmpxchg16b instruction */
|
||||
jit_uint32_t cmpxchg16b : 1;
|
||||
/* sse4.1 instructions available */
|
||||
jit_uint32_t sse4_1 : 1;
|
||||
/* sse4.2 instructions available */
|
||||
jit_uint32_t sse4_2 : 1;
|
||||
/* movbe instruction available */
|
||||
jit_uint32_t movbe : 1;
|
||||
/* popcnt instruction available */
|
||||
jit_uint32_t popcnt : 1;
|
||||
/* aes instructions available */
|
||||
jit_uint32_t aes : 1;
|
||||
/* avx instructions available */
|
||||
jit_uint32_t avx : 1;
|
||||
/* lahf/sahf available in 64 bits mode */
|
||||
jit_uint32_t lahf : 1;
|
||||
} jit_cpu_t;
|
||||
|
||||
#if __WORDSIZE == 32
|
||||
typedef jit_int32_t jit_regset_t;
|
||||
#else
|
||||
typedef jit_int64_t jit_regset_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
extern jit_cpu_t jit_cpu;
|
||||
|
||||
#endif /* _jit_x86_h */
|
28
lib/Makefile.am
Normal file
28
lib/Makefile.am
Normal file
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Copyright 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
|
||||
#
|
||||
# This is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This software is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
|
||||
AM_CFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE $(LIGHTNING_CFLAGS)
|
||||
liblightning_LTLIBRARIES = liblightning.la
|
||||
|
||||
liblightningdir = $(libdir)
|
||||
liblightning_la_SOURCES = \
|
||||
jit_disasm.c \
|
||||
jit_print.c \
|
||||
lightning.c
|
||||
|
||||
EXTRA_DIST = \
|
||||
jit_x86.c \
|
||||
jit_x86-cpu.c \
|
||||
jit_x86-sse.c \
|
||||
jit_x86-x87.c
|
297
lib/jit_disasm.c
Normal file
297
lib/jit_disasm.c
Normal file
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#include <lightning.h>
|
||||
#include <lightning/jit_private.h>
|
||||
#include <dis-asm.h>
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
#if DISASSEMBLER
|
||||
static int
|
||||
disasm_compare_symbols(const void *ap, const void *bp);
|
||||
|
||||
static void
|
||||
disasm_print_address(bfd_vma addr, struct disassemble_info *info);
|
||||
|
||||
static void
|
||||
disassemble(jit_pointer_t code, jit_int32_t length);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
#if DISASSEMBLER
|
||||
static bfd *disasm_bfd;
|
||||
static disassemble_info disasm_info;
|
||||
static disassembler_ftype disasm_print;
|
||||
static asymbol **disasm_symbols;
|
||||
static asymbol *disasm_synthetic;
|
||||
static long disasm_num_symbols;
|
||||
static long disasm_num_synthetic;
|
||||
#define disasm_stream stdout
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Implementation
|
||||
*/
|
||||
void
|
||||
jit_init_debug(void)
|
||||
{
|
||||
#if DISASSEMBLER
|
||||
bfd_init();
|
||||
|
||||
/* FIXME */
|
||||
disasm_bfd = bfd_openr("/proc/self/exe", NULL);
|
||||
|
||||
assert(disasm_bfd);
|
||||
bfd_check_format(disasm_bfd, bfd_object);
|
||||
bfd_check_format(disasm_bfd, bfd_archive);
|
||||
disasm_print = disassembler(disasm_bfd);
|
||||
assert(disasm_print);
|
||||
INIT_DISASSEMBLE_INFO(disasm_info, disasm_stream, fprintf);
|
||||
# if defined(__i386__) || defined(__x86_64__)
|
||||
disasm_info.arch = bfd_arch_i386;
|
||||
# if defined(__x86_64__)
|
||||
disasm_info.mach = bfd_mach_x86_64;
|
||||
# else
|
||||
disasm_info.mach = bfd_mach_i386_i386;
|
||||
# endif
|
||||
# endif
|
||||
# if defined(__arm__)
|
||||
/* FIXME add mapping for prolog switching to arm and possible jump
|
||||
* before first prolog also in arm mode */
|
||||
if (jit_cpu.thumb)
|
||||
disasm_info.disassembler_options = "force-thumb";
|
||||
# endif
|
||||
disasm_info.print_address_func = disasm_print_address;
|
||||
|
||||
if (bfd_get_file_flags(disasm_bfd) & HAS_SYMS) {
|
||||
asymbol **in;
|
||||
asymbol **out;
|
||||
asymbol *symbol;
|
||||
long offset;
|
||||
long sym_count;
|
||||
long dyn_count;
|
||||
long sym_storage;
|
||||
long dyn_storage;
|
||||
|
||||
sym_storage = bfd_get_symtab_upper_bound(disasm_bfd);
|
||||
assert(sym_storage >= 0);
|
||||
|
||||
if (bfd_get_file_flags(disasm_bfd) & DYNAMIC) {
|
||||
dyn_storage = bfd_get_dynamic_symtab_upper_bound(disasm_bfd);
|
||||
assert(dyn_storage >= 0);
|
||||
}
|
||||
else
|
||||
dyn_storage = 0;
|
||||
|
||||
disasm_symbols = malloc(sym_storage + dyn_storage);
|
||||
sym_count = bfd_canonicalize_symtab(disasm_bfd, disasm_symbols);
|
||||
assert(sym_count >= 0);
|
||||
if (dyn_storage) {
|
||||
dyn_count = bfd_canonicalize_dynamic_symtab(disasm_bfd,
|
||||
disasm_symbols +
|
||||
sym_count);
|
||||
assert(dyn_count >= 0);
|
||||
}
|
||||
else
|
||||
dyn_count = 0;
|
||||
disasm_num_symbols = sym_count + dyn_count;
|
||||
|
||||
disasm_num_synthetic = bfd_get_synthetic_symtab(disasm_bfd,
|
||||
sym_count,
|
||||
disasm_symbols,
|
||||
dyn_count,
|
||||
disasm_symbols +
|
||||
sym_count,
|
||||
&disasm_synthetic);
|
||||
if (disasm_num_synthetic > 0) {
|
||||
disasm_symbols = realloc(disasm_symbols,
|
||||
sym_storage + dyn_storage +
|
||||
disasm_num_synthetic * sizeof(asymbol *));
|
||||
for (offset = 0; offset < disasm_num_synthetic; offset++)
|
||||
disasm_symbols[disasm_num_symbols++] =
|
||||
disasm_synthetic + offset;
|
||||
}
|
||||
|
||||
/* remove symbols not useful for disassemble */
|
||||
in = out = disasm_symbols;
|
||||
for (offset = 0; offset < disasm_num_symbols; offset++) {
|
||||
symbol = *in++;
|
||||
if (symbol->name &&
|
||||
symbol->name[0] != '\0' &&
|
||||
!(symbol->flags & (BSF_DEBUGGING | BSF_SECTION_SYM)) &&
|
||||
!bfd_is_und_section(symbol->section) &&
|
||||
!bfd_is_com_section(symbol->section))
|
||||
*out++ = symbol;
|
||||
}
|
||||
disasm_num_symbols = out - disasm_symbols;
|
||||
qsort(disasm_symbols, disasm_num_symbols,
|
||||
sizeof(asymbol *), disasm_compare_symbols);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
jit_finish_debug(void)
|
||||
{
|
||||
#if DISASSEMBLER
|
||||
if (disasm_synthetic)
|
||||
free(disasm_synthetic);
|
||||
if (disasm_symbols)
|
||||
free(disasm_symbols);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_jit_disassemble(jit_state_t *_jit)
|
||||
{
|
||||
#if DISASSEMBLER
|
||||
disassemble(_jit->code.ptr, _jit->pc.uc - _jit->code.ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DISASSEMBLER
|
||||
/* Based on objdump source */
|
||||
static int
|
||||
disasm_compare_symbols(const void *ap, const void *bp)
|
||||
{
|
||||
const asymbol *a = *(const asymbol **)ap;
|
||||
const asymbol *b = *(const asymbol **)bp;
|
||||
|
||||
if (bfd_asymbol_value(a) > bfd_asymbol_value(b))
|
||||
return (1);
|
||||
if (bfd_asymbol_value(a) < bfd_asymbol_value(b))
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if __WORDSIZE == 32
|
||||
# define address_buffer_length 16
|
||||
# define address_buffer_format "%llx"
|
||||
#else
|
||||
# define address_buffer_length 32
|
||||
# define address_buffer_format "%lx"
|
||||
#endif
|
||||
static void
|
||||
disasm_print_address(bfd_vma addr, struct disassemble_info *info)
|
||||
{
|
||||
char buffer[address_buffer_length];
|
||||
|
||||
sprintf(buffer, address_buffer_format, (jit_word_t)addr);
|
||||
(*info->fprintf_func)(info->stream, "0x%s", buffer);
|
||||
|
||||
if (disasm_num_symbols) {
|
||||
long low;
|
||||
long high;
|
||||
long offset;
|
||||
asymbol *symbol;
|
||||
|
||||
low = 0;
|
||||
high = disasm_num_symbols;
|
||||
do {
|
||||
offset = (low + high) >> 1;
|
||||
symbol = disasm_symbols[offset];
|
||||
if (bfd_asymbol_value(symbol) > addr)
|
||||
high = offset - 1;
|
||||
else if (bfd_asymbol_value(symbol) < addr)
|
||||
low = offset + 1;
|
||||
else
|
||||
break;
|
||||
} while (low < high);
|
||||
|
||||
if (offset >= 0 && offset < disasm_num_symbols) {
|
||||
if (bfd_asymbol_value(symbol) < addr) {
|
||||
while (++offset < disasm_num_symbols) {
|
||||
symbol = disasm_symbols[offset];
|
||||
if (bfd_asymbol_value(symbol) >= addr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (bfd_asymbol_value(symbol) > addr) {
|
||||
while (offset--) {
|
||||
if (bfd_asymbol_value(disasm_symbols[offset]) < addr)
|
||||
break;
|
||||
symbol = disasm_symbols[offset];
|
||||
}
|
||||
}
|
||||
if (bfd_asymbol_value(symbol) == addr)
|
||||
(*info->fprintf_func)(info->stream, " # %s", symbol->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disassemble(jit_pointer_t code, jit_int32_t length)
|
||||
{
|
||||
int bytes;
|
||||
#if __arm__
|
||||
jit_data_info_t *data_info;
|
||||
jit_int32_t data_offset;
|
||||
#endif
|
||||
bfd_vma pc = (jit_uword_t)code;
|
||||
bfd_vma end = (jit_uword_t)code + length;
|
||||
char buffer[address_buffer_length];
|
||||
|
||||
#if __arm__
|
||||
data_info = _jit->data_info;
|
||||
data_offset = 0;
|
||||
#endif
|
||||
disasm_info.buffer = code;
|
||||
disasm_info.buffer_vma = (jit_uword_t)code;
|
||||
disasm_info.buffer_length = length;
|
||||
while (pc < end) {
|
||||
#if __arm__
|
||||
again:
|
||||
if (data_info) {
|
||||
while (data_info.ptr[data_offset].code < pc) {
|
||||
data_offset += 2;
|
||||
if (data_offset >= data_info.length) {
|
||||
data_info = NULL;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
if (pc == data_info.ptr[data_offset].code) {
|
||||
line = data_info.ptr[data_offset].length;
|
||||
for (; line >= 4; line -= 4, pc += 4) {
|
||||
bytes = sprintf(buffer, address_buffer_format, pc);
|
||||
(*disasm_info.fprintf_func)(disasm_stream,
|
||||
"%*c0x%s\t.data\t0x%08x\n",
|
||||
16 - bytes, ' ', buffer,
|
||||
*(jit_uint32_t *)
|
||||
(jit_uint32_t)pc);
|
||||
}
|
||||
/* reset disassemble information instead of attempting
|
||||
* to hack the arm specific backend data structures to
|
||||
* tell it to forward the required number of bytes. */
|
||||
disasm_info.buffer = (jit_pointer_t)(jit_uint32_t)pc;
|
||||
disasm_info.buffer_vma = (jit_uword_t)pc;
|
||||
if ((disasm_info.buffer_length = end - pc) <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
bytes = sprintf(buffer, address_buffer_format, (jit_word_t)pc);
|
||||
(*disasm_info.fprintf_func)(disasm_stream, "%*c0x%s\t",
|
||||
16 - bytes, ' ', buffer);
|
||||
pc += (*disasm_print)(pc, &disasm_info);
|
||||
putc('\n', disasm_stream);
|
||||
}
|
||||
}
|
||||
#endif
|
427
lib/jit_print.c
Normal file
427
lib/jit_print.c
Normal file
|
@ -0,0 +1,427 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Authors:
|
||||
* Paulo Cesar Pereira de Andrade
|
||||
*/
|
||||
|
||||
#include <lightning.h>
|
||||
#include <lightning/jit_private.h>
|
||||
|
||||
#define print_chr(value) fputc(value, stdout)
|
||||
#define print_hex(value) fprintf(stdout, "0x%lx", value)
|
||||
#define print_dec(value) fprintf(stdout, "%ld", value)
|
||||
#define print_flt(value) fprintf(stdout, "%g", value)
|
||||
#define print_str(value) fprintf(stdout, "%s", value)
|
||||
#define print_ptr(value) fprintf(stdout, "%p", value)
|
||||
#define print_reg(value) \
|
||||
do { \
|
||||
if ((value) & jit_regno_patch) \
|
||||
print_chr('?'); \
|
||||
print_str(_rvs[jit_regno(value)].name); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
static char *code_name[] = {
|
||||
"data",
|
||||
"save", "load",
|
||||
"#note",
|
||||
"label",
|
||||
"prolog",
|
||||
"addr", "addi",
|
||||
"addxr", "addxi",
|
||||
"addcr", "addci",
|
||||
"subr", "subi",
|
||||
"subxr", "subxi",
|
||||
"subcr", "subci",
|
||||
"mulr", "muli",
|
||||
"divr", "divi",
|
||||
"divr_u", "divi_u",
|
||||
"remr", "remi",
|
||||
"remr_u", "remi_u",
|
||||
"andr", "andi",
|
||||
"orr", "ori",
|
||||
"xorr", "xori",
|
||||
"lshr", "lshi",
|
||||
"rshr", "rshi",
|
||||
"rshr_u", "rshi_u",
|
||||
"negr", "comr",
|
||||
"ltr", "lti",
|
||||
"ltr_u", "lti_u",
|
||||
"ler", "lei",
|
||||
"ler_u", "lei_u",
|
||||
"eqr", "eqi",
|
||||
"ger", "gei",
|
||||
"ger_u", "gei_u",
|
||||
"gtr", "gti",
|
||||
"gtr_u", "gti_u",
|
||||
"ner", "nei",
|
||||
"movr", "movi",
|
||||
"extr_c", "extr_uc",
|
||||
"extr_s", "extr_us",
|
||||
"extr_i", "extr_ui",
|
||||
"htonr",
|
||||
"ldr_c", "ldi_c",
|
||||
"ldr_uc", "ldi_uc",
|
||||
"ldr_s", "ldi_s",
|
||||
"ldr_us", "ldi_us",
|
||||
"ldr_i", "ldi_i",
|
||||
"ldr_ui", "ldi_ui",
|
||||
"ldr_l", "ldi_l",
|
||||
"ldxr_c", "ldxi_c",
|
||||
"ldxr_uc", "ldxi_uc",
|
||||
"ldxr_s", "ldxi_s",
|
||||
"ldxr_us", "ldxi_us",
|
||||
"ldxr_i", "ldxi_i",
|
||||
"ldxr_ui", "ldxi_ui",
|
||||
"ldxr_l", "ldxi_l",
|
||||
"str_c", "sti_c",
|
||||
"str_s", "sti_s",
|
||||
"str_i", "sti_i",
|
||||
"str_l", "sti_l",
|
||||
"stxr_c", "stxi_c",
|
||||
"stxr_s", "stxi_s",
|
||||
"stxr_i", "stxi_i",
|
||||
"stxr_l", "stxi_l",
|
||||
"bltr", "blti",
|
||||
"bltr_u", "blti_u",
|
||||
"bler", "blei",
|
||||
"bler_u", "blei_u",
|
||||
"beqr", "beqi",
|
||||
"bger", "bgei",
|
||||
"bger_u", "bgei_u",
|
||||
"bgtr", "bgti",
|
||||
"bgtr_u", "bgti_u",
|
||||
"bner", "bnei",
|
||||
"bmsr", "bmsi",
|
||||
"bmcr", "bmci",
|
||||
"boaddr", "boaddi",
|
||||
"boaddr_u", "boaddi_u",
|
||||
"bxaddr", "bxaddi",
|
||||
"bxaddr_u", "bxaddi_u",
|
||||
"bosubr", "bosubi",
|
||||
"bosubr_u", "bosubi_u",
|
||||
"bxsubr", "bxsubi",
|
||||
"bxsubr_u", "bxsubi_u",
|
||||
"jmpr", "jmpi",
|
||||
"callr", "calli",
|
||||
"epilog",
|
||||
"addr_f", "addi_f",
|
||||
"subr_f", "subi_f",
|
||||
"mulr_f", "muli_f",
|
||||
"divr_f", "divi_f",
|
||||
"negr_f", "absr_f",
|
||||
"sqrtr_f",
|
||||
"ltr_f", "lti_f",
|
||||
"ler_f", "lei_f",
|
||||
"eqr_f", "eqi_f",
|
||||
"ger_f", "gei_f",
|
||||
"gtr_f", "gti_f",
|
||||
"ner_f", "nei_f",
|
||||
"unltr_f", "unlti_f",
|
||||
"unler_f", "unlei_f",
|
||||
"uneqr_f", "uneqi_f",
|
||||
"unger_f", "ungei_f",
|
||||
"ungtr_f", "ungti_f",
|
||||
"ltgtr_f", "ltgti_f",
|
||||
"ordr_f", "ordi_f",
|
||||
"unordr_f", "unordi_f",
|
||||
"truncr_f_i", "truncr_f_l",
|
||||
"extr_f", "extr_d_f",
|
||||
"movr_f", "movi_f",
|
||||
"ldr_f", "ldi_f",
|
||||
"ldxr_f", "ldxi_f",
|
||||
"str_f", "sti_f",
|
||||
"stxr_f", "stxi_f",
|
||||
"bltr_f", "blti_f",
|
||||
"bler_f", "blei_f",
|
||||
"beqr_f", "beqi_f",
|
||||
"bger_f", "bgei_f",
|
||||
"bgtr_f", "bgti_f",
|
||||
"bner_f", "bnei_f",
|
||||
"bunltr_f", "bunlti_f",
|
||||
"bunler_f", "bunlei_f",
|
||||
"buneqr_f", "buneqi_f",
|
||||
"bunger_f", "bungei_f",
|
||||
"bungtr_f", "bungti_f",
|
||||
"bltgtr_f", "bltgti_f",
|
||||
"bordr_f", "bordi_f",
|
||||
"bunordr_f", "bunordi_f",
|
||||
"retval_f",
|
||||
"addr_d", "addi_d",
|
||||
"subr_d", "subi_d",
|
||||
"mulr_d", "muli_d",
|
||||
"divr_d", "divi_d",
|
||||
"negr_d", "absr_d",
|
||||
"sqrtr_d",
|
||||
"ltr_d", "lti_d",
|
||||
"ler_d", "lei_d",
|
||||
"eqr_d", "eqi_d",
|
||||
"ger_d", "gei_d",
|
||||
"gtr_d", "gti_d",
|
||||
"ner_d", "nei_d",
|
||||
"unltr_d", "unlti_d",
|
||||
"unler_d", "unlei_d",
|
||||
"uneqr_d", "uneqi_d",
|
||||
"unger_d", "ungei_d",
|
||||
"ungtr_d", "ungti_d",
|
||||
"ltgtr_d", "ltgti_d",
|
||||
"ordr_d", "ordi_d",
|
||||
"unordr_d", "unordi_d",
|
||||
"truncr_d_i", "truncr_d_l",
|
||||
"extr_d", "extr_f_d",
|
||||
"movr_d", "movi_d",
|
||||
"ldr_d", "ldi_d",
|
||||
"ldxr_d", "ldxi_d",
|
||||
"str_d", "sti_d",
|
||||
"stxr_d", "stxi_d",
|
||||
"bltr_d", "blti_d",
|
||||
"bler_d", "blei_d",
|
||||
"beqr_d", "beqi_d",
|
||||
"bger_d", "bgei_d",
|
||||
"bgtr_d", "bgti_d",
|
||||
"bner_d", "bnei_d",
|
||||
"bunltr_d", "bunlti_d",
|
||||
"bunler_d", "bunlei_d",
|
||||
"buneqr_d", "buneqi_d",
|
||||
"bunger_d", "bungei_d",
|
||||
"bungtr_d", "bungti_d",
|
||||
"bltgtr_d", "bltgti_d",
|
||||
"bordr_d", "bordi_d",
|
||||
"bunordr_d", "bunordi_d",
|
||||
"retval_d",
|
||||
};
|
||||
|
||||
/*
|
||||
* Implementation
|
||||
*/
|
||||
void
|
||||
_jit_print(jit_state_t *_jit)
|
||||
{
|
||||
jit_node_t *node;
|
||||
jit_block_t *block;
|
||||
jit_bool_t first;
|
||||
jit_int32_t value;
|
||||
jit_int32_t offset;
|
||||
|
||||
first = 0;
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
if (!first)
|
||||
print_chr('\n');
|
||||
else
|
||||
first = 0;
|
||||
if (node->code == jit_code_label ||
|
||||
node->code == jit_code_prolog || node->code == jit_code_epilog) {
|
||||
print_chr('L');
|
||||
print_dec(node->v.w);
|
||||
print_chr(':');
|
||||
block = _jit->blocks.ptr + node->v.w;
|
||||
for (offset = 0; offset < _jit->reglen; offset++) {
|
||||
if (jit_regset_tstbit(block->reglive, offset)) {
|
||||
print_chr(' ');
|
||||
print_reg(offset);
|
||||
}
|
||||
}
|
||||
if (node->code == jit_code_prolog ||
|
||||
node->code == jit_code_epilog) {
|
||||
print_str(" /* ");
|
||||
print_str(code_name[node->code]);
|
||||
print_str(" */");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
value = jit_classify(node->code) &
|
||||
(jit_cc_a0_int|jit_cc_a0_jmp|jit_cc_a0_reg|
|
||||
jit_cc_a1_reg|jit_cc_a1_int|jit_cc_a1_flt|jit_cc_a1_dbl|
|
||||
jit_cc_a2_reg|jit_cc_a2_int|jit_cc_a2_flt|jit_cc_a2_dbl);
|
||||
if (value & jit_cc_a0_jmp)
|
||||
print_str(" ");
|
||||
else
|
||||
print_chr('\t');
|
||||
print_str(code_name[node->code]);
|
||||
switch (node->code) {
|
||||
r:
|
||||
print_chr(' '); print_reg(node->u.w); continue;
|
||||
n:
|
||||
print_chr(' ');
|
||||
if (!(node->flag & jit_flag_node))
|
||||
print_ptr(node->u.p);
|
||||
else {
|
||||
print_chr('L');
|
||||
print_dec(node->u.n->v.w);
|
||||
}
|
||||
continue;
|
||||
r_r:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w); continue;
|
||||
r_w:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' '); print_hex(node->v.w); continue;
|
||||
r_f:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' ');
|
||||
if (node->flag & jit_flag_data)
|
||||
print_flt(*(jit_float32_t *)node->v.n->u.w);
|
||||
else
|
||||
print_flt(node->v.f);
|
||||
continue;
|
||||
r_d:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' ');
|
||||
if (node->flag & jit_flag_data)
|
||||
print_flt(*(jit_float64_t *)node->v.n->u.w);
|
||||
else
|
||||
print_flt(node->v.d);
|
||||
continue;
|
||||
w_r:
|
||||
print_chr(' '); print_hex(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w); continue;
|
||||
r_r_r:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' '); print_reg(node->w.w); continue;
|
||||
r_r_w:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' '); print_hex(node->w.w); continue;
|
||||
r_r_f:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' ');
|
||||
if (node->flag & jit_flag_data)
|
||||
print_flt(*(jit_float32_t *)node->w.n->u.w);
|
||||
else
|
||||
print_flt(node->w.f);
|
||||
continue;
|
||||
r_r_d:
|
||||
print_chr(' '); print_reg(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' ');
|
||||
if (node->flag & jit_flag_data)
|
||||
print_flt(*(jit_float64_t *)node->w.n->u.w);
|
||||
else
|
||||
print_flt(node->w.d);
|
||||
continue;
|
||||
w_r_r:
|
||||
print_chr(' '); print_hex(node->u.w);
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' '); print_reg(node->w.w); continue;
|
||||
n_r_r:
|
||||
print_chr(' ');
|
||||
if (!(node->flag & jit_flag_node))
|
||||
print_ptr(node->u.p);
|
||||
else {
|
||||
print_chr('L');
|
||||
print_dec(node->u.n->v.w);
|
||||
}
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' '); print_reg(node->w.w); continue;
|
||||
n_r_w:
|
||||
print_chr(' ');
|
||||
if (!(node->flag & jit_flag_node))
|
||||
print_ptr(node->u.p);
|
||||
else {
|
||||
print_chr('L');
|
||||
print_dec(node->u.n->v.w);
|
||||
}
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' '); print_hex(node->w.w); continue;
|
||||
n_r_f:
|
||||
print_chr(' ');
|
||||
if (!(node->flag & jit_flag_node))
|
||||
print_ptr(node->u.p);
|
||||
else{
|
||||
print_chr('L');
|
||||
print_dec(node->u.n->v.w);
|
||||
}
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' ');
|
||||
if (node->flag & jit_flag_data)
|
||||
print_flt(*(jit_float32_t *)node->w.n->u.w);
|
||||
else
|
||||
print_flt(node->w.f);
|
||||
continue;
|
||||
n_r_d:
|
||||
print_chr(' ');
|
||||
if (!(node->flag & jit_flag_node))
|
||||
print_ptr(node->u.p);
|
||||
else {
|
||||
print_chr('L');
|
||||
print_dec(node->u.n->v.w);
|
||||
}
|
||||
print_chr(' '); print_reg(node->v.w);
|
||||
print_chr(' ');
|
||||
if (node->flag & jit_flag_data)
|
||||
print_flt(*(jit_float64_t *)node->w.n->u.w);
|
||||
else
|
||||
print_flt(node->w.d);
|
||||
continue;
|
||||
|
||||
case jit_code_note:
|
||||
/* FIXME should be name:line information */
|
||||
print_chr(' ');
|
||||
print_ptr(node->v.p);
|
||||
break;
|
||||
|
||||
case jit_code_data:
|
||||
case jit_code_label:
|
||||
case jit_code_prolog: case jit_code_epilog:
|
||||
break;
|
||||
case jit_code_save: case jit_code_load:
|
||||
goto r;
|
||||
default:
|
||||
switch (value) {
|
||||
case jit_cc_a0_reg:
|
||||
case jit_cc_a0_reg|jit_cc_a0_chg:
|
||||
case jit_cc_a0_reg|jit_cc_a0_jmp:
|
||||
goto r;
|
||||
case jit_cc_a0_jmp:
|
||||
goto n;
|
||||
case jit_cc_a0_reg|jit_cc_a1_reg:
|
||||
goto r_r;
|
||||
case jit_cc_a0_reg|jit_cc_a1_int:
|
||||
goto r_w;
|
||||
case jit_cc_a0_reg|jit_cc_a1_flt:
|
||||
goto r_f;
|
||||
case jit_cc_a0_reg|jit_cc_a1_dbl:
|
||||
goto r_d;
|
||||
case jit_cc_a0_int|jit_cc_a1_reg:
|
||||
goto w_r;
|
||||
case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_reg:
|
||||
goto r_r_r;
|
||||
case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_int:
|
||||
goto r_r_w;
|
||||
case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_flt:
|
||||
goto r_r_f;
|
||||
case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_dbl:
|
||||
goto r_r_d;
|
||||
case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_reg:
|
||||
goto w_r_r;
|
||||
case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_reg:
|
||||
goto n_r_r;
|
||||
case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_int:
|
||||
goto n_r_w;
|
||||
case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_flt:
|
||||
goto n_r_f;
|
||||
case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_dbl:
|
||||
goto n_r_d;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
print_chr('\n');
|
||||
}
|
3118
lib/jit_x86-cpu.c
Normal file
3118
lib/jit_x86-cpu.c
Normal file
File diff suppressed because it is too large
Load diff
1439
lib/jit_x86-sse.c
Normal file
1439
lib/jit_x86-sse.c
Normal file
File diff suppressed because it is too large
Load diff
1215
lib/jit_x86-x87.c
Normal file
1215
lib/jit_x86-x87.c
Normal file
File diff suppressed because it is too large
Load diff
1699
lib/jit_x86.c
Normal file
1699
lib/jit_x86.c
Normal file
File diff suppressed because it is too large
Load diff
2306
lib/lightning.c
Normal file
2306
lib/lightning.c
Normal file
File diff suppressed because it is too large
Load diff
62
lightning.h
62
lightning.h
|
@ -1,62 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* lightning main include file
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef __lightning_h
|
||||
#define __lightning_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <lightning/asm-common.h>
|
||||
|
||||
#ifndef LIGHTNING_DEBUG
|
||||
#include <lightning/asm.h>
|
||||
#endif
|
||||
|
||||
#include <lightning/core.h>
|
||||
#include <lightning/core-common.h>
|
||||
#include <lightning/funcs-common.h>
|
||||
#include <lightning/funcs.h>
|
||||
#include <lightning/fp.h>
|
||||
#include <lightning/fp-common.h>
|
||||
|
||||
#ifndef JIT_R0
|
||||
#error GNU lightning does not support the current target
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __lightning_h */
|
|
@ -1,78 +0,0 @@
|
|||
dnl I'd like this to be edited in -*- Autoconf -*- mode...
|
||||
dnl
|
||||
# serial 2 LIGHTNING_CONFIGURE_IF_NOT_FOUND
|
||||
m4_define([LIGHTNING_BACKENDS], [i386 i386:-32 i386:-64 sparc ppc])
|
||||
|
||||
AC_DEFUN([LIGHTNING_CONFIGURE_LINKS_PREREQ], [
|
||||
lightning_frag=/dev/null
|
||||
AC_SUBST_FILE(lightning_frag)])
|
||||
|
||||
AC_DEFUN([LIGHTNING_CONFIGURE_LINKS], [
|
||||
AC_REQUIRE([LIGHTNING_CONFIGURE_LINKS_PREREQ])
|
||||
|
||||
suffix=
|
||||
case "$target_cpu" in
|
||||
i?86) cpu=i386 ;;
|
||||
x86_64) cpu=i386 ;;
|
||||
sparc*) cpu=sparc ;;
|
||||
powerpc) cpu=ppc ;;
|
||||
*) ;;
|
||||
esac
|
||||
if test -n "$cpu" && test -d "$srcdir/lightning/$cpu"; then
|
||||
$1
|
||||
lightning_frag=`cd $srcdir && pwd`/lightning/$cpu/Makefile.frag
|
||||
test -f $lightning_frag || lightning_frag=/dev/null
|
||||
|
||||
asm_src=lightning/$cpu/asm.h
|
||||
test -f $srcdir/lightning/$cpu/asm$suffix.h && asm_src=lightning/$cpu/asm$suffix.h
|
||||
AC_CONFIG_LINKS(lightning/asm.h:$asm_src, [], [asm_src=$asm_src])
|
||||
|
||||
fp_src=lightning/$cpu/fp.h
|
||||
test -f $srcdir/lightning/$cpu/fp$suffix.h && fp_src=lightning/$cpu/fp$suffix.h
|
||||
AC_CONFIG_LINKS(lightning/fp.h:$fp_src, [], [fp_src=$fp_src])
|
||||
|
||||
core_src=lightning/$cpu/core.h
|
||||
test -f $srcdir/lightning/$cpu/core$suffix.h && core_src=lightning/$cpu/core$suffix.h
|
||||
AC_CONFIG_LINKS(lightning/core.h:$core_src, [], [core_src=$core_src])
|
||||
|
||||
funcs_src=lightning/$cpu/funcs.h
|
||||
test -f $srcdir/lightning/$cpu/funcs$suffix.h && funcs_src=lightning/$cpu/funcs$suffix.h
|
||||
AC_CONFIG_LINKS(lightning/funcs.h:$funcs_src, [], [funcs_src=$funcs_src])
|
||||
else
|
||||
$2
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
AC_DEFUN([LIGHTNING_CONFIGURE_IF_NOT_FOUND], [
|
||||
AC_REQUIRE([AC_PROG_LN_S])dnl
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])dnl
|
||||
|
||||
AC_ARG_WITH(lightning-prefix,
|
||||
AS_HELP_STRING([--with-lightning-prefix=PFX], [Prefix where GNU lightning is installed]),
|
||||
[], [with_lightning_prefix=])
|
||||
saveCFLAGS="$CFLAGS"
|
||||
if test "x$with_lightning_prefix" != x; then
|
||||
INCLIGHTNING="-I${with_lightning_prefix}/include"
|
||||
CFLAGS="$CFLAGS $INCLIGHTNING"
|
||||
else
|
||||
INCLIGHTNING=
|
||||
fi
|
||||
AC_CHECK_HEADER(lightning.h)
|
||||
CFLAGS="$saveCFLAGS"
|
||||
|
||||
AM_CONDITIONAL(LIGHTNING_MAIN, (exit 1))
|
||||
AM_CONDITIONAL(HAVE_INSTALLED_LIGHTNING, test "$ac_cv_header_lightning_h" = yes)
|
||||
|
||||
lightning=
|
||||
AS_IF([test "$ac_cv_header_lightning_h" = yes],
|
||||
[lightning=yes],
|
||||
[LIGHTNING_CONFIGURE_LINKS(lightning=yes, lightning=no)])
|
||||
|
||||
AS_IF([test "$lightning" = yes], [
|
||||
AC_DEFINE(HAVE_LIGHTNING, 1, [Define if GNU lightning can be used])
|
||||
$1
|
||||
], [$2])
|
||||
unset lightning
|
||||
|
||||
])dnl
|
123
tests/3to2.c
123
tests/3to2.c
|
@ -1,123 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test ternary->binary op conversion
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2008 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
double
|
||||
test_double (int a, int b, int c)
|
||||
{
|
||||
double x;
|
||||
int ofs;
|
||||
|
||||
jit_set_ip (codeBuffer);
|
||||
jit_leaf (2);
|
||||
ofs = jit_arg_d ();
|
||||
jit_getarg_d (b, ofs);
|
||||
ofs = jit_arg_d ();
|
||||
jit_getarg_d (c, ofs);
|
||||
jit_subr_d (a,b,c);
|
||||
jit_movr_d (JIT_FPRET, a);
|
||||
jit_ret ();
|
||||
|
||||
jit_flush_code ((char *) codeBuffer, jit_get_ip ().ptr);
|
||||
|
||||
x = ((double (*) (double, double)) codeBuffer) (3.0, 2.0);
|
||||
printf ("%g %g\n", ((b == c) ? 0.0 : 1.0), x);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
double
|
||||
test_int (int a, int b, int c)
|
||||
{
|
||||
int x;
|
||||
int ofs;
|
||||
|
||||
jit_set_ip (codeBuffer);
|
||||
jit_leaf (2);
|
||||
ofs = jit_arg_i ();
|
||||
jit_getarg_i (b, ofs);
|
||||
ofs = jit_arg_i ();
|
||||
jit_getarg_i (c, ofs);
|
||||
jit_subr_i (a,b,c);
|
||||
jit_movr_i (JIT_RET, a);
|
||||
jit_ret ();
|
||||
|
||||
jit_flush_code ((char *) codeBuffer, jit_get_ip ().ptr);
|
||||
|
||||
x = ((int (*) (int, int)) codeBuffer) (3, 2);
|
||||
printf ("%d %d\n", ((b == c) ? 0 : 1), x);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
test_double (JIT_FPR0, JIT_FPR0, JIT_FPR0);
|
||||
test_double (JIT_FPR0, JIT_FPR0, JIT_FPR1);
|
||||
test_double (JIT_FPR0, JIT_FPR1, JIT_FPR0);
|
||||
test_double (JIT_FPR0, JIT_FPR1, JIT_FPR2);
|
||||
|
||||
test_double (JIT_FPR3, JIT_FPR3, JIT_FPR3);
|
||||
test_double (JIT_FPR3, JIT_FPR3, JIT_FPR1);
|
||||
test_double (JIT_FPR3, JIT_FPR1, JIT_FPR3);
|
||||
test_double (JIT_FPR3, JIT_FPR1, JIT_FPR2);
|
||||
|
||||
test_double (JIT_FPR3, JIT_FPR0, JIT_FPR0);
|
||||
test_double (JIT_FPR3, JIT_FPR0, JIT_FPR3);
|
||||
test_double (JIT_FPR3, JIT_FPR3, JIT_FPR0);
|
||||
|
||||
test_int (JIT_R0, JIT_R0, JIT_R0);
|
||||
test_int (JIT_R0, JIT_R0, JIT_R1);
|
||||
test_int (JIT_R0, JIT_R1, JIT_R0);
|
||||
test_int (JIT_R0, JIT_R1, JIT_R2);
|
||||
|
||||
test_int (JIT_V0, JIT_V0, JIT_V0);
|
||||
test_int (JIT_V0, JIT_V0, JIT_R1);
|
||||
test_int (JIT_V0, JIT_R1, JIT_V0);
|
||||
test_int (JIT_V0, JIT_R1, JIT_R2);
|
||||
|
||||
test_int (JIT_V0, JIT_R0, JIT_R0);
|
||||
test_int (JIT_V0, JIT_R0, JIT_V0);
|
||||
test_int (JIT_V0, JIT_V0, JIT_R0);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
0 0
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
0 0
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
0 0
|
||||
1 1
|
||||
1 1
|
||||
0 0
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
0 0
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
0 0
|
||||
1 1
|
||||
1 1
|
|
@ -1,22 +0,0 @@
|
|||
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/lightning/$(cpu)
|
||||
|
||||
check_PROGRAMS = fibit incr printf printf2 rpn fib fibdelay \
|
||||
add bp testfp funcfp rpnfp modi ldxi divi movi ret \
|
||||
allocai sete 3to2 ldst
|
||||
|
||||
noinst_DATA = fibit.ok incr.ok printf.ok printf2.ok rpn.ok \
|
||||
fib.ok fibdelay.ok testfp.ok funcfp.ok rpnfp.ok add.ok \
|
||||
bp.ok modi.ok ldxi.ok divi.ok movi.ok ret.ok \
|
||||
allocai.ok sete.ok 3to2.ok ldst.ok
|
||||
|
||||
EXTRA_DIST = $(noinst_DATA) run-test
|
||||
|
||||
if REGRESSION_TESTING
|
||||
TESTS = fib fibit fibdelay incr printf printf2 rpn add bp \
|
||||
testfp funcfp rpnfp modi ldxi divi movi ret allocai \
|
||||
sete 3to2 ldst
|
||||
|
||||
TESTS_ENVIRONMENT=$(srcdir)/run-test
|
||||
endif
|
||||
|
||||
ldst_CFLAGS = -ffloat-store
|
60
tests/add.c
60
tests/add.c
|
@ -1,60 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample call for using arguments in GNU lightning
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static char codeBuffer[1024];
|
||||
|
||||
typedef int (*pifii)(int, int); /* Pointer to Int Function of Int, Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
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_addr_i(JIT_RET, JIT_R0, JIT_R1);
|
||||
jit_ret();
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
/* call the generated code, passing its size as argument */
|
||||
printf("%d + %d = %d\n", 5, 4, myFunction(5, 4));
|
||||
return 0;
|
||||
}
|
109
tests/allocai.c
109
tests/allocai.c
|
@ -1,109 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test `jit_allocai'
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtès. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lightning.h"
|
||||
|
||||
typedef int (* int_return_int_t) (int);
|
||||
|
||||
static int
|
||||
identity (int arg)
|
||||
{
|
||||
printf ("received %i\n", arg);
|
||||
return arg;
|
||||
}
|
||||
|
||||
static int_return_int_t
|
||||
generate_function_proxy (int_return_int_t func)
|
||||
{
|
||||
static const char failure_message[] = "numbers don't add up to zero\n";
|
||||
static char buffer[1024];
|
||||
|
||||
int_return_int_t result;
|
||||
int arg, arg_offset, argneg_offset;
|
||||
jit_insn *branch;
|
||||
|
||||
result = (int_return_int_t)(jit_set_ip (buffer).ptr);
|
||||
jit_prolog (1);
|
||||
arg = jit_arg_i ();
|
||||
jit_getarg_i (JIT_R1, arg);
|
||||
|
||||
/* Store the argument on the stack. */
|
||||
arg_offset = jit_allocai (sizeof (int));
|
||||
jit_stxi_i (arg_offset, JIT_FP, JIT_R1);
|
||||
|
||||
/* Store the negative of the argument on the stack. */
|
||||
argneg_offset = jit_allocai (sizeof (int));
|
||||
jit_negr_i (JIT_R2, JIT_R1);
|
||||
jit_stxi_i (argneg_offset, JIT_FP, JIT_R2);
|
||||
|
||||
/* Invoke FUNC. */
|
||||
jit_prepare (1);
|
||||
jit_pusharg_i (JIT_R1);
|
||||
(void)jit_finish (func);
|
||||
|
||||
/* Ignore the result. */
|
||||
|
||||
/* Restore the negative and the argument from the stack. */
|
||||
jit_ldxi_i (JIT_R2, JIT_FP, argneg_offset);
|
||||
jit_ldxi_i (JIT_V1, JIT_FP, arg_offset);
|
||||
|
||||
/* Make sure they still add to zero. */
|
||||
jit_addr_i (JIT_R0, JIT_V1, JIT_R2);
|
||||
branch = jit_bnei_i (jit_forward (), JIT_R0, 0);
|
||||
|
||||
/* Return it. */
|
||||
jit_movr_i (JIT_RET, JIT_V1);
|
||||
jit_ret ();
|
||||
|
||||
/* Display a failure message. */
|
||||
jit_patch (branch);
|
||||
(void)jit_movi_p (JIT_R2, failure_message);
|
||||
jit_prepare (1);
|
||||
jit_pusharg_p (JIT_R2);
|
||||
(void)jit_finish (printf);
|
||||
|
||||
/* Leave. */
|
||||
jit_movr_i (JIT_RET, JIT_V1);
|
||||
jit_ret ();
|
||||
|
||||
jit_flush_code (buffer, jit_get_ip ().ptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int_return_int_t identity_func;
|
||||
|
||||
identity_func = generate_function_proxy (identity);
|
||||
if (identity_func (7777) != 7777)
|
||||
{
|
||||
printf ("failed: got %i instead of %i\n",
|
||||
identity_func (7777), 7777);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
printf ("succeeded\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
coding: latin-1
|
||||
End:
|
||||
*/
|
88
tests/bp.c
88
tests/bp.c
|
@ -1,88 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Simple example of recursion and forward references
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000, 2004 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini and Laurent Michel.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
pifi nfibs = (pifi) (jit_set_ip(codeBuffer).iptr);
|
||||
int in; /* offset of the argument */
|
||||
jit_insn *ref; /* to patch the forward reference */
|
||||
jit_insn *mref; /* ref of move to backpatch */
|
||||
jit_insn *tp; /* location to patch */
|
||||
|
||||
jit_prolog (1);
|
||||
in = jit_arg_ui ();
|
||||
jit_getarg_ui(JIT_V0, in); /* V0 = n */
|
||||
mref= jit_movi_p(JIT_V2,jit_forward ()); /* Generate a dumb movi */
|
||||
jit_jmpr(JIT_V2);
|
||||
/* generate some dump filler that will never be executed!*/
|
||||
jit_addi_ui(JIT_V0,JIT_V0,1);
|
||||
jit_addi_ui(JIT_V0,JIT_V0,1);
|
||||
jit_addi_ui(JIT_V0,JIT_V0,1);
|
||||
jit_addi_ui(JIT_V0,JIT_V0,1);
|
||||
tp = jit_get_label ();
|
||||
ref = jit_blti_ui (jit_forward(), JIT_V0, 2);
|
||||
jit_subi_ui (JIT_V1, JIT_V0, 1); /* V1 = n-1 */
|
||||
jit_subi_ui (JIT_V2, JIT_V0, 2); /* V2 = n-2 */
|
||||
jit_prepare (1);
|
||||
jit_pusharg_ui(JIT_V1);
|
||||
jit_finish(nfibs);
|
||||
jit_retval(JIT_V1); /* V1 = nfibs(n-1) */
|
||||
jit_prepare(1);
|
||||
jit_pusharg_ui(JIT_V2);
|
||||
jit_finish(nfibs);
|
||||
jit_retval(JIT_V2); /* V2 = nfibs(n-2) */
|
||||
jit_addi_ui(JIT_V1, JIT_V1, 1);
|
||||
jit_addr_ui(JIT_RET, JIT_V1, JIT_V2); /* RET = V1 + V2 + 1 */
|
||||
jit_ret();
|
||||
|
||||
jit_patch(ref); /* patch jump */
|
||||
jit_movi_i(JIT_RET, 1); /* RET = 1 */
|
||||
jit_ret();
|
||||
|
||||
jit_patch_movi(mref,tp); /* Ok. Do the back-patching */
|
||||
|
||||
/* call the generated code, passing 32 as an argument */
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
printf("nfibs(%d) = %d\n", 32, nfibs(32));
|
||||
return 0;
|
||||
}
|
84
tests/divi.c
84
tests/divi.c
|
@ -1,84 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test jit_divi_i
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtès. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lightning.h"
|
||||
|
||||
typedef int (* divider_t) (int);
|
||||
|
||||
static divider_t
|
||||
generate_divider (int operand, unsigned int *size)
|
||||
{
|
||||
static char buffer[1024];
|
||||
divider_t result;
|
||||
int arg;
|
||||
|
||||
result = (divider_t)(jit_set_ip (buffer).iptr);
|
||||
jit_leaf (1);
|
||||
arg = jit_arg_i ();
|
||||
jit_getarg_i (JIT_R1, arg);
|
||||
|
||||
jit_divi_i (JIT_R2, JIT_R1, operand);
|
||||
jit_movr_i (JIT_RET, JIT_R2);
|
||||
|
||||
jit_ret ();
|
||||
jit_flush_code (buffer, jit_get_ip ().ptr);
|
||||
|
||||
*size = (char *)jit_get_ip ().ptr - buffer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
test_divider (int divisor, const int *operands, unsigned operand_count)
|
||||
{
|
||||
int failed = 0;
|
||||
unsigned int op, size;
|
||||
divider_t div = generate_divider (divisor, &size);
|
||||
|
||||
for (op = 0; op < operand_count; op++)
|
||||
{
|
||||
int result, expected;
|
||||
|
||||
result = div (operands[op]);
|
||||
expected = operands[op] / divisor;
|
||||
printf ("%i/%i = %i (expected %i)\n", operands[op], divisor,
|
||||
result, expected);
|
||||
|
||||
if (result != expected)
|
||||
failed = 1;
|
||||
}
|
||||
|
||||
return (!failed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
static const int small_ops[] = { 40, 64, 80 };
|
||||
static const int large_ops[] = { 98304, 65536, 163840 };
|
||||
|
||||
/* Test a small immediate operand. */
|
||||
if (!test_divider (8, small_ops, sizeof (small_ops) / sizeof (int)))
|
||||
return 1;
|
||||
|
||||
/* Test a large immediate operand (requires more instructions on RISC
|
||||
processors). */
|
||||
if (!test_divider (32768, large_ops, sizeof (large_ops) / sizeof (int)))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
76
tests/fib.c
76
tests/fib.c
|
@ -1,76 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample example of recursion and forward references
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
pifi nfibs = (pifi) (jit_set_ip(codeBuffer).iptr);
|
||||
int in; /* offset of the argument */
|
||||
jit_insn *ref; /* to patch the forward reference */
|
||||
|
||||
jit_prolog (1);
|
||||
in = jit_arg_ui ();
|
||||
jit_getarg_ui(JIT_V0, in); /* V0 = n */
|
||||
ref = jit_blti_ui (jit_forward(), JIT_V0, 2);
|
||||
jit_subi_ui (JIT_V1, JIT_V0, 1); /* V1 = n-1 */
|
||||
jit_subi_ui (JIT_V2, JIT_V0, 2); /* V2 = n-2 */
|
||||
jit_prepare_i(1);
|
||||
jit_pusharg_ui(JIT_V1);
|
||||
jit_finish(nfibs);
|
||||
jit_retval_i (JIT_V1); /* V1 = nfibs(n-1) */
|
||||
jit_prepare_i(1);
|
||||
jit_pusharg_ui(JIT_V2);
|
||||
jit_finish(nfibs);
|
||||
jit_retval_i (JIT_V2); /* V2 = nfibs(n-2) */
|
||||
jit_addi_ui(JIT_V1, JIT_V1, 1);
|
||||
jit_addr_ui(JIT_RET, JIT_V1, JIT_V2); /* RET = V1 + V2 + 1 */
|
||||
jit_ret();
|
||||
|
||||
jit_patch(ref); /* patch jump */
|
||||
jit_movi_i(JIT_RET, 1); /* RET = 1 */
|
||||
jit_ret();
|
||||
|
||||
/* call the generated code, passing 32 as an argument */
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
printf("nfibs(%d) = %d\n", 32, nfibs(32));
|
||||
return 0;
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample example of branches
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
pifi nfibs = (pifi) (jit_set_ip(codeBuffer).iptr);
|
||||
int in; /* offset of the argument */
|
||||
jit_insn *ref; /* to patch the forward reference */
|
||||
jit_insn *loop; /* start of the loop */
|
||||
|
||||
jit_prolog (1);
|
||||
in = jit_arg_ui ();
|
||||
jit_getarg_ui(JIT_R2, in); /* V0 = n */
|
||||
jit_delay(
|
||||
jit_movi_ui (JIT_R1, 1),
|
||||
ref = jit_blti_ui (jit_forward(), JIT_R2, 2));
|
||||
jit_subi_ui (JIT_R2, JIT_R2, 1);
|
||||
jit_movi_ui (JIT_R0, 1);
|
||||
|
||||
loop= jit_get_label();
|
||||
jit_subi_ui (JIT_R2, JIT_R2, 1); /* decr. counter */
|
||||
jit_addr_ui (JIT_V0, JIT_R0, JIT_R1); /* V0 = R0 + R1 */
|
||||
jit_movr_ui (JIT_R0, JIT_R1); /* R0 = R1 */
|
||||
jit_delay(
|
||||
jit_addi_ui (JIT_R1, JIT_V0, 1), /* R1 = V0 + 1 */
|
||||
jit_bnei_ui (loop, JIT_R2, 0)); /* if (R2) goto loop; */
|
||||
|
||||
jit_patch(ref); /* patch forward jump */
|
||||
jit_movr_ui (JIT_RET, JIT_R1); /* RET = R1 */
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
/* call the generated code, passing 36 as an argument */
|
||||
printf("nfibs(%d) = %d\n", 36, nfibs(36));
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
nfibs(36) = 48315633
|
|
@ -1,74 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample example of branches
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
pifi nfibs = (pifi) (jit_set_ip(codeBuffer).iptr);
|
||||
int in; /* offset of the argument */
|
||||
jit_insn *ref; /* to patch the forward reference */
|
||||
jit_insn *loop; /* start of the loop */
|
||||
|
||||
jit_prolog (1);
|
||||
in = jit_arg_ui ();
|
||||
jit_getarg_ui(JIT_R2, in); /* V0 = n */
|
||||
jit_movi_ui (JIT_R1, 1);
|
||||
ref = jit_blti_ui (jit_forward(), JIT_R2, 2);
|
||||
jit_subi_ui (JIT_R2, JIT_R2, 1);
|
||||
jit_movi_ui (JIT_R0, 1);
|
||||
|
||||
loop= jit_get_label();
|
||||
jit_subi_ui (JIT_R2, JIT_R2, 1); /* we'll calculate one more */
|
||||
jit_addr_ui (JIT_V0, JIT_R0, JIT_R1); /* V0 = R0 + R1 */
|
||||
jit_movr_ui (JIT_R0, JIT_R1); /* R0 = R1 */
|
||||
jit_addi_ui (JIT_R1, JIT_V0, 1); /* R1 = V0 + 1 */
|
||||
jit_bnei_ui (loop, JIT_R2, 0); /* if (R2) goto loop; */
|
||||
|
||||
jit_patch(ref); /* patch forward jump */
|
||||
jit_movr_ui (JIT_RET, JIT_R1); /* RET = R1 */
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
/* call the generated code, passing 36 as an argument */
|
||||
printf("nfibs(%d) = %d\n", 36, nfibs(36));
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
nfibs(36) = 48315633
|
161
tests/funcfp.c
161
tests/funcfp.c
|
@ -1,161 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Floating-point function invocation using GNU lightning
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000, 2004 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[300];
|
||||
|
||||
typedef int (*intFunc) (int, int);
|
||||
typedef double (*dblFunc) (double, double);
|
||||
typedef float (*floatFunc) (float, float);
|
||||
|
||||
|
||||
/* Generate a function that computes and returns the sum of
|
||||
its two double arguments (return an int)
|
||||
i.e., double foo(double x,double y) { return x + y;} */
|
||||
dblFunc
|
||||
makeDblFunc ()
|
||||
{
|
||||
dblFunc retVal;
|
||||
int dbl1, dbl2;
|
||||
retVal = (dblFunc) jit_get_ip ().iptr;
|
||||
jit_prolog (2);
|
||||
dbl1 = jit_arg_d ();
|
||||
dbl2 = jit_arg_d ();
|
||||
jit_getarg_d (JIT_FPR0, dbl1);
|
||||
jit_getarg_d (JIT_FPR1, dbl2);
|
||||
jit_addr_d (JIT_FPR0, JIT_FPR0, JIT_FPR1);
|
||||
jit_movr_d (JIT_FPRET, JIT_FPR0);
|
||||
jit_ret ();
|
||||
jit_flush_code ((char *) retVal, jit_get_ip ().ptr);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
/* Generate a function that computes and returns the sum of
|
||||
its two double arguments (return an int)
|
||||
i.e., double foo(double x,double y) { return x + y;} */
|
||||
floatFunc
|
||||
makeFloatFunc ()
|
||||
{
|
||||
floatFunc retVal;
|
||||
int dbl1, dbl2;
|
||||
retVal = (floatFunc) jit_get_ip ().iptr;
|
||||
jit_prolog (2);
|
||||
dbl1 = jit_arg_f ();
|
||||
dbl2 = jit_arg_f ();
|
||||
jit_getarg_f (JIT_FPR0, dbl1);
|
||||
jit_getarg_f (JIT_FPR1, dbl2);
|
||||
jit_addr_f (JIT_FPR0, JIT_FPR0, JIT_FPR1);
|
||||
jit_movr_f (JIT_FPRET, JIT_FPR0);
|
||||
jit_ret ();
|
||||
jit_flush_code ((char *) retVal, jit_get_ip ().ptr);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
dblFunc
|
||||
makeCallFunc (dblFunc theFunc)
|
||||
{
|
||||
dblFunc retVal;
|
||||
int dbl1, dbl2;
|
||||
retVal = (dblFunc) jit_get_ip ().iptr;
|
||||
jit_prolog (2);
|
||||
dbl1 = jit_arg_d ();
|
||||
dbl2 = jit_arg_d ();
|
||||
|
||||
jit_prepare_d (2);
|
||||
jit_getarg_d (JIT_FPR0, dbl1);
|
||||
jit_getarg_d (JIT_FPR1, dbl2);
|
||||
jit_mulr_d (JIT_FPR1, JIT_FPR1, JIT_FPR0);
|
||||
jit_pusharg_d (JIT_FPR1);
|
||||
jit_pusharg_d (JIT_FPR0);
|
||||
jit_finish ((void *) theFunc);
|
||||
jit_retval_d (JIT_FPRET);
|
||||
jit_ret ();
|
||||
jit_flush_code ((char *) retVal, jit_get_ip ().ptr);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
floatFunc
|
||||
makeCallFloatFunc (floatFunc theFunc)
|
||||
{
|
||||
floatFunc retVal;
|
||||
int dbl1, dbl2;
|
||||
retVal = (floatFunc) jit_get_ip ().iptr;
|
||||
jit_prolog (2);
|
||||
dbl1 = jit_arg_f ();
|
||||
dbl2 = jit_arg_f ();
|
||||
|
||||
jit_prepare_f (2);
|
||||
jit_getarg_f (JIT_FPR0, dbl1);
|
||||
jit_getarg_f (JIT_FPR1, dbl2);
|
||||
jit_mulr_f (JIT_FPR1, JIT_FPR1, JIT_FPR0);
|
||||
jit_pusharg_f (JIT_FPR1);
|
||||
jit_pusharg_f (JIT_FPR0);
|
||||
jit_finish ((void *) theFunc);
|
||||
jit_retval_f (JIT_FPRET);
|
||||
jit_ret ();
|
||||
jit_flush_code ((char *) retVal, jit_get_ip ().ptr);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
dblFunc myFunc2, callIt1;
|
||||
floatFunc myFunc3, callIt2;
|
||||
double y;
|
||||
float a, b, z;
|
||||
|
||||
jit_set_ip (codeBuffer);
|
||||
myFunc2 = makeDblFunc ();
|
||||
myFunc3 = makeFloatFunc ();
|
||||
callIt1 = makeCallFunc (myFunc2);
|
||||
callIt2 = makeCallFloatFunc (myFunc3);
|
||||
y = callIt1 (10.5, 15.3);
|
||||
a = 1.5;
|
||||
b = 10.5;
|
||||
z = callIt2 (a, b);
|
||||
printf ("result is %.5g\t %.5g\n", y, z);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
result is 171.15 17.25
|
58
tests/incr.c
58
tests/incr.c
|
@ -1,58 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample call for using arguments in GNU lightning
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static char codeBuffer[1024];
|
||||
|
||||
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
pifi myFunction= (pifi) (jit_set_ip(codeBuffer).iptr);
|
||||
int ofs; /* offset of the argument */
|
||||
|
||||
jit_leaf(1);
|
||||
ofs = jit_arg_i();
|
||||
jit_getarg_i(JIT_R0, ofs);
|
||||
jit_addi_i(JIT_RET, JIT_R0, 1);
|
||||
jit_ret();
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
/* call the generated code, passing its size as argument */
|
||||
printf("%d + 1 = %d\n", 5, myFunction(5));
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
5 + 1 = 6
|
1016
tests/ldst.c
1016
tests/ldst.c
File diff suppressed because it is too large
Load diff
71
tests/ldxi.c
71
tests/ldxi.c
|
@ -1,71 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test jit_ldxi_i
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtes. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lightning.h"
|
||||
|
||||
typedef char (* loader_t) (int);
|
||||
|
||||
/* Check `ldxi' with a big operand (OPERAND is assumed to be ``big'', e.g.,
|
||||
more than one octet-long on PowerPC). */
|
||||
static loader_t
|
||||
generate_ldxi_big_operand (const void *operand)
|
||||
{
|
||||
static char buffer[1024];
|
||||
loader_t result;
|
||||
int arg;
|
||||
|
||||
/* printf ("si?=%i ui?=%i\n", _siP (16, operand), _uiP (16, operand)); */
|
||||
|
||||
result = (loader_t)(jit_set_ip (buffer).iptr);
|
||||
jit_leaf (1);
|
||||
arg = jit_arg_i ();
|
||||
jit_getarg_p (JIT_R1, arg);
|
||||
|
||||
jit_ldxi_c (JIT_R0, JIT_R1, operand);
|
||||
jit_movr_i (JIT_RET, JIT_R0);
|
||||
|
||||
jit_ret ();
|
||||
jit_flush_code (buffer, jit_get_ip ().ptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
static const char the_array[] = "GNU Lightning";
|
||||
char the_on_stack_array[] = "GNU Lightning";
|
||||
unsigned i;
|
||||
loader_t array_loader;
|
||||
const char *large_pointer;
|
||||
|
||||
if (the_array > the_on_stack_array)
|
||||
large_pointer = the_array;
|
||||
else
|
||||
large_pointer = the_on_stack_array;
|
||||
|
||||
array_loader = generate_ldxi_big_operand (large_pointer);
|
||||
|
||||
for (i = 0; i < sizeof (the_array) - 1; i++)
|
||||
{
|
||||
printf ("array[%i] = %c, array_loader (%i) = %c\n",
|
||||
i, large_pointer[i], i, array_loader (i));
|
||||
if (large_pointer[i] != array_loader (i))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
array[0] = G, array_loader (0) = G
|
||||
array[1] = N, array_loader (1) = N
|
||||
array[2] = U, array_loader (2) = U
|
||||
array[3] = , array_loader (3) =
|
||||
array[4] = L, array_loader (4) = L
|
||||
array[5] = i, array_loader (5) = i
|
||||
array[6] = g, array_loader (6) = g
|
||||
array[7] = h, array_loader (7) = h
|
||||
array[8] = t, array_loader (8) = t
|
||||
array[9] = n, array_loader (9) = n
|
||||
array[10] = i, array_loader (10) = i
|
||||
array[11] = n, array_loader (11) = n
|
||||
array[12] = g, array_loader (12) = g
|
52
tests/modi.c
52
tests/modi.c
|
@ -1,52 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test jit_modi_i
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtes. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lightning.h"
|
||||
|
||||
typedef int (* mod_t) (int);
|
||||
|
||||
mod_t
|
||||
generate_modi (int operand)
|
||||
{
|
||||
static char buffer[1024];
|
||||
mod_t result;
|
||||
int arg;
|
||||
|
||||
result = (mod_t)(jit_set_ip (buffer).iptr);
|
||||
jit_leaf (1);
|
||||
arg = jit_arg_i ();
|
||||
jit_getarg_i (JIT_R1, arg);
|
||||
|
||||
jit_modi_i (JIT_R2, JIT_R1, operand);
|
||||
jit_movr_i (JIT_RET, JIT_R2);
|
||||
|
||||
jit_ret ();
|
||||
jit_flush_code (buffer, jit_get_ip ().ptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
mod_t mod_eight = generate_modi (8);
|
||||
|
||||
printf ("mod_eight (%i) = %i (vs. %i)\n",
|
||||
20420, mod_eight (20420), (20420 % 8));
|
||||
printf ("mod_eight (%i) = %i (vs. %i)\n",
|
||||
216096, mod_eight (216096), (216096 % 8));
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
mod_eight (20420) = 4 (vs. 4)
|
||||
mod_eight (216096) = 0 (vs. 0)
|
63
tests/movi.c
63
tests/movi.c
|
@ -1,63 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test jit_movi_p
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtès. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lightning.h"
|
||||
|
||||
typedef void * (* mover_t) (void);
|
||||
|
||||
static mover_t
|
||||
generate_movi (const void *operand)
|
||||
{
|
||||
static char buffer[1024];
|
||||
mover_t result;
|
||||
|
||||
/* printf ("si?=%i ui?=%i\n", _siP (16, operand), _uiP (16, operand)); */
|
||||
|
||||
result = (mover_t)(jit_set_ip (buffer).iptr);
|
||||
jit_leaf (1);
|
||||
|
||||
jit_movi_p (JIT_R0, operand);
|
||||
jit_movr_p (JIT_RET, JIT_R0);
|
||||
|
||||
jit_ret ();
|
||||
jit_flush_code (buffer, jit_get_ip ().ptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
static const char the_array[] = "GNU Lightning";
|
||||
mover_t get_array;
|
||||
const void *large_pointer;
|
||||
|
||||
if (the_array > (char *)&get_array)
|
||||
large_pointer = the_array;
|
||||
else
|
||||
large_pointer = &get_array;
|
||||
|
||||
/* On RISC machines, moving a large immediate may require several
|
||||
instructions (e.g., `sethi' followed by `ori' on SPARC). */
|
||||
get_array = generate_movi (large_pointer);
|
||||
|
||||
if (get_array () == large_pointer)
|
||||
printf ("`jit_movi_p' succeeded\n");
|
||||
else
|
||||
printf ("`jit_movi_p' failed\n");
|
||||
|
||||
return (get_array () != large_pointer);
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
`jit_movi_p' succeeded
|
|
@ -1,72 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample call to printf using GNU lightning
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static char codeBuffer[1024];
|
||||
|
||||
typedef void (*pvfi)(int); /* Pointer to Void Function of Int */
|
||||
|
||||
static void display_message (char *msg, int value)
|
||||
{
|
||||
printf (msg, value);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pvfi myFunction; /* ptr to generated code */
|
||||
char *start, *end; /* a couple of labels */
|
||||
int ofs; /* to get the argument */
|
||||
|
||||
myFunction = (pvfi) (jit_set_ip(codeBuffer).vptr);
|
||||
start = jit_get_ip().ptr;
|
||||
jit_prolog(1);
|
||||
ofs = jit_arg_i();
|
||||
jit_movi_p(JIT_R0, "looks like %d bytes sufficed\n");
|
||||
jit_getarg_i(JIT_R1, ofs);
|
||||
jit_prepare_i(2);
|
||||
jit_pusharg_i(JIT_R1); /* push in reverse order */
|
||||
jit_pusharg_p(JIT_R0);
|
||||
jit_finish(display_message);
|
||||
jit_ret();
|
||||
end = jit_get_ip().ptr;
|
||||
|
||||
jit_flush_code(codeBuffer, end);
|
||||
|
||||
/* call the generated code, passing its size as argument */
|
||||
myFunction(sizeof(codeBuffer));
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
looks like 1024 bytes sufficed
|
2444
tests/printf2.c
2444
tests/printf2.c
File diff suppressed because it is too large
Load diff
2376
tests/printf2.ok
2376
tests/printf2.ok
File diff suppressed because it is too large
Load diff
72
tests/ret.c
72
tests/ret.c
|
@ -1,72 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test `JIT_RET'
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtès. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lightning.h"
|
||||
|
||||
typedef int (* int_return_int_t) (int);
|
||||
|
||||
static int
|
||||
identity (int arg)
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
|
||||
static int_return_int_t
|
||||
generate_function_proxy (int_return_int_t func)
|
||||
{
|
||||
static char buffer[1024];
|
||||
int_return_int_t result;
|
||||
int arg;
|
||||
|
||||
result = (int_return_int_t)(jit_set_ip (buffer).ptr);
|
||||
jit_prolog (1);
|
||||
arg = jit_arg_i ();
|
||||
jit_getarg_i (JIT_R1, arg);
|
||||
|
||||
/* Reset `JIT_RET'. */
|
||||
jit_movi_i (JIT_RET, -1);
|
||||
|
||||
/* Invoke a FUNC. */
|
||||
jit_prepare (1);
|
||||
jit_pusharg_i (JIT_R1);
|
||||
(void)jit_finish (func);
|
||||
|
||||
/* Copy the result of FUNC from `JIT_RET' into our own result register. */
|
||||
jit_retval_i (JIT_RET);
|
||||
|
||||
jit_ret ();
|
||||
jit_flush_code (buffer, jit_get_ip ().ptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int_return_int_t identity_proxy;
|
||||
|
||||
identity_proxy = generate_function_proxy (identity);
|
||||
if (identity_proxy (7777) != 7777)
|
||||
{
|
||||
printf ("failed: got %i instead of %i\n",
|
||||
identity_proxy (7777), 7777);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
printf ("succeeded\n");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
succeeded
|
461
tests/rpn.c
461
tests/rpn.c
|
@ -1,461 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample RPN calculator using GNU lightning
|
||||
* Binary operators: + - * / % & | ^ < <= > >= = != << >> >>>
|
||||
* Unary operators: _ (unary minus) and ~ (unary NOT)
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000, 2004 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
typedef int (*pifi) (int); /* Pointer to Int Function of Int */
|
||||
|
||||
|
||||
enum stack_kind { IMM, EXPR, ARG };
|
||||
enum operator { LE, GE, NE, LSH, RSHU, RSH };
|
||||
|
||||
struct stack_element
|
||||
{
|
||||
enum stack_kind kind;
|
||||
int imm;
|
||||
};
|
||||
|
||||
/* Return a new operator TOK2 such that A TOK B = B TOK2 A,
|
||||
or 0 if there is none. */
|
||||
int
|
||||
swap_op (int tok)
|
||||
{
|
||||
switch (tok)
|
||||
{
|
||||
case '<':
|
||||
case '>':
|
||||
/* Swap < and >. */
|
||||
return '<' ^ '>' ^ tok;
|
||||
|
||||
case LE:
|
||||
case GE:
|
||||
/* Swap <= and >=. */
|
||||
return LE ^ GE ^ tok;
|
||||
|
||||
case '+':
|
||||
case '*':
|
||||
case '&':
|
||||
case '|':
|
||||
case '^':
|
||||
case '=':
|
||||
case NE:
|
||||
/* These are commutative. */
|
||||
return tok;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform constant folding on the two operands X and Y,
|
||||
passing them through the operator TOK. */
|
||||
int
|
||||
fold (int x, int y, int tok)
|
||||
{
|
||||
switch (tok)
|
||||
{
|
||||
case '+': return x + y;
|
||||
case '-': return x - y;
|
||||
case '*': return x * y;
|
||||
case '/': return x / y;
|
||||
case '%': return x % y;
|
||||
case '=': return x == y;
|
||||
case '<': return x < y;
|
||||
case '>': return x > y;
|
||||
case '&': return x & y;
|
||||
case '|': return x | y;
|
||||
case '^': return x ^ y;
|
||||
case LE: return x <= y;
|
||||
case GE: return x >= y;
|
||||
case NE: return x != y;
|
||||
case LSH: return x << y;
|
||||
case RSH: return x >> y;
|
||||
case RSHU: return ((unsigned) x) >> y;
|
||||
default: abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Store in R0 the result of evaluating the operator TOK with
|
||||
a register operand SRC and an immediate operand IMM. */
|
||||
void
|
||||
gen_reg_imm (int src, int imm, int tok)
|
||||
{
|
||||
switch (tok)
|
||||
{
|
||||
case '+': jit_addi_i (JIT_R0, src, imm); break;
|
||||
case '-': jit_subi_i (JIT_R0, src, imm); break;
|
||||
case '*': jit_muli_i (JIT_R0, src, imm); break;
|
||||
case '/': jit_divi_i (JIT_R0, src, imm); break;
|
||||
case '%': jit_modi_i (JIT_R0, src, imm); break;
|
||||
case '&': jit_andi_i (JIT_R0, src, imm); break;
|
||||
case '|': jit_ori_i (JIT_R0, src, imm); break;
|
||||
case '^': jit_xori_i (JIT_R0, src, imm); break;
|
||||
case '=': jit_eqi_i (JIT_R0, src, imm); break;
|
||||
case '<': jit_lti_i (JIT_R0, src, imm); break;
|
||||
case '>': jit_gti_i (JIT_R0, src, imm); break;
|
||||
case LE: jit_lei_i (JIT_R0, src, imm); break;
|
||||
case GE: jit_gei_i (JIT_R0, src, imm); break;
|
||||
case NE: jit_nei_i (JIT_R0, src, imm); break;
|
||||
case LSH: jit_lshi_i (JIT_R0, src, imm); break;
|
||||
case RSH: jit_rshi_i (JIT_R0, src, imm); break;
|
||||
case RSHU: jit_rshi_ui (JIT_R0, src, imm); break;
|
||||
default: abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Store in R0 the result of evaluating the operator TOK with
|
||||
two register operands SRC1 and SRC2. */
|
||||
void
|
||||
gen_reg_reg (int src1, int src2, int tok)
|
||||
{
|
||||
switch (tok)
|
||||
{
|
||||
case '+': jit_addr_i (JIT_R0, src1, src2); break;
|
||||
case '-': jit_subr_i (JIT_R0, src1, src2); break;
|
||||
case '*': jit_mulr_i (JIT_R0, src1, src2); break;
|
||||
case '/': jit_divr_i (JIT_R0, src1, src2); break;
|
||||
case '%': jit_modr_i (JIT_R0, src1, src2); break;
|
||||
case '&': jit_andr_i (JIT_R0, src1, src2); break;
|
||||
case '|': jit_orr_i (JIT_R0, src1, src2); break;
|
||||
case '^': jit_xorr_i (JIT_R0, src1, src2); break;
|
||||
case '=': jit_eqr_i (JIT_R0, src1, src2); break;
|
||||
case '<': jit_ltr_i (JIT_R0, src1, src2); break;
|
||||
case '>': jit_gtr_i (JIT_R0, src1, src2); break;
|
||||
case LE: jit_ler_i (JIT_R0, src1, src2); break;
|
||||
case GE: jit_ger_i (JIT_R0, src1, src2); break;
|
||||
case NE: jit_ner_i (JIT_R0, src1, src2); break;
|
||||
case LSH: jit_lshr_i (JIT_R0, src1, src2); break;
|
||||
case RSH: jit_rshr_i (JIT_R0, src1, src2); break;
|
||||
case RSHU: jit_rshr_ui (JIT_R0, src1, src2); break;
|
||||
default: abort ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pushr (int reg, int *sp)
|
||||
{
|
||||
jit_stxi_i (*sp, JIT_FP, reg);
|
||||
*sp += sizeof (int);
|
||||
}
|
||||
|
||||
static void
|
||||
popr (int reg, int *sp)
|
||||
{
|
||||
*sp -= sizeof (int);
|
||||
jit_ldxi_i (reg, JIT_FP, *sp);
|
||||
}
|
||||
|
||||
/* This function does all of lexing, parsing, and picking a good
|
||||
order of evaluation... Needless to say, this is not the best
|
||||
possible design, but it avoids cluttering everything with globals. */
|
||||
pifi
|
||||
compile_rpn (char *expr)
|
||||
{
|
||||
struct stack_element stack[32];
|
||||
int sp = 0;
|
||||
int curr_tos = -1; /* stack element currently in R0 */
|
||||
int spill_base, spill_sp;
|
||||
|
||||
pifi fn;
|
||||
int ofs;
|
||||
fn = (pifi) (jit_get_ip ().iptr);
|
||||
jit_leaf (1);
|
||||
ofs = jit_arg_i ();
|
||||
|
||||
spill_sp = spill_base = jit_allocai (32 * sizeof (int));
|
||||
|
||||
while (*expr)
|
||||
{
|
||||
int with_imm;
|
||||
int imm;
|
||||
int tok;
|
||||
int src1, src2;
|
||||
|
||||
/* This is the lexer. */
|
||||
switch (*expr)
|
||||
{
|
||||
case ' ': case '\t':
|
||||
expr++;
|
||||
continue;
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
stack[sp].kind = IMM;
|
||||
stack[sp++].imm = strtol (expr, &expr, 0);
|
||||
continue;
|
||||
|
||||
case 'x':
|
||||
expr++;
|
||||
stack[sp++].kind = ARG;
|
||||
continue;
|
||||
|
||||
case '~':
|
||||
/* NOT. Implemented as a XOR with -1. */
|
||||
stack[sp].kind = IMM;
|
||||
stack[sp++].imm = ~0;
|
||||
tok = '^';
|
||||
break;
|
||||
|
||||
case '_':
|
||||
/* Unary minus. Transform to 0 - X and go on.
|
||||
Also used to enter negative constants (32_ = -32). */
|
||||
expr++;
|
||||
stack[sp] = stack[sp - 1];
|
||||
|
||||
/* Ensure CURR_TOS is correct. */
|
||||
if (curr_tos == sp - 1)
|
||||
curr_tos = sp;
|
||||
|
||||
stack[sp - 1].kind = IMM;
|
||||
stack[sp - 1].imm = 0;
|
||||
sp++;
|
||||
tok = '-';
|
||||
break;
|
||||
|
||||
case '+':
|
||||
case '-':
|
||||
case '*':
|
||||
case '/':
|
||||
case '%':
|
||||
case '&':
|
||||
case '|':
|
||||
case '^':
|
||||
case '=':
|
||||
tok = *expr++;
|
||||
break;
|
||||
|
||||
case '!':
|
||||
/* Get != */
|
||||
expr++;
|
||||
assert (*expr == '=');
|
||||
tok = NE;
|
||||
break;
|
||||
|
||||
case '<':
|
||||
/* Get <, <<, <= */
|
||||
if (expr[1] == '=')
|
||||
expr += 2, tok = LE;
|
||||
else if (expr[1] == '<')
|
||||
expr += 2, tok = LSH;
|
||||
else
|
||||
expr++, tok = '<';
|
||||
break;
|
||||
|
||||
case '>':
|
||||
/* Get >, >>, >>>, >= */
|
||||
if (expr[1] == '=')
|
||||
expr += 2, tok = GE;
|
||||
else if (expr[1] == '>' && expr[2] == '>')
|
||||
expr += 3, tok = RSHU;
|
||||
else if (expr[1] == '>')
|
||||
expr += 2, tok = RSH;
|
||||
else
|
||||
expr++, tok = '>';
|
||||
break;
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
assert (sp >= 2);
|
||||
|
||||
/* Constant folding. */
|
||||
if (stack[sp - 1].kind == IMM && stack[sp - 2].kind == IMM)
|
||||
{
|
||||
stack[sp - 2].imm =
|
||||
fold (stack[sp - 2].imm, stack[sp - 1].imm, tok);
|
||||
sp--;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If possible, ensure that the constant is the RHS, possibly
|
||||
by changing TOK (if it is a comparison). */
|
||||
if (stack[sp - 2].kind == IMM)
|
||||
{
|
||||
int swapped_operation = swap_op (tok);
|
||||
if (swapped_operation)
|
||||
{
|
||||
tok = swapped_operation;
|
||||
stack[sp - 2].kind = stack[sp - 1].kind;
|
||||
stack[sp - 1].kind = IMM;
|
||||
stack[sp - 1].imm = stack[sp - 2].imm;
|
||||
|
||||
/* Ensure CURR_TOS is correct. */
|
||||
if (curr_tos == sp - 1)
|
||||
curr_tos = sp - 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the second argument into a register, if not an immediate.
|
||||
Also decide which argument will be prepared into JIT_R0 and
|
||||
which will be prepared into JIT_V0. */
|
||||
with_imm = 0;
|
||||
src1 = JIT_R0;
|
||||
src2 = JIT_V0;
|
||||
switch (stack[sp - 1].kind)
|
||||
{
|
||||
case IMM:
|
||||
/* RHS is an immediate, use an immediate instruction. */
|
||||
with_imm = 1;
|
||||
imm = stack[sp - 1].imm;
|
||||
break;
|
||||
|
||||
case EXPR:
|
||||
/* RHS is an expression, check if it is already in JIT_R0. */
|
||||
if (curr_tos == sp - 1)
|
||||
{
|
||||
/* Invert the two sources. */
|
||||
src1 = JIT_V0;
|
||||
src2 = JIT_R0;
|
||||
}
|
||||
else
|
||||
popr (JIT_V0, &spill_sp);
|
||||
|
||||
curr_tos = -1;
|
||||
break;
|
||||
|
||||
case ARG:
|
||||
jit_getarg_i (JIT_V0, ofs);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get the first argument into a register indicated by SRC1. */
|
||||
switch (stack[sp - 2].kind)
|
||||
{
|
||||
case IMM:
|
||||
/* LHS is an immediate, check if we must spill the top of stack. */
|
||||
if (curr_tos != -1)
|
||||
{
|
||||
pushr (JIT_R0, &spill_sp);
|
||||
curr_tos = -1;
|
||||
}
|
||||
|
||||
jit_movi_i (src1, stack[sp - 2].imm);
|
||||
break;
|
||||
|
||||
case EXPR:
|
||||
/* LHS is an expression, check if it is already in JIT_R0. */
|
||||
if (curr_tos != sp - 2)
|
||||
{
|
||||
popr (src1, &spill_sp);
|
||||
curr_tos = -1;
|
||||
}
|
||||
else
|
||||
assert (src1 == JIT_R0);
|
||||
break;
|
||||
|
||||
case ARG:
|
||||
if (curr_tos != -1)
|
||||
{
|
||||
pushr (JIT_R0, &spill_sp);
|
||||
curr_tos = -1;
|
||||
}
|
||||
|
||||
jit_getarg_i (src1, ofs);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set up the new stack entry, which is cached in R0. */
|
||||
sp -= 2;
|
||||
curr_tos = sp;
|
||||
stack[sp++].kind = EXPR;
|
||||
|
||||
/* Perform the computation. */
|
||||
if (with_imm)
|
||||
gen_reg_imm (src1, imm, tok);
|
||||
else
|
||||
gen_reg_reg (src1, src2, tok);
|
||||
}
|
||||
|
||||
assert (sp == 1);
|
||||
switch (stack[0].kind)
|
||||
{
|
||||
case IMM:
|
||||
jit_movi_i (JIT_RET, stack[0].imm);
|
||||
break;
|
||||
|
||||
case EXPR:
|
||||
assert (curr_tos == 0);
|
||||
jit_movr_i (JIT_RET, JIT_R0);
|
||||
break;
|
||||
|
||||
case ARG:
|
||||
jit_getarg_i (JIT_V0, ofs);
|
||||
break;
|
||||
}
|
||||
|
||||
jit_ret ();
|
||||
jit_flush_code ((char *) fn, jit_get_ip ().ptr);
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
pifi c2f, f2c;
|
||||
int i;
|
||||
|
||||
jit_set_ip (codeBuffer);
|
||||
c2f = compile_rpn ("32 x 9 * 5 / +");
|
||||
f2c = compile_rpn ("5 x 32_ + * 9 /");
|
||||
|
||||
printf ("\nC:");
|
||||
for (i = 0; i <= 100; i += 10)
|
||||
printf ("%3d ", i);
|
||||
printf ("\nF:");
|
||||
for (i = 0; i <= 100; i += 10)
|
||||
printf ("%3d ", c2f (i));
|
||||
printf ("\n");
|
||||
|
||||
printf ("\nF:");
|
||||
for (i = 32; i <= 212; i += 10)
|
||||
printf ("%3d ", i);
|
||||
printf ("\nC:");
|
||||
for (i = 32; i <= 212; i += 10)
|
||||
printf ("%3d ", f2c (i));
|
||||
printf ("\n");
|
||||
return 0;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
C: 0 10 20 30 40 50 60 70 80 90 100
|
||||
F: 32 50 68 86 104 122 140 158 176 194 212
|
||||
|
||||
F: 32 42 52 62 72 82 92 102 112 122 132 142 152 162 172 182 192 202 212
|
||||
C: 0 5 11 16 22 27 33 38 44 50 55 61 66 72 77 83 88 94 100
|
133
tests/rpnfp.c
133
tests/rpnfp.c
|
@ -1,133 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample RPN calculator using GNU lightning and floating-point
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000, 2004 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static jit_insn codeBuffer[1024];
|
||||
|
||||
typedef double (*pdfd) (double); /* Pointer to Double Function of Double */
|
||||
|
||||
static int regs[6] = { JIT_FPR0, JIT_FPR1, JIT_FPR2, JIT_FPR3, JIT_FPR4, JIT_FPR5 };
|
||||
|
||||
pdfd
|
||||
compile_rpn (char *expr)
|
||||
{
|
||||
pdfd fn;
|
||||
int ofs, sp = 1;
|
||||
|
||||
fn = (pdfd) (jit_get_ip ().dptr);
|
||||
jit_leaf (1);
|
||||
ofs = jit_arg_d ();
|
||||
jit_getarg_d (regs[0], ofs);
|
||||
|
||||
while (*expr)
|
||||
{
|
||||
char buf[32];
|
||||
int n;
|
||||
|
||||
/* This scanner is much less advanced than the one in rpn.c. */
|
||||
if (sscanf (expr, "%[0-9]%n", buf, &n))
|
||||
{
|
||||
double d = strtod (buf, NULL);
|
||||
expr += n - 1;
|
||||
jit_movi_d (regs[sp], d);
|
||||
sp++;
|
||||
}
|
||||
else if (*expr == '+')
|
||||
{
|
||||
jit_addr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]);
|
||||
sp--;
|
||||
}
|
||||
else if (*expr == '-')
|
||||
{
|
||||
jit_subr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]);
|
||||
sp--;
|
||||
}
|
||||
else if (*expr == '*')
|
||||
{
|
||||
jit_mulr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]);
|
||||
sp--;
|
||||
}
|
||||
else if (*expr == '/')
|
||||
{
|
||||
jit_divr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]);
|
||||
sp--;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "cannot compile: %s\n", expr);
|
||||
abort ();
|
||||
}
|
||||
++expr;
|
||||
}
|
||||
jit_movr_d (JIT_FPRET, regs[0]);
|
||||
jit_ret ();
|
||||
|
||||
jit_flush_code ((char *) fn, jit_get_ip ().ptr);
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
pdfd c2f, f2c;
|
||||
double i;
|
||||
|
||||
jit_set_ip (codeBuffer);
|
||||
c2f = compile_rpn ("9*5/32+");
|
||||
f2c = compile_rpn ("32-5*9/");
|
||||
|
||||
printf ("\nC:");
|
||||
for (i = 0; i <= 100; i += 10)
|
||||
printf ("%6.1f", i);
|
||||
printf ("\nF:");
|
||||
for (i = 0; i <= 100; i += 10)
|
||||
printf ("%6.1f", c2f (i));
|
||||
printf ("\n");
|
||||
|
||||
printf ("\nF:");
|
||||
for (i = 32; i <= 212; i += 10)
|
||||
printf ("%6.1f", i);
|
||||
printf ("\nC:");
|
||||
for (i = 32; i <= 212; i += 10)
|
||||
printf ("%6.1f", f2c (i));
|
||||
printf ("\n");
|
||||
return 0;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
C: 0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0
|
||||
F: 32.0 50.0 68.0 86.0 104.0 122.0 140.0 158.0 176.0 194.0 212.0
|
||||
|
||||
F: 32.0 42.0 52.0 62.0 72.0 82.0 92.0 102.0 112.0 122.0 132.0 142.0 152.0 162.0 172.0 182.0 192.0 202.0 212.0
|
||||
C: 0.0 5.6 11.1 16.7 22.2 27.8 33.3 38.9 44.4 50.0 55.6 61.1 66.7 72.2 77.8 83.3 88.9 94.4 100.0
|
62
tests/sete.c
62
tests/sete.c
|
@ -1,62 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Sample call for using arguments in GNU lightning
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
static char codeBuffer[1024];
|
||||
|
||||
typedef int (*pifii)(int, int); /* Pointer to Int Function of Int, Int */
|
||||
|
||||
int main()
|
||||
{
|
||||
pifii myFunction= (pifii) (jit_set_ip(codeBuffer).iptr);
|
||||
int arg; /* offset of the argument */
|
||||
|
||||
jit_leaf(2);
|
||||
arg = jit_arg_i();
|
||||
jit_getarg_i(JIT_R0, arg);
|
||||
arg = jit_arg_i();
|
||||
jit_getarg_i(JIT_R1, arg);
|
||||
jit_eqr_i(JIT_V0, JIT_R0, JIT_R1);
|
||||
jit_movr_i(JIT_RET, JIT_V0);
|
||||
jit_ret();
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
|
||||
/* call the generated code, passing its size as argument */
|
||||
printf("%d == %d? %s\n", 5, 4, myFunction(5, 4) ? "yes" : "no");
|
||||
printf("%d == %d? %s\n", 5, 5, myFunction(5, 5) ? "yes" : "no");
|
||||
return 0;
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
5 == 4? no
|
||||
5 == 5? yes
|
180
tests/testfp.c
180
tests/testfp.c
|
@ -1,180 +0,0 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Floating-point miscellanea using GNU lightning
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright 2000, 2002, 2004 Free Software Foundation, Inc.
|
||||
* Written by Paolo Bonzini.
|
||||
*
|
||||
* This file is part of GNU lightning.
|
||||
*
|
||||
* GNU lightning is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU lightning is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GNU lightning; see the file COPYING.LESSER; if not, write to the
|
||||
* Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lightning.h"
|
||||
|
||||
#ifdef JIT_FPR
|
||||
static jit_insn codeBuffer[300];
|
||||
static double a;
|
||||
|
||||
void
|
||||
int_test(char *what, jit_code code, double b, double c, double d, double e, double f)
|
||||
{
|
||||
a = b; printf("%s\t\t%d ", what, code.iptr ());
|
||||
a = c; printf("%d ", code.iptr());
|
||||
a = d; printf("%d ", code.iptr());
|
||||
a = e; printf("%d ", code.iptr());
|
||||
a = f; printf("%d\n", code.iptr());
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
jit_code code;
|
||||
volatile double x = 0.0;
|
||||
code.ptr = (char *) codeBuffer;
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jit_ldi_d(JIT_FPR0, &a);
|
||||
jit_movi_d(JIT_FPR1, 0.0);
|
||||
jit_gtr_d(JIT_R0, JIT_FPR0, JIT_FPR1);
|
||||
jit_ltr_d(JIT_R1, JIT_FPR0, JIT_FPR1);
|
||||
jit_subr_i(JIT_RET, JIT_R0, JIT_R1); /* [greater] - [less] = -1/0/1 */
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
int_test("compare", code, -2.6, -2.4, 0, 2.4, 2.6);
|
||||
|
||||
#ifdef __GNUC__
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jit_ldi_d(JIT_FPR0, &a);
|
||||
jit_movi_d(JIT_FPR1, 0.0);
|
||||
jit_eqr_d(JIT_R0, JIT_FPR0, JIT_FPR1);
|
||||
jit_ltgtr_d(JIT_R1, JIT_FPR0, JIT_FPR1);
|
||||
jit_lshi_i(JIT_R1, JIT_R1, 1);
|
||||
jit_orr_i(JIT_RET, JIT_R0, JIT_R1);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
int_test("nans", code, x / x, 1 / (a - a), -1 / (a - a), 0.0, -2.0);
|
||||
#else
|
||||
printf ("nans\t\t1 3 3 0 3\n");
|
||||
#endif
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jit_ldi_d(JIT_FPR0, &a);
|
||||
jit_truncr_d_i(JIT_RET, JIT_FPR0);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
int_test("trunc", code, -2.6, -2.4, 0, 2.4, 2.6);
|
||||
int_test("trunc", code, -3, -2, 0, 2, 3);
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jit_ldi_d(JIT_FPR0, &a);
|
||||
jit_ceilr_d_i(JIT_RET, JIT_FPR0);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
int_test("ceil", code, -2.6, -2.4, 0, 2.4, 2.6);
|
||||
int_test("ceil", code, -3, -2, 0, 2, 3);
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jit_ldi_d(JIT_FPR0, &a);
|
||||
jit_floorr_d_i(JIT_RET, JIT_FPR0);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
int_test("floor", code, -2.6, -2.4, 0, 2.4, 2.6);
|
||||
int_test("floor", code, -3, -2, 0, 2, 3);
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jit_ldi_d(JIT_FPR0, &a);
|
||||
jit_roundr_d_i(JIT_RET, JIT_FPR0);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
int_test("round", code, -2.6, -2.4, 0, 2.4, 2.6);
|
||||
int_test("round", code, -3, -2, 0, 2, 3);
|
||||
|
||||
#if 0 && defined JIT_TRANSCENDENTAL
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jitfp_sti_d(&a,
|
||||
jitfp_log(
|
||||
jitfp_exp(jitfp_imm(1.0))
|
||||
)
|
||||
);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
code.vptr();
|
||||
printf("log e = \t%f\n", a);
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jitfp_sti_d(&a,
|
||||
jitfp_atn(
|
||||
jitfp_imm(1.732050807657)
|
||||
)
|
||||
);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
code.vptr();
|
||||
printf("pi = \t%f\n", a*3);
|
||||
|
||||
jit_set_ip(codeBuffer);
|
||||
jit_leaf(0);
|
||||
jitfp_sti_d(&a,
|
||||
jitfp_tan(
|
||||
jitfp_ldi_d(&a)
|
||||
)
|
||||
);
|
||||
jit_ret();
|
||||
|
||||
jit_flush_code(codeBuffer, jit_get_ip().ptr);
|
||||
code.vptr();
|
||||
printf("tan^2 pi/3 = \t%f\n", a*a);
|
||||
|
||||
#endif /* JIT_TRANSCEDENTAL */
|
||||
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
int
|
||||
main()
|
||||
{
|
||||
return (77);
|
||||
}
|
||||
#endif
|
|
@ -1,10 +0,0 @@
|
|||
compare -1 -1 0 1 1
|
||||
nans 0 2 2 1 2
|
||||
trunc -2 -2 0 2 2
|
||||
trunc -3 -2 0 2 3
|
||||
ceil -2 -2 0 3 3
|
||||
ceil -3 -2 0 2 3
|
||||
floor -3 -3 0 2 2
|
||||
floor -3 -2 0 2 3
|
||||
round -3 -2 0 2 3
|
||||
round -3 -2 0 2 3
|
Loading…
Add table
Add a link
Reference in a new issue