mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-20 18:50:21 +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
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');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue