1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-21 19:20: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:
pcpa 2012-12-02 19:44:36 -02:00
parent 75d99beb21
commit 7a1c455237
77 changed files with 17194 additions and 8221 deletions

View 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
View 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 */

View 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
View 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 */

View 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
View 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 */