mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 20:00:19 +02:00
Rework to better describe what is used only during jit generation.
* include/lightning/jit_private.h, lib/jit_arm-cpu.c, lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips-cpu.c, lib/jit_mips.c, lib/jit_note.c, lib/jit_ppc-cpu.c, lib/jit_ppc.c, lib/jit_print.c, lib/jit_sparc-cpu.c, lib/jit_sparc.c, lib/jit_x86-cpu.c, lib/jit_x86.c, lib/lightning.c: Add an extra structure for data storage during jit generation, and release it after generating jit, to reduce a bit memory usage, and also to make it easier to understand what data is available during jit runtime.
This commit is contained in:
parent
f39eee6694
commit
9afca85921
16 changed files with 1328 additions and 1299 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2013-03-06 Paulo Andrade <pcpa@gnu.org>
|
||||
|
||||
* include/lightning/jit_private.h, lib/jit_arm-cpu.c,
|
||||
lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips-cpu.c,
|
||||
lib/jit_mips.c, lib/jit_note.c, lib/jit_ppc-cpu.c,
|
||||
lib/jit_ppc.c, lib/jit_print.c, lib/jit_sparc-cpu.c,
|
||||
lib/jit_sparc.c, lib/jit_x86-cpu.c, lib/jit_x86.c,
|
||||
lib/lightning.c: Add an extra structure for data storage
|
||||
during jit generation, and release it after generating
|
||||
jit, to reduce a bit memory usage, and also to make it
|
||||
easier to understand what data is available during
|
||||
jit runtime.
|
||||
|
||||
2013-03-06 Paulo Andrade <pcpa@gnu.org>
|
||||
|
||||
* lib/lightning.c: Make data and code buffer readonly.
|
||||
|
|
|
@ -79,9 +79,9 @@
|
|||
#define jit_size(vector) (sizeof(vector) / sizeof((vector)[0]))
|
||||
|
||||
#define jit_reg_free_p(regno) \
|
||||
(!jit_regset_tstbit(_jit->reglive, regno) && \
|
||||
!jit_regset_tstbit(_jit->regarg, regno) && \
|
||||
!jit_regset_tstbit(_jit->regsav, regno))
|
||||
(!jit_regset_tstbit(_jitc->reglive, regno) && \
|
||||
!jit_regset_tstbit(_jitc->regarg, regno) && \
|
||||
!jit_regset_tstbit(_jitc->regsav, regno))
|
||||
|
||||
/*
|
||||
* Private jit_class bitmasks
|
||||
|
@ -152,8 +152,8 @@ 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); \
|
||||
jit_regset_set_ui(_jitc->reglive, 0); \
|
||||
jit_regset_set_ui(_jitc->regmask, 0); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
|
@ -164,6 +164,7 @@ typedef struct jit_note jit_note_t;
|
|||
typedef struct jit_line jit_line_t;
|
||||
typedef struct jit_block jit_block_t;
|
||||
typedef struct jit_value jit_value_t;
|
||||
typedef struct jit_compiler jit_compiler_t;
|
||||
typedef struct jit_function jit_function_t;
|
||||
typedef struct jit_register jit_register_t;
|
||||
#if __arm__
|
||||
|
@ -264,14 +265,8 @@ struct jit_function {
|
|||
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;
|
||||
/* data used only during jit generation */
|
||||
struct jit_compiler {
|
||||
jit_node_t *head;
|
||||
jit_node_t *tail;
|
||||
jit_uint32_t done : 1; /* emit state finished */
|
||||
|
@ -285,17 +280,13 @@ struct jit_state {
|
|||
jit_regset_t regmask; /* register mask to update reglive */
|
||||
mpz_t blockmask; /* mask of visited basic blocks */
|
||||
struct {
|
||||
jit_uint8_t *ptr;
|
||||
jit_uint8_t *end;
|
||||
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" */
|
||||
|
@ -323,10 +314,8 @@ struct jit_state {
|
|||
} pool;
|
||||
jit_node_t *list;
|
||||
struct {
|
||||
jit_note_t *ptr;
|
||||
jit_node_t *head; /* first note node */
|
||||
jit_node_t *tail; /* linked list insertion */
|
||||
jit_word_t length;
|
||||
|
||||
/* fields to store temporary state information */
|
||||
jit_word_t size;
|
||||
|
@ -361,6 +350,30 @@ struct jit_state {
|
|||
#endif
|
||||
};
|
||||
|
||||
#define _jitc _jit->comp
|
||||
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;
|
||||
struct {
|
||||
jit_uint8_t *ptr;
|
||||
jit_word_t length;
|
||||
} code;
|
||||
struct {
|
||||
jit_uint8_t *ptr;
|
||||
jit_word_t length;
|
||||
} data;
|
||||
struct {
|
||||
jit_note_t *ptr;
|
||||
jit_word_t length;
|
||||
} note;
|
||||
jit_compiler_t *comp;
|
||||
};
|
||||
|
||||
struct jit_register {
|
||||
jit_reg_t spec;
|
||||
char *name;
|
||||
|
|
|
@ -2558,7 +2558,7 @@ _jmpi(jit_state_t *_jit, jit_word_t i0)
|
|||
jit_word_t d;
|
||||
w = _jit->pc.w;
|
||||
/* if thumb and in thumb mode */
|
||||
if (jit_thumb_p() && _jit->thumb) {
|
||||
if (jit_thumb_p() && _jitc->thumb) {
|
||||
d = ((i0 - w) >> 1) - 2;
|
||||
if (d >= -1024 && d <= 1023)
|
||||
T1_B(d & 0x7ff);
|
||||
|
@ -2590,7 +2590,7 @@ _jmpi_p(jit_state_t *_jit, jit_word_t i0)
|
|||
jit_word_t d;
|
||||
w = _jit->pc.w;
|
||||
/* if thumb and in thumb mode */
|
||||
if (jit_thumb_p() && _jit->thumb) {
|
||||
if (jit_thumb_p() && _jitc->thumb) {
|
||||
d = ((i0 - w) >> 1) - 2;
|
||||
assert(_s24P(d));
|
||||
T2_B(encode_thumb_jump(d));
|
||||
|
@ -3692,9 +3692,9 @@ _calli_p(jit_state_t *_jit, jit_word_t i0)
|
|||
static void
|
||||
_prolog(jit_state_t *_jit, jit_node_t *node)
|
||||
{
|
||||
_jit->function->stack = ((_jit->function->self.alen -
|
||||
_jitc->function->stack = ((_jitc->function->self.alen -
|
||||
/* align stack at 8 bytes */
|
||||
_jit->function->self.aoff) + 7) & -8;
|
||||
_jitc->function->self.aoff) + 7) & -8;
|
||||
|
||||
if (jit_thumb_p()) {
|
||||
/* switch to thumb mode (better approach would be to
|
||||
|
@ -3703,8 +3703,8 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
|
|||
* a pointer to a jit function) */
|
||||
ADDI(_R12_REGNO, _R15_REGNO, 1);
|
||||
BX(_R12_REGNO);
|
||||
if (!_jit->thumb)
|
||||
_jit->thumb = _jit->pc.w;
|
||||
if (!_jitc->thumb)
|
||||
_jitc->thumb = _jit->pc.w;
|
||||
if (jit_cpu.abi) {
|
||||
T2_PUSH(0x3f0|(1<<_FP_REGNO)|(1<<_LR_REGNO));
|
||||
VPUSH_F64(_D8_REGNO, 8);
|
||||
|
@ -3723,7 +3723,7 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
|
|||
PUSH(0x3ff|(1<<_FP_REGNO)|(1<<_LR_REGNO));
|
||||
}
|
||||
movr(_FP_REGNO, _SP_REGNO);
|
||||
subi(_SP_REGNO, _SP_REGNO, _jit->function->stack);
|
||||
subi(_SP_REGNO, _SP_REGNO, _jitc->function->stack);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3753,7 +3753,7 @@ _patch_at(jit_state_t *_jit,
|
|||
} u;
|
||||
u.w = instr;
|
||||
if (kind == arm_patch_jump) {
|
||||
if (jit_thumb_p() && instr >= _jit->thumb) {
|
||||
if (jit_thumb_p() && instr >= _jitc->thumb) {
|
||||
code2thumb(thumb.s[0], thumb.s[1], u.s[0], u.s[1]);
|
||||
if ((thumb.i & THUMB2_B) == THUMB2_B) {
|
||||
d = ((label - instr) >> 1) - 2;
|
||||
|
|
446
lib/jit_arm.c
446
lib/jit_arm.c
|
@ -187,7 +187,7 @@ _jit_init(jit_state_t *_jit)
|
|||
jit_int32_t regno;
|
||||
static jit_bool_t first = 1;
|
||||
|
||||
_jit->reglen = jit_size(_rvs) - 1;
|
||||
_jitc->reglen = jit_size(_rvs) - 1;
|
||||
if (first) {
|
||||
/* jit_get_cpu() should have been already called, and only once */
|
||||
if (!jit_cpu.vfp) {
|
||||
|
@ -209,58 +209,58 @@ _jit_prolog(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
if (_jit->function)
|
||||
if (_jitc->function)
|
||||
jit_epilog();
|
||||
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jit->regsav, 0);
|
||||
offset = _jit->functions.offset;
|
||||
if (offset >= _jit->functions.length) {
|
||||
_jit->functions.ptr = realloc(_jit->functions.ptr,
|
||||
(_jit->functions.length + 16) *
|
||||
assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jitc->regsav, 0);
|
||||
offset = _jitc->functions.offset;
|
||||
if (offset >= _jitc->functions.length) {
|
||||
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
|
||||
(_jitc->functions.length + 16) *
|
||||
sizeof(jit_function_t));
|
||||
memset(_jit->functions.ptr + _jit->functions.length, 0,
|
||||
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
|
||||
16 * sizeof(jit_function_t));
|
||||
_jit->functions.length += 16;
|
||||
_jitc->functions.length += 16;
|
||||
}
|
||||
_jit->function = _jit->functions.ptr + _jit->functions.offset++;
|
||||
_jit->function->self.size = stack_framesize;
|
||||
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
|
||||
_jitc->function->self.size = stack_framesize;
|
||||
if (jit_cpu.abi)
|
||||
_jit->function->self.size += 64;
|
||||
_jit->function->self.argi = _jit->function->self.argf =
|
||||
_jit->function->self.alen = 0;
|
||||
_jitc->function->self.size += 64;
|
||||
_jitc->function->self.argi = _jitc->function->self.argf =
|
||||
_jitc->function->self.alen = 0;
|
||||
if (jit_swf_p())
|
||||
/* 8 soft float registers */
|
||||
_jit->function->self.aoff = -64;
|
||||
_jitc->function->self.aoff = -64;
|
||||
else
|
||||
_jit->function->self.aoff = 0;
|
||||
_jit->function->self.call = jit_call_default;
|
||||
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t));
|
||||
_jitc->function->self.aoff = 0;
|
||||
_jitc->function->self.call = jit_call_default;
|
||||
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
|
||||
|
||||
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jit->function->prolog);
|
||||
_jit->function->prolog->w.w = offset;
|
||||
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jitc->function->prolog);
|
||||
_jitc->function->prolog->w.w = offset;
|
||||
_jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
/* u: label value
|
||||
* v: offset in blocks vector
|
||||
* w: offset in functions vector
|
||||
*/
|
||||
_jit->function->epilog->w.w = offset;
|
||||
_jitc->function->epilog->w.w = offset;
|
||||
|
||||
jit_regset_new(_jit->function->regset);
|
||||
jit_regset_new(_jitc->function->regset);
|
||||
}
|
||||
|
||||
jit_int32_t
|
||||
_jit_allocai(jit_state_t *_jit, jit_int32_t length)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
switch (length) {
|
||||
case 0: case 1: break;
|
||||
case 2: _jit->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jit->function->self.aoff &= -4; break;
|
||||
default: _jit->function->self.aoff &= -8; break;
|
||||
case 2: _jitc->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jitc->function->self.aoff &= -4; break;
|
||||
default: _jitc->function->self.aoff &= -8; break;
|
||||
}
|
||||
_jit->function->self.aoff -= length;
|
||||
return (_jit->function->self.aoff);
|
||||
_jitc->function->self.aoff -= length;
|
||||
return (_jitc->function->self.aoff);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -268,11 +268,11 @@ _jit_ret(jit_state_t *_jit)
|
|||
{
|
||||
jit_node_t *instr;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
|
||||
/* jump to epilog */
|
||||
instr = jit_jmpi();
|
||||
jit_patch_at(instr, _jit->function->epilog);
|
||||
jit_patch_at(instr, _jitc->function->epilog);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -352,10 +352,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
|
|||
void
|
||||
_jit_epilog(jit_state_t *_jit)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jit->function->epilog->next == NULL);
|
||||
jit_link(_jit->function->epilog);
|
||||
_jit->function = NULL;
|
||||
assert(_jitc->function);
|
||||
assert(_jitc->function->epilog->next == NULL);
|
||||
jit_link(_jitc->function->epilog);
|
||||
_jitc->function = NULL;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -363,12 +363,12 @@ _jit_arg(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi < 4)
|
||||
offset = _jit->function->self.argi++;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argi < 4)
|
||||
offset = _jitc->function->self.argi++;
|
||||
else {
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_word_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_word_t);
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg, offset));
|
||||
}
|
||||
|
@ -384,21 +384,21 @@ _jit_arg_f(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (jit_cpu.abi && !(_jit->function->self.call & jit_call_varargs)) {
|
||||
if (_jit->function->self.argf < 16) {
|
||||
offset = _jit->function->self.argf++;
|
||||
assert(_jitc->function);
|
||||
if (jit_cpu.abi && !(_jitc->function->self.call & jit_call_varargs)) {
|
||||
if (_jitc->function->self.argf < 16) {
|
||||
offset = _jitc->function->self.argf++;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_jit->function->self.argi < 4) {
|
||||
offset = _jit->function->self.argi++;
|
||||
if (_jitc->function->self.argi < 4) {
|
||||
offset = _jitc->function->self.argi++;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float32_t);
|
||||
done:
|
||||
return (jit_new_node_w(jit_code_arg_f, offset));
|
||||
}
|
||||
|
@ -414,29 +414,29 @@ _jit_arg_d(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (jit_cpu.abi && !(_jit->function->self.call & jit_call_varargs)) {
|
||||
if (_jit->function->self.argf < 15) {
|
||||
if (_jit->function->self.argf & 1)
|
||||
++_jit->function->self.argf;
|
||||
offset = _jit->function->self.argf;
|
||||
_jit->function->self.argf += 2;
|
||||
assert(_jitc->function);
|
||||
if (jit_cpu.abi && !(_jitc->function->self.call & jit_call_varargs)) {
|
||||
if (_jitc->function->self.argf < 15) {
|
||||
if (_jitc->function->self.argf & 1)
|
||||
++_jitc->function->self.argf;
|
||||
offset = _jitc->function->self.argf;
|
||||
_jitc->function->self.argf += 2;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_jit->function->self.argi < 3) {
|
||||
if (_jit->function->self.argi & 1)
|
||||
++_jit->function->self.argi;
|
||||
offset = _jit->function->self.argi;
|
||||
_jit->function->self.argi += 2;
|
||||
if (_jitc->function->self.argi < 3) {
|
||||
if (_jitc->function->self.argi & 1)
|
||||
++_jitc->function->self.argi;
|
||||
offset = _jitc->function->self.argi;
|
||||
_jitc->function->self.argi += 2;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (_jit->function->self.size & 7)
|
||||
_jit->function->self.size += 4;
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float64_t);
|
||||
if (_jitc->function->self.size & 7)
|
||||
_jitc->function->self.size += 4;
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float64_t);
|
||||
done:
|
||||
return (jit_new_node_w(jit_code_arg_d, offset));
|
||||
}
|
||||
|
@ -543,14 +543,14 @@ _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
|||
void
|
||||
_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movr(JIT_RA0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argi < 4) {
|
||||
jit_movr(JIT_RA0 - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
jit_stxi(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi(_jitc->function->call.size, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -559,40 +559,40 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movi(JIT_RA0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argi < 4) {
|
||||
jit_movi(JIT_RA0 - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
regno = jit_get_reg(jit_class_gpr);
|
||||
jit_movi(regno, u);
|
||||
jit_stxi(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_stxi(_jitc->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) {
|
||||
if (_jit->function->call.argf < 16) {
|
||||
jit_movr_f(JIT_FA0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
assert(_jitc->function);
|
||||
if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
|
||||
if (_jitc->function->call.argf < 16) {
|
||||
jit_movr_f(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movr_f_w(JIT_RA0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
if (_jitc->function->call.argi < 4) {
|
||||
jit_movr_f_w(JIT_RA0 - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
return;
|
||||
}
|
||||
}
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi_f(_jitc->function->call.size, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -600,63 +600,63 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) {
|
||||
if (_jit->function->call.argf < 16) {
|
||||
assert(_jitc->function);
|
||||
if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
|
||||
if (_jitc->function->call.argf < 16) {
|
||||
/* cannot jit_movi_f in the argument register because
|
||||
* float arguments are packed, and that would cause
|
||||
* either an assertion in debug mode, or overwritting
|
||||
* two registers */
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
jit_movr_f(JIT_FA0 - _jit->function->call.argf, regno);
|
||||
jit_movr_f(JIT_FA0 - _jitc->function->call.argf, regno);
|
||||
jit_unget_reg(regno);
|
||||
++_jit->function->call.argf;
|
||||
++_jitc->function->call.argf;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movi_f_w(JIT_RA0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
if (_jitc->function->call.argi < 4) {
|
||||
jit_movi_f_w(JIT_RA0 - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
return;
|
||||
}
|
||||
}
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_stxi_f(_jitc->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) {
|
||||
if (_jit->function->call.argf < 15) {
|
||||
if (_jit->function->call.argf & 1)
|
||||
++_jit->function->call.argf;
|
||||
jit_movr_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
_jit->function->call.argf += 2;
|
||||
assert(_jitc->function);
|
||||
if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
|
||||
if (_jitc->function->call.argf < 15) {
|
||||
if (_jitc->function->call.argf & 1)
|
||||
++_jitc->function->call.argf;
|
||||
jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
_jitc->function->call.argf += 2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_jit->function->call.argi & 1)
|
||||
++_jit->function->call.argi;
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movr_d_ww(JIT_RA0 - _jit->function->call.argi,
|
||||
JIT_RA0 - (_jit->function->call.argi + 1),
|
||||
if (_jitc->function->call.argi & 1)
|
||||
++_jitc->function->call.argi;
|
||||
if (_jitc->function->call.argi < 4) {
|
||||
jit_movr_d_ww(JIT_RA0 - _jitc->function->call.argi,
|
||||
JIT_RA0 - (_jitc->function->call.argi + 1),
|
||||
u);
|
||||
_jit->function->call.argi += 2;
|
||||
_jitc->function->call.argi += 2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_jit->function->call.size & 7)
|
||||
_jit->function->call.size += 4;
|
||||
jit_stxi_d(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
if (_jitc->function->call.size & 7)
|
||||
_jitc->function->call.size += 4;
|
||||
jit_stxi_d(_jitc->function->call.size, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -664,34 +664,34 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) {
|
||||
if (_jit->function->call.argf < 15) {
|
||||
if (_jit->function->call.argf & 1)
|
||||
++_jit->function->call.argf;
|
||||
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
_jit->function->call.argf += 2;
|
||||
assert(_jitc->function);
|
||||
if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
|
||||
if (_jitc->function->call.argf < 15) {
|
||||
if (_jitc->function->call.argf & 1)
|
||||
++_jitc->function->call.argf;
|
||||
jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
_jitc->function->call.argf += 2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_jit->function->call.argi & 1)
|
||||
++_jit->function->call.argi;
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movi_d_ww(JIT_RA0 - _jit->function->call.argi,
|
||||
JIT_RA0 - (_jit->function->call.argi + 1),
|
||||
if (_jitc->function->call.argi & 1)
|
||||
++_jitc->function->call.argi;
|
||||
if (_jitc->function->call.argi < 4) {
|
||||
jit_movi_d_ww(JIT_RA0 - _jitc->function->call.argi,
|
||||
JIT_RA0 - (_jitc->function->call.argi + 1),
|
||||
u);
|
||||
_jit->function->call.argi += 2;
|
||||
_jitc->function->call.argi += 2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_jit->function->call.size & 7)
|
||||
_jit->function->call.size += 4;
|
||||
if (_jitc->function->call.size & 7)
|
||||
_jitc->function->call.size += 4;
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_d(regno, u);
|
||||
jit_stxi_d(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_stxi_d(_jitc->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
|
||||
jit_bool_t
|
||||
|
@ -719,15 +719,15 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
|
|||
{
|
||||
jit_node_t *node;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
node = jit_callr(r0);
|
||||
node->v.w = _jit->function->self.argi;
|
||||
node->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
node->v.w = _jitc->function->self.argi;
|
||||
node->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -735,15 +735,15 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
|
|||
{
|
||||
jit_node_t *node;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
node = jit_calli(i0);
|
||||
node->v.w = _jit->function->call.argi;
|
||||
node->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
node->v.w = _jitc->function->call.argi;
|
||||
node->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
return (node);
|
||||
}
|
||||
|
||||
|
@ -818,7 +818,7 @@ _emit_code(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
|
||||
jit_reglive_setup();
|
||||
|
||||
|
@ -1034,8 +1034,8 @@ _emit_code(jit_state_t *_jit)
|
|||
patch(word, node); \
|
||||
} \
|
||||
break
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jit->code.end)
|
||||
for (node = _jitc->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jitc->code.end)
|
||||
return (NULL);
|
||||
|
||||
value = jit_classify(node->code);
|
||||
|
@ -1415,22 +1415,22 @@ _emit_code(jit_state_t *_jit)
|
|||
calli(node->u.w);
|
||||
break;
|
||||
case jit_code_prolog:
|
||||
_jit->function = _jit->functions.ptr + node->w.w;
|
||||
_jitc->function = _jitc->functions.ptr + node->w.w;
|
||||
undo.node = node;
|
||||
undo.word = _jit->pc.w;
|
||||
undo.data = _jit->consts.data;
|
||||
undo.thumb = _jit->thumb;
|
||||
undo.const_offset = _jit->consts.offset;
|
||||
undo.patch_offset = _jit->patches.offset;
|
||||
if (_jit->data_info.ptr)
|
||||
undo.info_offset = _jit->data_info.offset;
|
||||
undo.data = _jitc->consts.data;
|
||||
undo.thumb = _jitc->thumb;
|
||||
undo.const_offset = _jitc->consts.offset;
|
||||
undo.patch_offset = _jitc->patches.offset;
|
||||
if (_jitc->data_info.ptr)
|
||||
undo.info_offset = _jitc->data_info.offset;
|
||||
restart_function:
|
||||
_jit->again = 0;
|
||||
_jitc->again = 0;
|
||||
prolog(node);
|
||||
break;
|
||||
case jit_code_epilog:
|
||||
assert(_jit->function == _jit->functions.ptr + node->w.w);
|
||||
if (_jit->again) {
|
||||
assert(_jitc->function == _jitc->functions.ptr + node->w.w);
|
||||
if (_jitc->again) {
|
||||
for (temp = undo.node->next;
|
||||
temp != node; temp = temp->next) {
|
||||
if (temp->code == jit_code_label ||
|
||||
|
@ -1440,19 +1440,19 @@ _emit_code(jit_state_t *_jit)
|
|||
node = undo.node;
|
||||
_jit->pc.w = undo.word;
|
||||
invalidate_consts();
|
||||
_jit->consts.data = undo.data;
|
||||
_jit->thumb = undo.thumb;
|
||||
_jit->consts.offset = undo.const_offset;
|
||||
_jit->patches.offset = undo.patch_offset;
|
||||
if (_jit->data_info.ptr)
|
||||
_jit->data_info.offset = undo.info_offset;
|
||||
_jitc->consts.data = undo.data;
|
||||
_jitc->thumb = undo.thumb;
|
||||
_jitc->consts.offset = undo.const_offset;
|
||||
_jitc->patches.offset = undo.patch_offset;
|
||||
if (_jitc->data_info.ptr)
|
||||
_jitc->data_info.offset = undo.info_offset;
|
||||
goto restart_function;
|
||||
}
|
||||
/* remember label is defined */
|
||||
node->flag |= jit_flag_patch;
|
||||
node->u.w = _jit->pc.w;
|
||||
epilog(node);
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
flush_consts();
|
||||
break;
|
||||
case jit_code_movr_w_f:
|
||||
|
@ -1504,7 +1504,7 @@ _emit_code(jit_state_t *_jit)
|
|||
/* update register live state */
|
||||
jit_reglive(node);
|
||||
|
||||
if (_jit->consts.length && _jit->pc.uc - _jit->consts.data >= 3968) {
|
||||
if (_jitc->consts.length && _jit->pc.uc - _jitc->consts.data >= 3968) {
|
||||
/* longest sequence should be 64 bytes, but preventively
|
||||
* do not let it go past 128 remaining bytes before a flush */
|
||||
if (node->next &&
|
||||
|
@ -1541,10 +1541,10 @@ _emit_code(jit_state_t *_jit)
|
|||
#undef case_rr
|
||||
|
||||
flush_consts();
|
||||
for (offset = 0; offset < _jit->patches.offset; offset++) {
|
||||
assert(_jit->patches.ptr[offset].kind & arm_patch_node);
|
||||
node = _jit->patches.ptr[offset].node;
|
||||
word = _jit->patches.ptr[offset].inst;
|
||||
for (offset = 0; offset < _jitc->patches.offset; offset++) {
|
||||
assert(_jitc->patches.ptr[offset].kind & arm_patch_node);
|
||||
node = _jitc->patches.ptr[offset].node;
|
||||
word = _jitc->patches.ptr[offset].inst;
|
||||
if (!jit_thumb_p() &&
|
||||
(node->code == jit_code_movi || node->code == jit_code_calli)) {
|
||||
/* calculate where to patch word */
|
||||
|
@ -1560,7 +1560,7 @@ _emit_code(jit_state_t *_jit)
|
|||
word = word + 8 + value;
|
||||
}
|
||||
value = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
|
||||
patch_at(_jit->patches.ptr[offset].kind & ~arm_patch_node, word, value);
|
||||
patch_at(_jitc->patches.ptr[offset].kind & ~arm_patch_node, word, value);
|
||||
}
|
||||
|
||||
__clear_cache(_jit->code.ptr, _jit->pc.uc);
|
||||
|
@ -1612,28 +1612,28 @@ _jit_get_reg_pair(jit_state_t *_jit)
|
|||
* return JIT_NOREG if fail, as the cost of spills is greater
|
||||
* than splitting a double load/store in two operations. */
|
||||
if (jit_reg_free_p(_R0) && jit_reg_free_p(_R1)) {
|
||||
jit_regset_setbit(_jit->regarg, _R0);
|
||||
jit_regset_setbit(_jit->regarg, _R1);
|
||||
jit_regset_setbit(_jitc->regarg, _R0);
|
||||
jit_regset_setbit(_jitc->regarg, _R1);
|
||||
return (_R0);
|
||||
}
|
||||
if (jit_reg_free_p(_R2) && jit_reg_free_p(_R3)) {
|
||||
jit_regset_setbit(_jit->regarg, _R2);
|
||||
jit_regset_setbit(_jit->regarg, _R3);
|
||||
jit_regset_setbit(_jitc->regarg, _R2);
|
||||
jit_regset_setbit(_jitc->regarg, _R3);
|
||||
return (_R2);
|
||||
}
|
||||
if (jit_reg_free_p(_R4) && jit_reg_free_p(_R5)) {
|
||||
jit_regset_setbit(_jit->regarg, _R4);
|
||||
jit_regset_setbit(_jit->regarg, _R5);
|
||||
jit_regset_setbit(_jitc->regarg, _R4);
|
||||
jit_regset_setbit(_jitc->regarg, _R5);
|
||||
return (_R4);
|
||||
}
|
||||
if (jit_reg_free_p(_R6) && jit_reg_free_p(_R7)) {
|
||||
jit_regset_setbit(_jit->regarg, _R6);
|
||||
jit_regset_setbit(_jit->regarg, _R7);
|
||||
jit_regset_setbit(_jitc->regarg, _R6);
|
||||
jit_regset_setbit(_jitc->regarg, _R7);
|
||||
return (_R6);
|
||||
}
|
||||
if (jit_reg_free_p(_R8) && jit_reg_free_p(_R9)) {
|
||||
jit_regset_setbit(_jit->regarg, _R8);
|
||||
jit_regset_setbit(_jit->regarg, _R9);
|
||||
jit_regset_setbit(_jitc->regarg, _R8);
|
||||
jit_regset_setbit(_jitc->regarg, _R9);
|
||||
return (_R8);
|
||||
}
|
||||
return (JIT_NOREG);
|
||||
|
@ -1680,7 +1680,7 @@ _load_const(jit_state_t *_jit, jit_bool_t uniq, jit_int32_t r0, jit_word_t i0)
|
|||
*/
|
||||
|
||||
/* search in previous constant pool */
|
||||
if ((data = (jit_int32_t *)_jit->consts.data)) {
|
||||
if ((data = (jit_int32_t *)_jitc->consts.data)) {
|
||||
w = (jit_word_t)data;
|
||||
/* maximum backwards offset */
|
||||
base = (_jit->pc.w + 8) - 4092;
|
||||
|
@ -1689,7 +1689,7 @@ _load_const(jit_state_t *_jit, jit_bool_t uniq, jit_int32_t r0, jit_word_t i0)
|
|||
base = 0;
|
||||
else
|
||||
base = (base - w) >> 2;
|
||||
size = _jit->consts.size >> 2;
|
||||
size = _jitc->consts.size >> 2;
|
||||
for (offset = size - 1; offset >= base; offset--) {
|
||||
if (data[offset] == i0) {
|
||||
w = (jit_word_t)(data + offset);
|
||||
|
@ -1703,15 +1703,15 @@ _load_const(jit_state_t *_jit, jit_bool_t uniq, jit_int32_t r0, jit_word_t i0)
|
|||
else
|
||||
assert(i0 == 0);
|
||||
|
||||
_jit->consts.patches[_jit->consts.offset++] = _jit->pc.w;
|
||||
_jitc->consts.patches[_jitc->consts.offset++] = _jit->pc.w;
|
||||
/* (probably) positive forward offset */
|
||||
LDRI(r0, _R15_REGNO, 0);
|
||||
|
||||
if (!uniq) {
|
||||
/* search already requested values */
|
||||
for (offset = 0; offset < _jit->consts.length; offset++) {
|
||||
if (_jit->consts.values[offset] == i0) {
|
||||
_jit->consts.patches[_jit->consts.offset++] = offset;
|
||||
for (offset = 0; offset < _jitc->consts.length; offset++) {
|
||||
if (_jitc->consts.values[offset] == i0) {
|
||||
_jitc->consts.patches[_jitc->consts.offset++] = offset;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1720,11 +1720,11 @@ _load_const(jit_state_t *_jit, jit_bool_t uniq, jit_int32_t r0, jit_word_t i0)
|
|||
#if DEBUG
|
||||
/* cannot run out of space because of limited range
|
||||
* but assert anyway to catch logic errors */
|
||||
assert(_jit->consts.length < 1024);
|
||||
assert(_jit->consts.offset < 2048);
|
||||
assert(_jitc->consts.length < 1024);
|
||||
assert(_jitc->consts.offset < 2048);
|
||||
#endif
|
||||
_jit->consts.patches[_jit->consts.offset++] = _jit->consts.length;
|
||||
_jit->consts.values[_jit->consts.length++] = i0;
|
||||
_jitc->consts.patches[_jitc->consts.offset++] = _jitc->consts.length;
|
||||
_jitc->consts.values[_jitc->consts.length++] = i0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1734,35 +1734,35 @@ _flush_consts(jit_state_t *_jit)
|
|||
jit_int32_t offset;
|
||||
|
||||
/* if no forward constants */
|
||||
if (!_jit->consts.length)
|
||||
if (!_jitc->consts.length)
|
||||
return;
|
||||
assert(!jit_thumb_p());
|
||||
word = _jit->pc.w;
|
||||
_jit->consts.data = _jit->pc.uc;
|
||||
_jit->consts.size = _jit->consts.length << 2;
|
||||
_jitc->consts.data = _jit->pc.uc;
|
||||
_jitc->consts.size = _jitc->consts.length << 2;
|
||||
/* FIXME check will not overrun, otherwise, need to reallocate
|
||||
* code buffer and start over */
|
||||
memcpy(_jit->consts.data, _jit->consts.values, _jit->consts.size);
|
||||
_jit->pc.w += _jit->consts.size;
|
||||
memcpy(_jitc->consts.data, _jitc->consts.values, _jitc->consts.size);
|
||||
_jit->pc.w += _jitc->consts.size;
|
||||
|
||||
if (_jit->data_info.ptr) {
|
||||
if (_jit->data_info.offset >= _jit->data_info.length) {
|
||||
_jit->data_info.ptr = realloc(_jit->data_info.ptr,
|
||||
(_jit->data_info.length + 1024) *
|
||||
if (_jitc->data_info.ptr) {
|
||||
if (_jitc->data_info.offset >= _jitc->data_info.length) {
|
||||
_jitc->data_info.ptr = realloc(_jitc->data_info.ptr,
|
||||
(_jitc->data_info.length + 1024) *
|
||||
sizeof(jit_data_info_t));
|
||||
memset(_jit->data_info.ptr + _jit->data_info.length, 0,
|
||||
memset(_jitc->data_info.ptr + _jitc->data_info.length, 0,
|
||||
1024 * sizeof(jit_data_info_t));
|
||||
_jit->data_info.length += 1024;
|
||||
_jitc->data_info.length += 1024;
|
||||
}
|
||||
_jit->data_info.ptr[_jit->data_info.offset].code = word;
|
||||
_jit->data_info.ptr[_jit->data_info.offset].length = _jit->consts.size;
|
||||
++_jit->data_info.offset;
|
||||
_jitc->data_info.ptr[_jitc->data_info.offset].code = word;
|
||||
_jitc->data_info.ptr[_jitc->data_info.offset].length = _jitc->consts.size;
|
||||
++_jitc->data_info.offset;
|
||||
}
|
||||
|
||||
for (offset = 0; offset < _jit->consts.offset; offset += 2)
|
||||
patch_at(arm_patch_load, _jit->consts.patches[offset],
|
||||
word + (_jit->consts.patches[offset + 1] << 2));
|
||||
_jit->consts.length = _jit->consts.offset = 0;
|
||||
for (offset = 0; offset < _jitc->consts.offset; offset += 2)
|
||||
patch_at(arm_patch_load, _jitc->consts.patches[offset],
|
||||
word + (_jitc->consts.patches[offset + 1] << 2));
|
||||
_jitc->consts.length = _jitc->consts.offset = 0;
|
||||
}
|
||||
|
||||
/* to be called if needing to start over a function */
|
||||
|
@ -1770,8 +1770,8 @@ static void
|
|||
_invalidate_consts(jit_state_t *_jit)
|
||||
{
|
||||
/* if no forward constants */
|
||||
if (_jit->consts.length)
|
||||
_jit->consts.length = _jit->consts.offset = 0;
|
||||
if (_jitc->consts.length)
|
||||
_jitc->consts.length = _jitc->consts.offset = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1794,16 +1794,16 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
|
|||
}
|
||||
assert(!(flag & jit_flag_patch));
|
||||
kind |= arm_patch_node;
|
||||
if (_jit->patches.offset >= _jit->patches.length) {
|
||||
_jit->patches.ptr = realloc(_jit->patches.ptr,
|
||||
(_jit->patches.length + 1024) *
|
||||
if (_jitc->patches.offset >= _jitc->patches.length) {
|
||||
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
|
||||
(_jitc->patches.length + 1024) *
|
||||
sizeof(jit_patch_t));
|
||||
memset(_jit->patches.ptr + _jit->patches.length, 0,
|
||||
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
|
||||
1024 * sizeof(jit_patch_t));
|
||||
_jit->patches.length += 1024;
|
||||
_jitc->patches.length += 1024;
|
||||
}
|
||||
_jit->patches.ptr[_jit->patches.offset].kind = kind;
|
||||
_jit->patches.ptr[_jit->patches.offset].inst = instr;
|
||||
_jit->patches.ptr[_jit->patches.offset].node = node;
|
||||
++_jit->patches.offset;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].kind = kind;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].inst = instr;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].node = node;
|
||||
++_jitc->patches.offset;
|
||||
}
|
||||
|
|
|
@ -287,15 +287,15 @@ _disassemble(jit_state_t *_jit, jit_pointer_t code, jit_int32_t length)
|
|||
#if __arm__
|
||||
again:
|
||||
if (data_info) {
|
||||
while (_jit->data_info.ptr[data_offset].code < pc) {
|
||||
while (_jitc->data_info.ptr[data_offset].code < pc) {
|
||||
data_offset += 2;
|
||||
if (data_offset >= _jit->data_info.length) {
|
||||
if (data_offset >= _jitc->data_info.length) {
|
||||
data_info = 0;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
if (pc == _jit->data_info.ptr[data_offset].code) {
|
||||
offset = _jit->data_info.ptr[data_offset].length;
|
||||
if (pc == _jitc->data_info.ptr[data_offset].code) {
|
||||
offset = _jitc->data_info.ptr[data_offset].length;
|
||||
for (; offset >= 4; offset -= 4, pc += 4) {
|
||||
bytes = sprintf(buffer, address_buffer_format, pc);
|
||||
(*disasm_info.fprintf_func)(disasm_stream,
|
||||
|
|
|
@ -2773,79 +2773,79 @@ _calli_p(jit_state_t *_jit, jit_word_t i0)
|
|||
static void
|
||||
_prolog(jit_state_t *_jit, jit_node_t *node)
|
||||
{
|
||||
_jit->function->stack = ((/* first 16 bytes must be allocated */
|
||||
(_jit->function->self.alen > 16 ?
|
||||
_jit->function->self.alen : 16) -
|
||||
_jitc->function->stack = ((/* first 16 bytes must be allocated */
|
||||
(_jitc->function->self.alen > 16 ?
|
||||
_jitc->function->self.alen : 16) -
|
||||
/* align stack at 8 bytes */
|
||||
_jit->function->self.aoff) + 7) & -8;
|
||||
_jitc->function->self.aoff) + 7) & -8;
|
||||
/* callee save registers */
|
||||
subi(_SP_REGNO, _SP_REGNO, stack_framesize);
|
||||
#if __WORDSIZE == 32
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F30))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F30))
|
||||
stxi_d(96, _SP_REGNO, _F30_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F28))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F28))
|
||||
stxi_d(88, _SP_REGNO, _F28_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F26))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F26))
|
||||
stxi_d(80, _SP_REGNO, _F26_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F24))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F24))
|
||||
stxi_d(72, _SP_REGNO, _F24_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F22))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F22))
|
||||
stxi_d(64, _SP_REGNO, _F22_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F20))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F20))
|
||||
stxi_d(56, _SP_REGNO, _F20_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F18))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F18))
|
||||
stxi_d(48, _SP_REGNO, _F18_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F16))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F16))
|
||||
stxi_d(40, _SP_REGNO, _F16_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S7))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S7))
|
||||
stxi(36, _SP_REGNO, _S7_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S6))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S6))
|
||||
stxi(32, _SP_REGNO, _S6_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S5))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S5))
|
||||
stxi(28, _SP_REGNO, _S5_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S4))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S4))
|
||||
stxi(24, _SP_REGNO, _S4_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S3))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S3))
|
||||
stxi(20, _SP_REGNO, _S3_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S2))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S2))
|
||||
stxi(16, _SP_REGNO, _S2_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S1))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S1))
|
||||
stxi(12, _SP_REGNO, _S1_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S0))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S0))
|
||||
stxi( 8, _SP_REGNO, _S0_REGNO);
|
||||
stxi( 4, _SP_REGNO, _RA_REGNO);
|
||||
#else
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F30))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F30))
|
||||
stxi_d(136, _SP_REGNO, _F30_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F28))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F28))
|
||||
stxi_d(128, _SP_REGNO, _F28_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F26))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F26))
|
||||
stxi_d(120, _SP_REGNO, _F26_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F24))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F24))
|
||||
stxi_d(112, _SP_REGNO, _F24_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F22))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F22))
|
||||
stxi_d(104, _SP_REGNO, _F22_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F20))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F20))
|
||||
stxi_d(96, _SP_REGNO, _F20_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F18))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F18))
|
||||
stxi_d(88, _SP_REGNO, _F18_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F16))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F16))
|
||||
stxi_d(80, _SP_REGNO, _F16_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S7))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S7))
|
||||
stxi(72, _SP_REGNO, _S7_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S6))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S6))
|
||||
stxi(64, _SP_REGNO, _S6_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S5))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S5))
|
||||
stxi(56, _SP_REGNO, _S5_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S4))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S4))
|
||||
stxi(48, _SP_REGNO, _S4_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S3))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S3))
|
||||
stxi(40, _SP_REGNO, _S3_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S2))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S2))
|
||||
stxi(32, _SP_REGNO, _S2_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S1))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S1))
|
||||
stxi(24, _SP_REGNO, _S1_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S0))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S0))
|
||||
stxi(16, _SP_REGNO, _S0_REGNO);
|
||||
stxi( 8, _SP_REGNO, _RA_REGNO);
|
||||
#endif
|
||||
|
@ -2853,7 +2853,7 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
|
|||
movr(_BP_REGNO, _SP_REGNO);
|
||||
|
||||
/* alloca */
|
||||
subi(_SP_REGNO, _SP_REGNO, _jit->function->stack);
|
||||
subi(_SP_REGNO, _SP_REGNO, _jitc->function->stack);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2862,71 +2862,71 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
|
|||
/* callee save registers */
|
||||
movr(_SP_REGNO, _BP_REGNO);
|
||||
#if __WORDSIZE == 32
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F30))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F30))
|
||||
ldxi_d(_F30_REGNO, _SP_REGNO, 96);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F28))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F28))
|
||||
ldxi_d(_F28_REGNO, _SP_REGNO, 88);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F26))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F26))
|
||||
ldxi_d(_F26_REGNO, _SP_REGNO, 80);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F24))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F24))
|
||||
ldxi_d(_F24_REGNO, _SP_REGNO, 72);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F22))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F22))
|
||||
ldxi_d(_F22_REGNO, _SP_REGNO, 64);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F20))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F20))
|
||||
ldxi_d(_F20_REGNO, _SP_REGNO, 56);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F18))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F18))
|
||||
ldxi_d(_F18_REGNO, _SP_REGNO, 48);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F16))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F16))
|
||||
ldxi_d(_F16_REGNO, _SP_REGNO, 40);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S7))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S7))
|
||||
ldxi(_S7_REGNO, _SP_REGNO, 36);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S6))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S6))
|
||||
ldxi(_S6_REGNO, _SP_REGNO, 32);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S5))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S5))
|
||||
ldxi(_S5_REGNO, _SP_REGNO, 28);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S4))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S4))
|
||||
ldxi(_S4_REGNO, _SP_REGNO, 24);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S3))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S3))
|
||||
ldxi(_S3_REGNO, _SP_REGNO, 20);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S2))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S2))
|
||||
ldxi(_S2_REGNO, _SP_REGNO, 16);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S1))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S1))
|
||||
ldxi(_S1_REGNO, _SP_REGNO, 12);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S0))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S0))
|
||||
ldxi(_S0_REGNO, _SP_REGNO, 8);
|
||||
ldxi(_RA_REGNO, _SP_REGNO, 4);
|
||||
#else
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F30))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F30))
|
||||
ldxi_d(_F30_REGNO, _SP_REGNO, 136);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F28))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F28))
|
||||
ldxi_d(_F28_REGNO, _SP_REGNO, 128);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F26))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F26))
|
||||
ldxi_d(_F26_REGNO, _SP_REGNO, 120);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F24))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F24))
|
||||
ldxi_d(_F24_REGNO, _SP_REGNO, 112);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F22))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F22))
|
||||
ldxi_d(_F22_REGNO, _SP_REGNO, 104);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F20))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F20))
|
||||
ldxi_d(_F20_REGNO, _SP_REGNO, 96);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F18))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F18))
|
||||
ldxi_d(_F18_REGNO, _SP_REGNO, 88);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F16))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F16))
|
||||
ldxi_d(_F16_REGNO, _SP_REGNO, 80);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S7))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S7))
|
||||
ldxi(_S7_REGNO, _SP_REGNO, 72);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S6))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S6))
|
||||
ldxi(_S6_REGNO, _SP_REGNO, 64);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S5))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S5))
|
||||
ldxi(_S5_REGNO, _SP_REGNO, 56);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S4))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S4))
|
||||
ldxi(_S4_REGNO, _SP_REGNO, 48);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S3))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S3))
|
||||
ldxi(_S3_REGNO, _SP_REGNO, 40);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S2))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S2))
|
||||
ldxi(_S2_REGNO, _SP_REGNO, 32);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S1))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S1))
|
||||
ldxi(_S1_REGNO, _SP_REGNO, 24);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _S0))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _S0))
|
||||
ldxi(_S0_REGNO, _SP_REGNO, 16);
|
||||
ldxi(_RA_REGNO, _SP_REGNO, 8);
|
||||
#endif
|
||||
|
|
264
lib/jit_mips.c
264
lib/jit_mips.c
|
@ -109,7 +109,7 @@ jit_get_cpu(void)
|
|||
void
|
||||
_jit_init(jit_state_t *_jit)
|
||||
{
|
||||
_jit->reglen = jit_size(_rvs) - 1;
|
||||
_jitc->reglen = jit_size(_rvs) - 1;
|
||||
jit_carry = _NOREG;
|
||||
}
|
||||
|
||||
|
@ -118,51 +118,51 @@ _jit_prolog(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
if (_jit->function)
|
||||
if (_jitc->function)
|
||||
jit_epilog();
|
||||
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jit->regsav, 0);
|
||||
offset = _jit->functions.offset;
|
||||
if (offset >= _jit->functions.length) {
|
||||
_jit->functions.ptr = realloc(_jit->functions.ptr,
|
||||
(_jit->functions.length + 16) *
|
||||
assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jitc->regsav, 0);
|
||||
offset = _jitc->functions.offset;
|
||||
if (offset >= _jitc->functions.length) {
|
||||
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
|
||||
(_jitc->functions.length + 16) *
|
||||
sizeof(jit_function_t));
|
||||
memset(_jit->functions.ptr + _jit->functions.length, 0,
|
||||
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
|
||||
16 * sizeof(jit_function_t));
|
||||
_jit->functions.length += 16;
|
||||
_jitc->functions.length += 16;
|
||||
}
|
||||
_jit->function = _jit->functions.ptr + _jit->functions.offset++;
|
||||
_jit->function->self.size = stack_framesize;
|
||||
_jit->function->self.argi = _jit->function->self.argf =
|
||||
_jit->function->self.aoff = _jit->function->self.alen = 0;
|
||||
_jit->function->self.call = jit_call_default;
|
||||
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t));
|
||||
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
|
||||
_jitc->function->self.size = stack_framesize;
|
||||
_jitc->function->self.argi = _jitc->function->self.argf =
|
||||
_jitc->function->self.aoff = _jitc->function->self.alen = 0;
|
||||
_jitc->function->self.call = jit_call_default;
|
||||
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
|
||||
|
||||
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jit->function->prolog);
|
||||
_jit->function->prolog->w.w = offset;
|
||||
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jitc->function->prolog);
|
||||
_jitc->function->prolog->w.w = offset;
|
||||
_jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
/* u: label value
|
||||
* v: offset in blocks vector
|
||||
* w: offset in functions vector
|
||||
*/
|
||||
_jit->function->epilog->w.w = offset;
|
||||
_jitc->function->epilog->w.w = offset;
|
||||
|
||||
jit_regset_new(_jit->function->regset);
|
||||
jit_regset_new(_jitc->function->regset);
|
||||
}
|
||||
|
||||
jit_int32_t
|
||||
_jit_allocai(jit_state_t *_jit, jit_int32_t length)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
switch (length) {
|
||||
case 0: case 1: break;
|
||||
case 2: _jit->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jit->function->self.aoff &= -4; break;
|
||||
default: _jit->function->self.aoff &= -8; break;
|
||||
case 2: _jitc->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jitc->function->self.aoff &= -4; break;
|
||||
default: _jitc->function->self.aoff &= -8; break;
|
||||
}
|
||||
_jit->function->self.aoff -= length;
|
||||
return (_jit->function->self.aoff);
|
||||
_jitc->function->self.aoff -= length;
|
||||
return (_jitc->function->self.aoff);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -170,11 +170,11 @@ _jit_ret(jit_state_t *_jit)
|
|||
{
|
||||
jit_node_t *instr;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
|
||||
/* jump to epilog */
|
||||
instr = jit_jmpi();
|
||||
jit_patch_at(instr, _jit->function->epilog);
|
||||
jit_patch_at(instr, _jitc->function->epilog);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -232,10 +232,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
|
|||
void
|
||||
_jit_epilog(jit_state_t *_jit)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jit->function->epilog->next == NULL);
|
||||
jit_link(_jit->function->epilog);
|
||||
_jit->function = NULL;
|
||||
assert(_jitc->function);
|
||||
assert(_jitc->function->epilog->next == NULL);
|
||||
jit_link(_jitc->function->epilog);
|
||||
_jitc->function = NULL;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -243,12 +243,12 @@ _jit_arg(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
offset = (_jit->function->self.size - stack_framesize) >> 2;
|
||||
_jit->function->self.argi = 1;
|
||||
assert(_jitc->function);
|
||||
offset = (_jitc->function->self.size - stack_framesize) >> 2;
|
||||
_jitc->function->self.argi = 1;
|
||||
if (offset >= 4)
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_word_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_word_t);
|
||||
return (jit_new_node_w(jit_code_arg, offset));
|
||||
}
|
||||
|
||||
|
@ -263,21 +263,21 @@ _jit_arg_f(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
offset = (_jit->function->self.size - stack_framesize) >> 2;
|
||||
assert(_jitc->function);
|
||||
offset = (_jitc->function->self.size - stack_framesize) >> 2;
|
||||
if (offset < 4) {
|
||||
if (!_jit->function->self.argi) {
|
||||
if (!_jitc->function->self.argi) {
|
||||
if (offset == 0)
|
||||
offset = 4;
|
||||
else {
|
||||
offset = 6;
|
||||
_jit->function->self.argi = 1;
|
||||
_jitc->function->self.argi = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float32_t);
|
||||
|
||||
return (jit_new_node_w(jit_code_arg_f, offset));
|
||||
}
|
||||
|
@ -294,19 +294,19 @@ _jit_arg_d(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.size & 7) {
|
||||
_jit->function->self.size += 4;
|
||||
_jit->function->self.argi = 1;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.size & 7) {
|
||||
_jitc->function->self.size += 4;
|
||||
_jitc->function->self.argi = 1;
|
||||
}
|
||||
offset = (_jit->function->self.size - stack_framesize) >> 2;
|
||||
offset = (_jitc->function->self.size - stack_framesize) >> 2;
|
||||
if (offset < 4) {
|
||||
if (!_jit->function->self.argi)
|
||||
if (!_jitc->function->self.argi)
|
||||
offset += 4;
|
||||
}
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float64_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float64_t);
|
||||
return (jit_new_node_w(jit_code_arg_d, offset));
|
||||
}
|
||||
|
||||
|
@ -413,14 +413,14 @@ _jit_pushargr(jit_state_t *_jit, jit_int32_t u)
|
|||
{
|
||||
jit_word_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
offset = _jit->function->call.size >> 2;
|
||||
_jit->function->call.argi = 1;
|
||||
assert(_jitc->function);
|
||||
offset = _jitc->function->call.size >> 2;
|
||||
_jitc->function->call.argi = 1;
|
||||
if (offset < 4)
|
||||
jit_movr(_A0 - offset, u);
|
||||
else
|
||||
jit_stxi(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi(_jitc->function->call.size, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -429,18 +429,18 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
|||
jit_int32_t regno;
|
||||
jit_word_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
offset = _jit->function->call.size >> 2;
|
||||
++_jit->function->call.argi;
|
||||
assert(_jitc->function);
|
||||
offset = _jitc->function->call.size >> 2;
|
||||
++_jitc->function->call.argi;
|
||||
if (offset < 4)
|
||||
jit_movi(_A0 - offset, u);
|
||||
else {
|
||||
regno = jit_get_reg(jit_class_gpr);
|
||||
jit_movi(regno, u);
|
||||
jit_stxi(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_stxi(_jitc->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -448,19 +448,19 @@ _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
|
|||
{
|
||||
jit_word_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
offset = _jit->function->call.size >> 2;
|
||||
if (offset < 2 && !_jit->function->call.argi) {
|
||||
++_jit->function->call.argf;
|
||||
assert(_jitc->function);
|
||||
offset = _jitc->function->call.size >> 2;
|
||||
if (offset < 2 && !_jitc->function->call.argi) {
|
||||
++_jitc->function->call.argf;
|
||||
jit_movr_f(_F12 - offset, u);
|
||||
}
|
||||
else if (offset < 4) {
|
||||
++_jit->function->call.argi;
|
||||
++_jitc->function->call.argi;
|
||||
jit_movr_f_w(_A0 - offset, u);
|
||||
}
|
||||
else
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
jit_stxi_f(_jitc->function->call.size, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -469,23 +469,23 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
jit_int32_t regno;
|
||||
jit_word_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
offset = _jit->function->call.size >> 2;
|
||||
if (offset < 2 && !_jit->function->call.argi) {
|
||||
++_jit->function->call.argf;
|
||||
assert(_jitc->function);
|
||||
offset = _jitc->function->call.size >> 2;
|
||||
if (offset < 2 && !_jitc->function->call.argi) {
|
||||
++_jitc->function->call.argf;
|
||||
jit_movi_f(_F12 - offset, u);
|
||||
}
|
||||
else if (offset < 4) {
|
||||
++_jit->function->call.argi;
|
||||
++_jitc->function->call.argi;
|
||||
jit_movi_f_w(_A0 - offset, u);
|
||||
}
|
||||
else {
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_stxi_f(_jitc->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -494,26 +494,26 @@ _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
|||
jit_bool_t adjust;
|
||||
jit_word_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
adjust = !!_jit->function->call.argi;
|
||||
if (_jit->function->call.size & 7) {
|
||||
_jit->function->call.size += 4;
|
||||
assert(_jitc->function);
|
||||
adjust = !!_jitc->function->call.argi;
|
||||
if (_jitc->function->call.size & 7) {
|
||||
_jitc->function->call.size += 4;
|
||||
adjust = 1;
|
||||
}
|
||||
offset = _jit->function->call.size >> 2;
|
||||
offset = _jitc->function->call.size >> 2;
|
||||
if (offset < 3) {
|
||||
if (adjust) {
|
||||
jit_movr_d_ww(_A0 - offset, _A0 - (offset + 1), u);
|
||||
_jit->function->call.argi += 2;
|
||||
_jitc->function->call.argi += 2;
|
||||
}
|
||||
else {
|
||||
jit_movr_d(_F12 - (offset >> 1), u);
|
||||
++_jit->function->call.argf;
|
||||
++_jitc->function->call.argf;
|
||||
}
|
||||
}
|
||||
else
|
||||
jit_stxi_d(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -523,30 +523,30 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
|
|||
jit_bool_t adjust;
|
||||
jit_word_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
adjust = !!_jit->function->call.argi;
|
||||
if (_jit->function->call.size & 7) {
|
||||
_jit->function->call.size += 4;
|
||||
assert(_jitc->function);
|
||||
adjust = !!_jitc->function->call.argi;
|
||||
if (_jitc->function->call.size & 7) {
|
||||
_jitc->function->call.size += 4;
|
||||
adjust = 1;
|
||||
}
|
||||
offset = _jit->function->call.size >> 2;
|
||||
offset = _jitc->function->call.size >> 2;
|
||||
if (offset < 3) {
|
||||
if (adjust) {
|
||||
jit_movi_d_ww(_A0 - offset, _A0 - (offset + 1), u);
|
||||
_jit->function->call.argi += 2;
|
||||
_jitc->function->call.argi += 2;
|
||||
}
|
||||
else {
|
||||
jit_movi_d(_F12 - (offset >> 1), u);
|
||||
++_jit->function->call.argf;
|
||||
++_jitc->function->call.argf;
|
||||
}
|
||||
}
|
||||
else {
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_d(regno, u);
|
||||
jit_stxi_d(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_stxi_d(_jitc->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
|
||||
jit_bool_t
|
||||
|
@ -576,16 +576,16 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
|
|||
{
|
||||
jit_node_t *call;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
jit_movr(_T9, r0);
|
||||
call = jit_callr(_T9);
|
||||
call->v.w = _jit->function->self.argi;
|
||||
call->w.w = _jit->function->self.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
call->v.w = _jitc->function->self.argi;
|
||||
call->w.w = _jitc->function->self.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -594,16 +594,16 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
|
|||
jit_node_t *call;
|
||||
jit_node_t *node;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
node = jit_movi(_T9, (jit_word_t)i0);
|
||||
call = jit_callr(_T9);
|
||||
call->v.w = _jit->function->call.argi;
|
||||
call->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
call->v.w = _jitc->function->call.argi;
|
||||
call->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
return (node);
|
||||
}
|
||||
|
||||
|
@ -685,7 +685,7 @@ _emit_code(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
|
||||
jit_reglive_setup();
|
||||
|
||||
|
@ -775,8 +775,8 @@ _emit_code(jit_state_t *_jit)
|
|||
patch(word, node); \
|
||||
} \
|
||||
break
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jit->code.end)
|
||||
for (node = _jitc->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jitc->code.end)
|
||||
return (NULL);
|
||||
|
||||
value = jit_classify(node->code);
|
||||
|
@ -1169,17 +1169,17 @@ _emit_code(jit_state_t *_jit)
|
|||
calli(node->u.w);
|
||||
break;
|
||||
case jit_code_prolog:
|
||||
_jit->function = _jit->functions.ptr + node->w.w;
|
||||
_jitc->function = _jitc->functions.ptr + node->w.w;
|
||||
undo.node = node;
|
||||
undo.word = _jit->pc.w;
|
||||
undo.patch_offset = _jit->patches.offset;
|
||||
undo.patch_offset = _jitc->patches.offset;
|
||||
restart_function:
|
||||
_jit->again = 0;
|
||||
_jitc->again = 0;
|
||||
prolog(node);
|
||||
break;
|
||||
case jit_code_epilog:
|
||||
assert(_jit->function == _jit->functions.ptr + node->w.w);
|
||||
if (_jit->again) {
|
||||
assert(_jitc->function == _jitc->functions.ptr + node->w.w);
|
||||
if (_jitc->again) {
|
||||
for (temp = undo.node->next;
|
||||
temp != node; temp = temp->next) {
|
||||
if (temp->code == jit_code_label ||
|
||||
|
@ -1188,14 +1188,14 @@ _emit_code(jit_state_t *_jit)
|
|||
}
|
||||
node = undo.node;
|
||||
_jit->pc.w = undo.word;
|
||||
_jit->patches.offset = undo.patch_offset;
|
||||
_jitc->patches.offset = undo.patch_offset;
|
||||
goto restart_function;
|
||||
}
|
||||
/* remember label is defined */
|
||||
node->flag |= jit_flag_patch;
|
||||
node->u.w = _jit->pc.w;
|
||||
epilog(node);
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
break;
|
||||
case jit_code_movr_w_f:
|
||||
movr_w_f(rn(node->u.w), rn(node->v.w));
|
||||
|
@ -1254,10 +1254,10 @@ _emit_code(jit_state_t *_jit)
|
|||
#undef case_rw
|
||||
#undef case_rr
|
||||
|
||||
for (offset = 0; offset < _jit->patches.offset; offset++) {
|
||||
node = _jit->patches.ptr[offset].node;
|
||||
for (offset = 0; offset < _jitc->patches.offset; offset++) {
|
||||
node = _jitc->patches.ptr[offset].node;
|
||||
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
|
||||
patch_at(_jit->patches.ptr[offset].inst, word);
|
||||
patch_at(_jitc->patches.ptr[offset].inst, word);
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
|
@ -1315,15 +1315,15 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
|
|||
else
|
||||
flag = node->u.n->flag;
|
||||
assert(!(flag & jit_flag_patch));
|
||||
if (_jit->patches.offset >= _jit->patches.length) {
|
||||
_jit->patches.ptr = realloc(_jit->patches.ptr,
|
||||
(_jit->patches.length + 1024) *
|
||||
if (_jitc->patches.offset >= _jitc->patches.length) {
|
||||
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
|
||||
(_jitc->patches.length + 1024) *
|
||||
sizeof(jit_patch_t));
|
||||
memset(_jit->patches.ptr + _jit->patches.length, 0,
|
||||
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
|
||||
1024 * sizeof(jit_patch_t));
|
||||
_jit->patches.length += 1024;
|
||||
_jitc->patches.length += 1024;
|
||||
}
|
||||
_jit->patches.ptr[_jit->patches.offset].inst = instr;
|
||||
_jit->patches.ptr[_jit->patches.offset].node = node;
|
||||
++_jit->patches.offset;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].inst = instr;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].node = node;
|
||||
++_jitc->patches.offset;
|
||||
}
|
||||
|
|
|
@ -54,17 +54,17 @@ _jit_name(jit_state_t *_jit, char *name)
|
|||
node->v.n = jit_data(name, strlen(name) + 1, 1);
|
||||
else
|
||||
node->v.p = NULL;
|
||||
if (_jit->note.head == NULL)
|
||||
_jit->note.head = _jit->note.tail = node;
|
||||
if (_jitc->note.head == NULL)
|
||||
_jitc->note.head = _jitc->note.tail = node;
|
||||
else {
|
||||
_jit->note.tail->link = node;
|
||||
_jit->note.tail = node;
|
||||
_jitc->note.tail->link = node;
|
||||
_jitc->note.tail = node;
|
||||
}
|
||||
++_jit->note.length;
|
||||
_jit->note.size += sizeof(jit_note_t);
|
||||
_jitc->note.size += sizeof(jit_note_t);
|
||||
/* remember previous note is invalid due to name change */
|
||||
_jit->note.note = NULL;
|
||||
return (_jit->note.name = node);
|
||||
_jitc->note.note = NULL;
|
||||
return (_jitc->note.name = node);
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -78,20 +78,20 @@ _jit_note(jit_state_t *_jit, char *name, int line)
|
|||
else
|
||||
node->v.p = NULL;
|
||||
node->w.w = line;
|
||||
if (_jit->note.head == NULL)
|
||||
_jit->note.head = _jit->note.tail = node;
|
||||
if (_jitc->note.head == NULL)
|
||||
_jitc->note.head = _jitc->note.tail = node;
|
||||
else {
|
||||
_jit->note.tail->link = node;
|
||||
_jit->note.tail = node;
|
||||
_jitc->note.tail->link = node;
|
||||
_jitc->note.tail = node;
|
||||
}
|
||||
if (_jit->note.note == NULL ||
|
||||
(name == NULL && _jit->note.note != NULL) ||
|
||||
(name != NULL && _jit->note.note == NULL) ||
|
||||
(name != NULL && _jit->note.note != NULL &&
|
||||
strcmp(name, (char *)_jit->data.ptr + _jit->note.note->v.n->u.w)))
|
||||
_jit->note.size += sizeof(jit_line_t);
|
||||
_jit->note.size += sizeof(jit_int32_t) * 2;
|
||||
return (_jit->note.note = node);
|
||||
if (_jitc->note.note == NULL ||
|
||||
(name == NULL && _jitc->note.note != NULL) ||
|
||||
(name != NULL && _jitc->note.note == NULL) ||
|
||||
(name != NULL && _jitc->note.note != NULL &&
|
||||
strcmp(name, (char *)_jit->data.ptr + _jitc->note.note->v.n->u.w)))
|
||||
_jitc->note.size += sizeof(jit_line_t);
|
||||
_jitc->note.size += sizeof(jit_int32_t) * 2;
|
||||
return (_jitc->note.note = node);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -105,11 +105,11 @@ _jit_annotate(jit_state_t *_jit)
|
|||
jit_word_t line_offset;
|
||||
|
||||
/* initialize pointers in mmaped data area */
|
||||
_jit->note.ptr = (jit_note_t *)_jit->note.base;
|
||||
_jit->note.ptr = (jit_note_t *)_jitc->note.base;
|
||||
_jit->note.length = 0;
|
||||
|
||||
note = NULL;
|
||||
for (node = _jit->note.head; node; node = node->link) {
|
||||
for (node = _jitc->note.head; node; node = node->link) {
|
||||
if (node->code == jit_code_name)
|
||||
note = new_note(node->u.p, node->v.p ? node->v.n->u.p : NULL);
|
||||
else if (node->v.p) {
|
||||
|
@ -132,11 +132,11 @@ _jit_annotate(jit_state_t *_jit)
|
|||
for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
|
||||
note = _jit->note.ptr + note_offset;
|
||||
length = sizeof(jit_line_t) * note->length;
|
||||
assert(_jit->note.base + length < _jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jit->note.base, note->lines, length);
|
||||
assert(_jitc->note.base + length < _jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, note->lines, length);
|
||||
free(note->lines);
|
||||
note->lines = (jit_line_t *)_jit->note.base;
|
||||
_jit->note.base += length;
|
||||
note->lines = (jit_line_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
}
|
||||
|
||||
/* relocate offset and line number information */
|
||||
|
@ -145,18 +145,18 @@ _jit_annotate(jit_state_t *_jit)
|
|||
for (line_offset = 0; line_offset < note->length; line_offset++) {
|
||||
line = note->lines + line_offset;
|
||||
length = sizeof(jit_int32_t) * line->length;
|
||||
assert(_jit->note.base + length <
|
||||
assert(_jitc->note.base + length <
|
||||
_jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jit->note.base, line->linenos, length);
|
||||
memcpy(_jitc->note.base, line->linenos, length);
|
||||
free(line->linenos);
|
||||
line->linenos = (jit_int32_t *)_jit->note.base;
|
||||
_jit->note.base += length;
|
||||
assert(_jit->note.base + length <
|
||||
line->linenos = (jit_int32_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
assert(_jitc->note.base + length <
|
||||
_jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jit->note.base, line->offsets, length);
|
||||
memcpy(_jitc->note.base, line->offsets, length);
|
||||
free(line->offsets);
|
||||
line->offsets = (jit_int32_t *)_jit->note.base;
|
||||
_jit->note.base += length;
|
||||
line->offsets = (jit_int32_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,8 +252,8 @@ _new_note(jit_state_t *_jit, jit_uint8_t *code, char *name)
|
|||
assert(code >= prev->code);
|
||||
prev->size = code - prev->code;
|
||||
}
|
||||
note = (jit_note_t *)_jit->note.base;
|
||||
_jit->note.base += sizeof(jit_note_t);
|
||||
note = (jit_note_t *)_jitc->note.base;
|
||||
_jitc->note.base += sizeof(jit_note_t);
|
||||
++_jit->note.length;
|
||||
note->code = code;
|
||||
note->name = name;
|
||||
|
|
|
@ -2471,20 +2471,20 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
|
|||
unsigned long regno;
|
||||
jit_word_t offset;
|
||||
|
||||
_jit->function->stack = ((_jit->function->self.alen +
|
||||
_jit->function->self.size -
|
||||
_jit->function->self.aoff) + 15) & -16;
|
||||
_jitc->function->stack = ((_jitc->function->self.alen +
|
||||
_jitc->function->self.size -
|
||||
_jitc->function->self.aoff) + 15) & -16;
|
||||
|
||||
/* return address */
|
||||
MFLR(_R0_REGNO);
|
||||
|
||||
/* save any clobbered callee save gpr register */
|
||||
regno = jit_regset_scan1(_jit->function->regset, _R14);
|
||||
regno = jit_regset_scan1(_jitc->function->regset, _R14);
|
||||
if (regno == ULONG_MAX || regno > _R31)
|
||||
regno = _R31; /* aka _FP_REGNO */
|
||||
STMW(rn(regno), _SP_REGNO, -fpr_save_area - (32 * 4) + rn(regno) * 4);
|
||||
for (offset = 0; offset < 8; offset++) {
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F14 + offset))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F14 + offset))
|
||||
stxi_d(-fpr_save_area + offset * 8, _SP_REGNO, rn(_F14 + offset));
|
||||
}
|
||||
|
||||
|
@ -2494,7 +2494,7 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
|
|||
* alloca < %r31-80 */
|
||||
movr(_FP_REGNO, _SP_REGNO);
|
||||
|
||||
STWU(_SP_REGNO, _SP_REGNO, -_jit->function->stack);
|
||||
STWU(_SP_REGNO, _SP_REGNO, -_jitc->function->stack);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2508,12 +2508,12 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
|
|||
|
||||
MTLR(_R0_REGNO);
|
||||
|
||||
regno = jit_regset_scan1(_jit->function->regset, _R14);
|
||||
regno = jit_regset_scan1(_jitc->function->regset, _R14);
|
||||
if (regno == ULONG_MAX || regno > _R31)
|
||||
regno = _R31; /* aka _FP_REGNO */
|
||||
LMW(rn(regno), _SP_REGNO, -fpr_save_area - (32 * 4) + rn(regno) * 4);
|
||||
for (offset = 0; offset < 8; offset++) {
|
||||
if (jit_regset_tstbit(_jit->function->regset, _F14 + offset))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _F14 + offset))
|
||||
ldxi_d(rn(_F14 + offset), _SP_REGNO, -fpr_save_area + offset * 8);
|
||||
}
|
||||
BLR();
|
||||
|
|
314
lib/jit_ppc.c
314
lib/jit_ppc.c
|
@ -114,7 +114,7 @@ jit_get_cpu(void)
|
|||
void
|
||||
_jit_init(jit_state_t *_jit)
|
||||
{
|
||||
_jit->reglen = jit_size(_rvs) - 1;
|
||||
_jitc->reglen = jit_size(_rvs) - 1;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,53 +122,53 @@ _jit_prolog(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
if (_jit->function)
|
||||
if (_jitc->function)
|
||||
jit_epilog();
|
||||
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jit->regsav, 0);
|
||||
offset = _jit->functions.offset;
|
||||
if (offset >= _jit->functions.length) {
|
||||
_jit->functions.ptr = realloc(_jit->functions.ptr,
|
||||
(_jit->functions.length + 16) *
|
||||
assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jitc->regsav, 0);
|
||||
offset = _jitc->functions.offset;
|
||||
if (offset >= _jitc->functions.length) {
|
||||
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
|
||||
(_jitc->functions.length + 16) *
|
||||
sizeof(jit_function_t));
|
||||
memset(_jit->functions.ptr + _jit->functions.length, 0,
|
||||
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
|
||||
16 * sizeof(jit_function_t));
|
||||
_jit->functions.length += 16;
|
||||
_jitc->functions.length += 16;
|
||||
}
|
||||
_jit->function = _jit->functions.ptr + _jit->functions.offset++;
|
||||
_jit->function->self.size = params_offset;
|
||||
_jit->function->self.argi = _jit->function->self.argf =
|
||||
_jit->function->self.alen = 0;
|
||||
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
|
||||
_jitc->function->self.size = params_offset;
|
||||
_jitc->function->self.argi = _jitc->function->self.argf =
|
||||
_jitc->function->self.alen = 0;
|
||||
/* float conversion */
|
||||
_jit->function->self.aoff = alloca_offset - 8;
|
||||
_jit->function->self.call = jit_call_default;
|
||||
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t));
|
||||
_jitc->function->self.aoff = alloca_offset - 8;
|
||||
_jitc->function->self.call = jit_call_default;
|
||||
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
|
||||
|
||||
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jit->function->prolog);
|
||||
_jit->function->prolog->w.w = offset;
|
||||
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jitc->function->prolog);
|
||||
_jitc->function->prolog->w.w = offset;
|
||||
_jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
/* u: label value
|
||||
* v: offset in blocks vector
|
||||
* w: offset in functions vector
|
||||
*/
|
||||
_jit->function->epilog->w.w = offset;
|
||||
_jitc->function->epilog->w.w = offset;
|
||||
|
||||
jit_regset_new(_jit->function->regset);
|
||||
jit_regset_new(_jitc->function->regset);
|
||||
}
|
||||
|
||||
jit_int32_t
|
||||
_jit_allocai(jit_state_t *_jit, jit_int32_t length)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
switch (length) {
|
||||
case 0: case 1: break;
|
||||
case 2: _jit->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jit->function->self.aoff &= -4; break;
|
||||
default: _jit->function->self.aoff &= -8; break;
|
||||
case 2: _jitc->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jitc->function->self.aoff &= -4; break;
|
||||
default: _jitc->function->self.aoff &= -8; break;
|
||||
}
|
||||
_jit->function->self.aoff -= length;
|
||||
return (_jit->function->self.aoff);
|
||||
_jitc->function->self.aoff -= length;
|
||||
return (_jitc->function->self.aoff);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -176,11 +176,11 @@ _jit_ret(jit_state_t *_jit)
|
|||
{
|
||||
jit_node_t *instr;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
|
||||
/* jump to epilog */
|
||||
instr = jit_jmpi();
|
||||
jit_patch_at(instr, _jit->function->epilog);
|
||||
jit_patch_at(instr, _jitc->function->epilog);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -238,22 +238,22 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
|
|||
void
|
||||
_jit_epilog(jit_state_t *_jit)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jit->function->epilog->next == NULL);
|
||||
jit_link(_jit->function->epilog);
|
||||
_jit->function = NULL;
|
||||
assert(_jitc->function);
|
||||
assert(_jitc->function->epilog->next == NULL);
|
||||
jit_link(_jitc->function->epilog);
|
||||
_jitc->function = NULL;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
_jit_arg(jit_state_t *_jit)
|
||||
{
|
||||
jit_int32_t offset;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi < 8)
|
||||
offset = _jit->function->self.argi++;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argi < 8)
|
||||
offset = _jitc->function->self.argi++;
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_word_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_word_t);
|
||||
return (jit_new_node_w(jit_code_arg, offset));
|
||||
}
|
||||
|
||||
|
@ -267,12 +267,12 @@ jit_node_t *
|
|||
_jit_arg_f(jit_state_t *_jit)
|
||||
{
|
||||
jit_int32_t offset;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argf < 13)
|
||||
offset = _jit->function->self.argf++;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argf < 13)
|
||||
offset = _jitc->function->self.argf++;
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float32_t);
|
||||
return (jit_new_node_w(jit_code_arg_f, offset));
|
||||
}
|
||||
|
||||
|
@ -286,12 +286,12 @@ jit_node_t *
|
|||
_jit_arg_d(jit_state_t *_jit)
|
||||
{
|
||||
jit_int32_t offset;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argf < 13)
|
||||
offset = _jit->function->self.argf++;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argf < 13)
|
||||
offset = _jitc->function->self.argf++;
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float64_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float64_t);
|
||||
return (jit_new_node_w(jit_code_arg_d, offset));
|
||||
}
|
||||
|
||||
|
@ -423,62 +423,62 @@ _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
|||
void
|
||||
_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argi < 8) {
|
||||
jit_movr(JIT_RA0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argi < 8) {
|
||||
jit_movr(JIT_RA0 - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else
|
||||
jit_stxi(_jit->function->call.size + params_offset, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
||||
{
|
||||
jit_int32_t regno;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argi < 8) {
|
||||
jit_movi(JIT_RA0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argi < 8) {
|
||||
jit_movi(JIT_RA0 - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
regno = jit_get_reg(jit_class_gpr);
|
||||
jit_movi(regno, u);
|
||||
jit_stxi(_jit->function->call.size + params_offset, JIT_SP, regno);
|
||||
jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 13) {
|
||||
jit_movr_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (!(_jit->function->call.call & jit_call_varargs)) {
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argf < 13) {
|
||||
jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
if (!(_jitc->function->call.call & jit_call_varargs)) {
|
||||
/* in case of excess arguments */
|
||||
if (_jit->function->call.argi < 8)
|
||||
_jit->function->call.argi += 2;
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
if (_jitc->function->call.argi < 8)
|
||||
_jitc->function->call.argi += 2;
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_jit->function->call.argi < 8) {
|
||||
if (_jitc->function->call.argi < 8) {
|
||||
/* use reserved 8 bytes area */
|
||||
jit_stxi_d(alloca_offset - 8, JIT_FP, u);
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 8);
|
||||
_jit->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
_jitc->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 4);
|
||||
_jit->function->call.argi++;
|
||||
_jitc->function->call.argi++;
|
||||
}
|
||||
else
|
||||
jit_stxi_f(_jit->function->call.size + params_offset, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -486,64 +486,64 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 13) {
|
||||
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (!(_jit->function->call.call & jit_call_varargs)) {
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argf < 13) {
|
||||
jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
if (!(_jitc->function->call.call & jit_call_varargs)) {
|
||||
/* in case of excess arguments */
|
||||
if (_jit->function->call.argi < 8)
|
||||
_jit->function->call.argi += 2;
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
if (_jitc->function->call.argi < 8)
|
||||
_jitc->function->call.argi += 2;
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
if (_jit->function->call.argi < 8) {
|
||||
if (_jitc->function->call.argi < 8) {
|
||||
/* use reserved 8 bytes area */
|
||||
jit_stxi_d(alloca_offset - 8, JIT_FP, regno);
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 8);
|
||||
_jit->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
_jitc->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 4);
|
||||
_jit->function->call.argi++;
|
||||
_jitc->function->call.argi++;
|
||||
}
|
||||
else
|
||||
jit_stxi_f(_jit->function->call.size + params_offset, JIT_SP, regno);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 13) {
|
||||
jit_movr_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (!(_jit->function->call.call & jit_call_varargs)) {
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argf < 13) {
|
||||
jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
if (!(_jitc->function->call.call & jit_call_varargs)) {
|
||||
/* in case of excess arguments */
|
||||
if (_jit->function->call.argi < 8)
|
||||
_jit->function->call.argi += 2;
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
if (_jitc->function->call.argi < 8)
|
||||
_jitc->function->call.argi += 2;
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_jit->function->call.argi < 8) {
|
||||
if (_jitc->function->call.argi < 8) {
|
||||
/* use reserved 8 bytes area */
|
||||
jit_stxi_d(alloca_offset - 8, JIT_FP, u);
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 8);
|
||||
_jit->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
_jitc->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 4);
|
||||
_jit->function->call.argi++;
|
||||
_jitc->function->call.argi++;
|
||||
}
|
||||
else
|
||||
jit_stxi_d(_jit->function->call.size + params_offset, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -551,33 +551,33 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 13) {
|
||||
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (!(_jit->function->call.call & jit_call_varargs)) {
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->call.argf < 13) {
|
||||
jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
if (!(_jitc->function->call.call & jit_call_varargs)) {
|
||||
/* in case of excess arguments */
|
||||
if (_jit->function->call.argi < 8)
|
||||
_jit->function->call.argi += 2;
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
if (_jitc->function->call.argi < 8)
|
||||
_jitc->function->call.argi += 2;
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_d(regno, u);
|
||||
if (_jit->function->call.argi < 8) {
|
||||
if (_jitc->function->call.argi < 8) {
|
||||
/* use reserved 8 bytes area */
|
||||
jit_stxi_d(alloca_offset - 8, JIT_FP, regno);
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 8);
|
||||
_jit->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP,
|
||||
_jitc->function->call.argi++;
|
||||
jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
|
||||
alloca_offset - 4);
|
||||
_jit->function->call.argi++;
|
||||
_jitc->function->call.argi++;
|
||||
}
|
||||
else
|
||||
jit_stxi_d(_jit->function->call.size + params_offset, JIT_SP, regno);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
|
||||
|
@ -605,28 +605,28 @@ void
|
|||
_jit_finishr(jit_state_t *_jit, jit_int32_t r0)
|
||||
{
|
||||
jit_node_t *call;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
call = jit_callr(r0);
|
||||
call->v.w = _jit->function->call.argi;
|
||||
call->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf = 0;
|
||||
_jit->prepare = 0;
|
||||
call->v.w = _jitc->function->call.argi;
|
||||
call->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf = 0;
|
||||
_jitc->prepare = 0;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
_jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
|
||||
{
|
||||
jit_node_t *node;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
node = jit_calli(i0);
|
||||
node->v.w = _jit->function->call.argi;
|
||||
node->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf = 0;
|
||||
_jit->prepare = 0;
|
||||
node->v.w = _jitc->function->call.argi;
|
||||
node->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf = 0;
|
||||
_jitc->prepare = 0;
|
||||
return (node);
|
||||
}
|
||||
|
||||
|
@ -707,7 +707,7 @@ _emit_code(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
|
||||
jit_reglive_setup();
|
||||
|
||||
|
@ -798,8 +798,8 @@ _emit_code(jit_state_t *_jit)
|
|||
patch(word, node); \
|
||||
} \
|
||||
break
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jit->code.end)
|
||||
for (node = _jitc->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jitc->code.end)
|
||||
return (NULL);
|
||||
|
||||
value = jit_classify(node->code);
|
||||
|
@ -1169,17 +1169,17 @@ _emit_code(jit_state_t *_jit)
|
|||
calli(node->u.w);
|
||||
break;
|
||||
case jit_code_prolog:
|
||||
_jit->function = _jit->functions.ptr + node->w.w;
|
||||
_jitc->function = _jitc->functions.ptr + node->w.w;
|
||||
undo.node = node;
|
||||
undo.word = _jit->pc.w;
|
||||
undo.patch_offset = _jit->patches.offset;
|
||||
undo.patch_offset = _jitc->patches.offset;
|
||||
restart_function:
|
||||
_jit->again = 0;
|
||||
_jitc->again = 0;
|
||||
prolog(node);
|
||||
break;
|
||||
case jit_code_epilog:
|
||||
assert(_jit->function == _jit->functions.ptr + node->w.w);
|
||||
if (_jit->again) {
|
||||
assert(_jitc->function == _jitc->functions.ptr + node->w.w);
|
||||
if (_jitc->again) {
|
||||
for (temp = undo.node->next;
|
||||
temp != node; temp = temp->next) {
|
||||
if (temp->code == jit_code_label ||
|
||||
|
@ -1188,14 +1188,14 @@ _emit_code(jit_state_t *_jit)
|
|||
}
|
||||
node = undo.node;
|
||||
_jit->pc.w = undo.word;
|
||||
_jit->patches.offset = undo.patch_offset;
|
||||
_jitc->patches.offset = undo.patch_offset;
|
||||
goto restart_function;
|
||||
}
|
||||
/* remember label is defined */
|
||||
node->flag |= jit_flag_patch;
|
||||
node->u.w = _jit->pc.w;
|
||||
epilog(node);
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
break;
|
||||
case jit_code_live:
|
||||
case jit_code_arg:
|
||||
|
@ -1219,10 +1219,10 @@ _emit_code(jit_state_t *_jit)
|
|||
#undef case_rw
|
||||
#undef case_rr
|
||||
|
||||
for (offset = 0; offset < _jit->patches.offset; offset++) {
|
||||
node = _jit->patches.ptr[offset].node;
|
||||
for (offset = 0; offset < _jitc->patches.offset; offset++) {
|
||||
node = _jitc->patches.ptr[offset].node;
|
||||
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
|
||||
patch_at(_jit->patches.ptr[offset].inst, word);
|
||||
patch_at(_jitc->patches.ptr[offset].inst, word);
|
||||
}
|
||||
|
||||
__clear_cache(_jit->code.ptr, _jit->pc.uc);
|
||||
|
@ -1279,15 +1279,15 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
|
|||
else
|
||||
flag = node->u.n->flag;
|
||||
assert(!(flag & jit_flag_patch));
|
||||
if (_jit->patches.offset >= _jit->patches.length) {
|
||||
_jit->patches.ptr = realloc(_jit->patches.ptr,
|
||||
(_jit->patches.length + 1024) *
|
||||
if (_jitc->patches.offset >= _jitc->patches.length) {
|
||||
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
|
||||
(_jitc->patches.length + 1024) *
|
||||
sizeof(jit_patch_t));
|
||||
memset(_jit->patches.ptr + _jit->patches.length, 0,
|
||||
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
|
||||
1024 * sizeof(jit_patch_t));
|
||||
_jit->patches.length += 1024;
|
||||
_jitc->patches.length += 1024;
|
||||
}
|
||||
_jit->patches.ptr[_jit->patches.offset].inst = instr;
|
||||
_jit->patches.ptr[_jit->patches.offset].node = node;
|
||||
++_jit->patches.offset;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].inst = instr;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].node = node;
|
||||
++_jitc->patches.offset;
|
||||
}
|
||||
|
|
|
@ -227,7 +227,7 @@ _jit_print(jit_state_t *_jit)
|
|||
jit_int32_t offset;
|
||||
|
||||
first = 0;
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
for (node = _jitc->head; node; node = node->next) {
|
||||
if (!first)
|
||||
print_chr('\n');
|
||||
else
|
||||
|
@ -237,8 +237,8 @@ _jit_print(jit_state_t *_jit)
|
|||
print_chr('L');
|
||||
print_dec(node->v.w);
|
||||
print_chr(':');
|
||||
block = _jit->blocks.ptr + node->v.w;
|
||||
for (offset = 0; offset < _jit->reglen; offset++) {
|
||||
block = _jitc->blocks.ptr + node->v.w;
|
||||
for (offset = 0; offset < _jitc->reglen; offset++) {
|
||||
if (jit_regset_tstbit(block->reglive, offset)) {
|
||||
print_chr(' ');
|
||||
print_reg(offset);
|
||||
|
|
|
@ -1619,28 +1619,28 @@ static void
|
|||
_prolog(jit_state_t *_jit, jit_node_t *node)
|
||||
{
|
||||
/* align at 16 bytes boundary */
|
||||
_jit->function->stack = ((stack_framesize +
|
||||
_jit->function->self.alen -
|
||||
_jit->function->self.aoff) + 15) & -16;
|
||||
SAVEI(_SP_REGNO, -_jit->function->stack, _SP_REGNO);
|
||||
_jitc->function->stack = ((stack_framesize +
|
||||
_jitc->function->self.alen -
|
||||
_jitc->function->self.aoff) + 15) & -16;
|
||||
SAVEI(_SP_REGNO, -_jitc->function->stack, _SP_REGNO);
|
||||
|
||||
/* (most) other backends do not save incoming arguments, so,
|
||||
* only save locals here */
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L0))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L0))
|
||||
stxi(0, _SP_REGNO, _L0_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L1))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L1))
|
||||
stxi(4, _SP_REGNO, _L1_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L2))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L2))
|
||||
stxi(8, _SP_REGNO, _L2_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L3))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L3))
|
||||
stxi(12, _SP_REGNO, _L3_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L4))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L4))
|
||||
stxi(16, _SP_REGNO, _L4_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L5))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L5))
|
||||
stxi(20, _SP_REGNO, _L5_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L6))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L6))
|
||||
stxi(24, _SP_REGNO, _L6_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L7))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L7))
|
||||
stxi(28, _SP_REGNO, _L7_REGNO);
|
||||
}
|
||||
|
||||
|
@ -1649,21 +1649,21 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
|
|||
{
|
||||
/* (most) other backends do not save incoming arguments, so,
|
||||
* only save locals here */
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L0))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L0))
|
||||
ldxi(_L0_REGNO, _SP_REGNO, 0);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L1))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L1))
|
||||
ldxi(_L1_REGNO, _SP_REGNO, 4);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L2))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L2))
|
||||
ldxi(_L2_REGNO, _SP_REGNO, 8);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L3))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L3))
|
||||
ldxi(_L3_REGNO, _SP_REGNO, 12);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L4))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L4))
|
||||
ldxi(_L4_REGNO, _SP_REGNO, 16);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L5))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L5))
|
||||
ldxi(_L5_REGNO, _SP_REGNO, 20);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L6))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L6))
|
||||
ldxi(_L6_REGNO, _SP_REGNO, 24);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _L7))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _L7))
|
||||
ldxi(_L7_REGNO, _SP_REGNO, 28);
|
||||
RESTOREI(0, 0, 0);
|
||||
RETL();
|
||||
|
|
266
lib/jit_sparc.c
266
lib/jit_sparc.c
|
@ -95,7 +95,7 @@ jit_get_cpu(void)
|
|||
void
|
||||
_jit_init(jit_state_t *_jit)
|
||||
{
|
||||
_jit->reglen = jit_size(_rvs) - 1;
|
||||
_jitc->reglen = jit_size(_rvs) - 1;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -103,53 +103,53 @@ _jit_prolog(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
if (_jit->function)
|
||||
if (_jitc->function)
|
||||
jit_epilog();
|
||||
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jit->regsav, 0);
|
||||
offset = _jit->functions.offset;
|
||||
if (offset >= _jit->functions.length) {
|
||||
_jit->functions.ptr = realloc(_jit->functions.ptr,
|
||||
(_jit->functions.length + 16) *
|
||||
assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jitc->regsav, 0);
|
||||
offset = _jitc->functions.offset;
|
||||
if (offset >= _jitc->functions.length) {
|
||||
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
|
||||
(_jitc->functions.length + 16) *
|
||||
sizeof(jit_function_t));
|
||||
memset(_jit->functions.ptr + _jit->functions.length, 0,
|
||||
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
|
||||
16 * sizeof(jit_function_t));
|
||||
_jit->functions.length += 16;
|
||||
_jitc->functions.length += 16;
|
||||
}
|
||||
_jit->function = _jit->functions.ptr + _jit->functions.offset++;
|
||||
_jit->function->self.size = stack_framesize;
|
||||
_jit->function->self.argi = _jit->function->self.argf =
|
||||
_jit->function->self.aoff = _jit->function->self.alen = 0;
|
||||
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
|
||||
_jitc->function->self.size = stack_framesize;
|
||||
_jitc->function->self.argi = _jitc->function->self.argf =
|
||||
_jitc->function->self.aoff = _jitc->function->self.alen = 0;
|
||||
/* float conversion */
|
||||
_jit->function->self.aoff = -8;
|
||||
_jit->function->self.call = jit_call_default;
|
||||
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t));
|
||||
_jitc->function->self.aoff = -8;
|
||||
_jitc->function->self.call = jit_call_default;
|
||||
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
|
||||
|
||||
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jit->function->prolog);
|
||||
_jit->function->prolog->w.w = offset;
|
||||
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jitc->function->prolog);
|
||||
_jitc->function->prolog->w.w = offset;
|
||||
_jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
/* u: label value
|
||||
* v: offset in blocks vector
|
||||
* w: offset in functions vector
|
||||
*/
|
||||
_jit->function->epilog->w.w = offset;
|
||||
_jitc->function->epilog->w.w = offset;
|
||||
|
||||
jit_regset_new(_jit->function->regset);
|
||||
jit_regset_new(_jitc->function->regset);
|
||||
}
|
||||
|
||||
jit_int32_t
|
||||
_jit_allocai(jit_state_t *_jit, jit_int32_t length)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
switch (length) {
|
||||
case 0: case 1: break;
|
||||
case 2: _jit->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jit->function->self.aoff &= -4; break;
|
||||
default: _jit->function->self.aoff &= -8; break;
|
||||
case 2: _jitc->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jitc->function->self.aoff &= -4; break;
|
||||
default: _jitc->function->self.aoff &= -8; break;
|
||||
}
|
||||
_jit->function->self.aoff -= length;
|
||||
return (_jit->function->self.aoff);
|
||||
_jitc->function->self.aoff -= length;
|
||||
return (_jitc->function->self.aoff);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -157,11 +157,11 @@ _jit_ret(jit_state_t *_jit)
|
|||
{
|
||||
jit_node_t *instr;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
|
||||
/* jump to epilog */
|
||||
instr = jit_jmpi();
|
||||
jit_patch_at(instr, _jit->function->epilog);
|
||||
jit_patch_at(instr, _jitc->function->epilog);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -218,22 +218,22 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
|
|||
void
|
||||
_jit_epilog(jit_state_t *_jit)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jit->function->epilog->next == NULL);
|
||||
jit_link(_jit->function->epilog);
|
||||
_jit->function = NULL;
|
||||
assert(_jitc->function);
|
||||
assert(_jitc->function->epilog->next == NULL);
|
||||
jit_link(_jitc->function->epilog);
|
||||
_jitc->function = NULL;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
_jit_arg(jit_state_t *_jit)
|
||||
{
|
||||
jit_int32_t offset;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi < 6)
|
||||
offset = _jit->function->self.argi++;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argi < 6)
|
||||
offset = _jitc->function->self.argi++;
|
||||
else {
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_word_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_word_t);
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg, offset));
|
||||
}
|
||||
|
@ -248,12 +248,12 @@ jit_node_t *
|
|||
_jit_arg_f(jit_state_t *_jit)
|
||||
{
|
||||
jit_int32_t offset;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi < 6)
|
||||
offset = _jit->function->self.argi++;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argi < 6)
|
||||
offset = _jitc->function->self.argi++;
|
||||
else {
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float32_t);
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg_f, offset));
|
||||
}
|
||||
|
@ -268,18 +268,18 @@ jit_node_t *
|
|||
_jit_arg_d(jit_state_t *_jit)
|
||||
{
|
||||
jit_int32_t offset;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi < 5) {
|
||||
offset = _jit->function->self.argi;
|
||||
_jit->function->self.argi += 2;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.argi < 5) {
|
||||
offset = _jitc->function->self.argi;
|
||||
_jitc->function->self.argi += 2;
|
||||
}
|
||||
else if (_jit->function->self.argi < 6) {
|
||||
offset = _jit->function->self.argi++;
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
else if (_jitc->function->self.argi < 6) {
|
||||
offset = _jitc->function->self.argi++;
|
||||
_jitc->function->self.size += sizeof(jit_float32_t);
|
||||
}
|
||||
else {
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float64_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float64_t);
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg_d, offset));
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ _jit_getarg_i(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
|||
void
|
||||
_jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
if (v->u.w < 6) {
|
||||
jit_stxi(-4, JIT_FP, _I0 + v->u.w);
|
||||
jit_ldxi_f(u, JIT_FP, -4);
|
||||
|
@ -362,7 +362,7 @@ _jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
|||
void
|
||||
_jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
if (v->u.w < 5) {
|
||||
jit_stxi(-8, JIT_FP, _I0 + v->u.w);
|
||||
jit_stxi(-4, JIT_FP, _I0 + v->u.w + 1);
|
||||
|
@ -380,13 +380,13 @@ _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
|||
void
|
||||
_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
if (_jit->function->call.argi < 6) {
|
||||
jit_movr(_O0 + _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
if (_jitc->function->call.argi < 6) {
|
||||
jit_movr(_O0 + _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
jit_stxi(_jit->function->call.size + stack_framesize, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi(_jitc->function->call.size + stack_framesize, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,30 +394,30 @@ void
|
|||
_jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
||||
{
|
||||
jit_int32_t regno;
|
||||
if (_jit->function->call.argi < 6) {
|
||||
jit_movi(_O0 + _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
if (_jitc->function->call.argi < 6) {
|
||||
jit_movi(_O0 + _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
regno = jit_get_reg(jit_class_gpr);
|
||||
jit_movi(regno, u);
|
||||
jit_stxi(_jit->function->call.size + stack_framesize, JIT_SP, regno);
|
||||
jit_stxi(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
if (_jit->function->call.argi < 6) {
|
||||
if (_jitc->function->call.argi < 6) {
|
||||
jit_stxi_f(-4, JIT_FP, u);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -4);
|
||||
++_jit->function->call.argi;
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -4);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
jit_stxi_f(_jit->function->call.size + stack_framesize, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
jit_stxi_f(_jitc->function->call.size + stack_framesize, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -427,14 +427,14 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
jit_int32_t regno;
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
if (_jit->function->call.argi < 6) {
|
||||
if (_jitc->function->call.argi < 6) {
|
||||
jit_stxi_f(-4, JIT_FP, regno);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -4);
|
||||
++_jit->function->call.argi;
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -4);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else {
|
||||
jit_stxi_f(_jit->function->call.size + stack_framesize, JIT_SP, regno);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
jit_stxi_f(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
|
@ -442,22 +442,22 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
void
|
||||
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
if (_jit->function->call.argi < 5) {
|
||||
if (_jitc->function->call.argi < 5) {
|
||||
jit_stxi_d(-8, JIT_FP, u);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi + 1, JIT_FP, -4);
|
||||
_jit->function->call.argi += 2;
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi + 1, JIT_FP, -4);
|
||||
_jitc->function->call.argi += 2;
|
||||
}
|
||||
else if (_jit->function->call.argi < 6) {
|
||||
else if (_jitc->function->call.argi < 6) {
|
||||
jit_stxi_f(-8, JIT_FP, u);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
|
||||
++_jit->function->call.argi;
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
|
||||
++_jitc->function->call.argi;
|
||||
jit_stxi_f(stack_framesize, JIT_SP, u + 1);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
else {
|
||||
jit_stxi_d(_jit->function->call.size + stack_framesize, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size + stack_framesize, JIT_SP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -467,22 +467,22 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
|
|||
jit_int32_t regno;
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_d(regno, u);
|
||||
if (_jit->function->call.argi < 5) {
|
||||
if (_jitc->function->call.argi < 5) {
|
||||
jit_stxi_d(-8, JIT_FP, regno);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi + 1, JIT_FP, -4);
|
||||
_jit->function->call.argi += 2;
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi + 1, JIT_FP, -4);
|
||||
_jitc->function->call.argi += 2;
|
||||
}
|
||||
else if (_jit->function->call.argi < 6) {
|
||||
else if (_jitc->function->call.argi < 6) {
|
||||
jit_stxi_f(-8, JIT_FP, regno);
|
||||
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
|
||||
++_jit->function->call.argi;
|
||||
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
|
||||
++_jitc->function->call.argi;
|
||||
jit_stxi_f(stack_framesize, JIT_SP, regno + 1);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
_jitc->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
else {
|
||||
jit_stxi_d(_jit->function->call.size + stack_framesize, JIT_SP, regno);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
|
@ -508,15 +508,15 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
|
|||
{
|
||||
jit_node_t *call;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
call = jit_callr(r0);
|
||||
call->v.w = _jit->function->self.argi;
|
||||
call->w.w = _jit->function->self.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
call->v.w = _jitc->function->self.argi;
|
||||
call->w.w = _jitc->function->self.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -524,15 +524,15 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
|
|||
{
|
||||
jit_node_t *node;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
node = jit_calli(i0);
|
||||
node->v.w = _jit->function->call.argi;
|
||||
node->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
node->v.w = _jitc->function->call.argi;
|
||||
node->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
return (node);
|
||||
}
|
||||
|
||||
|
@ -595,7 +595,7 @@ _emit_code(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
|
||||
jit_reglive_setup();
|
||||
|
||||
|
@ -692,8 +692,8 @@ _emit_code(jit_state_t *_jit)
|
|||
patch(word, node); \
|
||||
} \
|
||||
break
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jit->code.end)
|
||||
for (node = _jitc->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jitc->code.end)
|
||||
return (NULL);
|
||||
|
||||
value = jit_classify(node->code);
|
||||
|
@ -1059,17 +1059,17 @@ _emit_code(jit_state_t *_jit)
|
|||
calli(node->u.w);
|
||||
break;
|
||||
case jit_code_prolog:
|
||||
_jit->function = _jit->functions.ptr + node->w.w;
|
||||
_jitc->function = _jitc->functions.ptr + node->w.w;
|
||||
undo.node = node;
|
||||
undo.word = _jit->pc.w;
|
||||
undo.patch_offset = _jit->patches.offset;
|
||||
undo.patch_offset = _jitc->patches.offset;
|
||||
restart_function:
|
||||
_jit->again = 0;
|
||||
_jitc->again = 0;
|
||||
prolog(node);
|
||||
break;
|
||||
case jit_code_epilog:
|
||||
assert(_jit->function == _jit->functions.ptr + node->w.w);
|
||||
if (_jit->again) {
|
||||
assert(_jitc->function == _jitc->functions.ptr + node->w.w);
|
||||
if (_jitc->again) {
|
||||
for (temp = undo.node->next;
|
||||
temp != node; temp = temp->next) {
|
||||
if (temp->code == jit_code_label ||
|
||||
|
@ -1078,14 +1078,14 @@ _emit_code(jit_state_t *_jit)
|
|||
}
|
||||
node = undo.node;
|
||||
_jit->pc.w = undo.word;
|
||||
_jit->patches.offset = undo.patch_offset;
|
||||
_jitc->patches.offset = undo.patch_offset;
|
||||
goto restart_function;
|
||||
}
|
||||
/* remember label is defined */
|
||||
node->flag |= jit_flag_patch;
|
||||
node->u.w = _jit->pc.w;
|
||||
epilog(node);
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
break;
|
||||
case jit_code_live:
|
||||
case jit_code_arg:
|
||||
|
@ -1112,10 +1112,10 @@ _emit_code(jit_state_t *_jit)
|
|||
#undef case_rw
|
||||
#undef case_rr
|
||||
|
||||
for (offset = 0; offset < _jit->patches.offset; offset++) {
|
||||
node = _jit->patches.ptr[offset].node;
|
||||
for (offset = 0; offset < _jitc->patches.offset; offset++) {
|
||||
node = _jitc->patches.ptr[offset].node;
|
||||
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
|
||||
patch_at(_jit->patches.ptr[offset].inst, word);
|
||||
patch_at(_jitc->patches.ptr[offset].inst, word);
|
||||
}
|
||||
|
||||
return (_jit->code.ptr);
|
||||
|
@ -1161,15 +1161,15 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
|
|||
else
|
||||
flag = node->u.n->flag;
|
||||
assert(!(flag & jit_flag_patch));
|
||||
if (_jit->patches.offset >= _jit->patches.length) {
|
||||
_jit->patches.ptr = realloc(_jit->patches.ptr,
|
||||
(_jit->patches.length + 1024) *
|
||||
if (_jitc->patches.offset >= _jitc->patches.length) {
|
||||
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
|
||||
(_jitc->patches.length + 1024) *
|
||||
sizeof(jit_patch_t));
|
||||
memset(_jit->patches.ptr + _jit->patches.length, 0,
|
||||
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
|
||||
1024 * sizeof(jit_patch_t));
|
||||
_jit->patches.length += 1024;
|
||||
_jitc->patches.length += 1024;
|
||||
}
|
||||
_jit->patches.ptr[_jit->patches.offset].inst = instr;
|
||||
_jit->patches.ptr[_jit->patches.offset].node = node;
|
||||
++_jit->patches.offset;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].inst = instr;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].node = node;
|
||||
++_jitc->patches.offset;
|
||||
}
|
||||
|
|
|
@ -863,22 +863,22 @@ _alui(jit_state_t *_jit, jit_int32_t code, jit_int32_t r0, jit_word_t i0)
|
|||
static void
|
||||
_save(jit_state_t *_jit, jit_int32_t r0)
|
||||
{
|
||||
if (!_jit->function->regoff[r0]) {
|
||||
_jit->function->regoff[r0] = jit_allocai(sizeof(jit_word_t));
|
||||
_jit->again = 1;
|
||||
if (!_jitc->function->regoff[r0]) {
|
||||
_jitc->function->regoff[r0] = jit_allocai(sizeof(jit_word_t));
|
||||
_jitc->again = 1;
|
||||
}
|
||||
assert(!jit_regset_tstbit(_jit->regsav, r0));
|
||||
jit_regset_setbit(_jit->regsav, r0);
|
||||
stxi(_jit->function->regoff[r0], _RBP_REGNO, r0);
|
||||
assert(!jit_regset_tstbit(_jitc->regsav, r0));
|
||||
jit_regset_setbit(_jitc->regsav, r0);
|
||||
stxi(_jitc->function->regoff[r0], _RBP_REGNO, r0);
|
||||
}
|
||||
|
||||
static void
|
||||
_load(jit_state_t *_jit, jit_int32_t r0)
|
||||
{
|
||||
assert(_jit->function->regoff[r0]);
|
||||
assert(jit_regset_tstbit(_jit->regsav, r0));
|
||||
jit_regset_clrbit(_jit->regsav, r0);
|
||||
ldxi(r0, _RBP_REGNO, _jit->function->regoff[r0]);
|
||||
assert(_jitc->function->regoff[r0]);
|
||||
assert(jit_regset_tstbit(_jitc->regsav, r0));
|
||||
jit_regset_clrbit(_jitc->regsav, r0);
|
||||
ldxi(r0, _RBP_REGNO, _jitc->function->regoff[r0]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1199,8 +1199,8 @@ _muli(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
|
|||
if (set & (1 << rn)) \
|
||||
(void)jit_get_reg(rv|jit_class_gpr|jit_class_named); \
|
||||
if (sav & (1 << rn)) { \
|
||||
if ( jit_regset_tstbit(_jit->regsav, rv) || \
|
||||
!jit_regset_tstbit(_jit->reglive, rv)) \
|
||||
if ( jit_regset_tstbit(_jitc->regsav, rv) || \
|
||||
!jit_regset_tstbit(_jitc->reglive, rv)) \
|
||||
sav &= ~(1 << rn); \
|
||||
else \
|
||||
save(rv); \
|
||||
|
@ -3303,39 +3303,39 @@ static void
|
|||
_prolog(jit_state_t *_jit, jit_node_t *node)
|
||||
{
|
||||
#if __WORDSIZE == 32
|
||||
_jit->function->stack = (((_jit->function->self.alen -
|
||||
_jit->function->self.aoff) + 15) & -16) + 12;
|
||||
_jitc->function->stack = (((_jitc->function->self.alen -
|
||||
_jitc->function->self.aoff) + 15) & -16) + 12;
|
||||
#else
|
||||
_jit->function->stack = (((_jit->function->self.alen -
|
||||
_jit->function->self.aoff) + 15) & -16) + 8;
|
||||
_jitc->function->stack = (((_jitc->function->self.alen -
|
||||
_jitc->function->self.aoff) + 15) & -16) + 8;
|
||||
#endif
|
||||
|
||||
/* callee save registers */
|
||||
subi(_RSP_REGNO, _RSP_REGNO, stack_framesize - sizeof(jit_word_t));
|
||||
#if __WORDSIZE == 32
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RDI))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RDI))
|
||||
stxi(12, _RSP_REGNO, _RDI_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RSI))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RSI))
|
||||
stxi( 8, _RSP_REGNO, _RSI_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RBX))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RBX))
|
||||
stxi( 4, _RSP_REGNO, _RBX_REGNO);
|
||||
#else
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RBX))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RBX))
|
||||
stxi(40, _RSP_REGNO, _RBX_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R12))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R12))
|
||||
stxi(32, _RSP_REGNO, _R12_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R13))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R13))
|
||||
stxi(24, _RSP_REGNO, _R13_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R14))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R14))
|
||||
stxi(16, _RSP_REGNO, _R14_REGNO);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R15))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R15))
|
||||
stxi( 8, _RSP_REGNO, _R15_REGNO);
|
||||
#endif
|
||||
stxi(0, _RSP_REGNO, _RBP_REGNO);
|
||||
movr(_RBP_REGNO, _RSP_REGNO);
|
||||
|
||||
/* alloca */
|
||||
subi(_RSP_REGNO, _RSP_REGNO, _jit->function->stack);
|
||||
subi(_RSP_REGNO, _RSP_REGNO, _jitc->function->stack);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3344,22 +3344,22 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
|
|||
/* callee save registers */
|
||||
movr(_RSP_REGNO, _RBP_REGNO);
|
||||
#if __WORDSIZE == 32
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RDI))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RDI))
|
||||
ldxi(_RDI_REGNO, _RSP_REGNO, 12);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RSI))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RSI))
|
||||
ldxi(_RSI_REGNO, _RSP_REGNO, 8);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RBX))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RBX))
|
||||
ldxi(_RBX_REGNO, _RSP_REGNO, 4);
|
||||
#else
|
||||
if (jit_regset_tstbit(_jit->function->regset, _RBX))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _RBX))
|
||||
ldxi(_RBX_REGNO, _RSP_REGNO, 40);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R12))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R12))
|
||||
ldxi(_R12_REGNO, _RSP_REGNO, 32);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R13))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R13))
|
||||
ldxi(_R13_REGNO, _RSP_REGNO, 24);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R14))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R14))
|
||||
ldxi(_R14_REGNO, _RSP_REGNO, 16);
|
||||
if (jit_regset_tstbit(_jit->function->regset, _R15))
|
||||
if (jit_regset_tstbit(_jitc->function->regset, _R15))
|
||||
ldxi(_R15_REGNO, _RSP_REGNO, 8);
|
||||
#endif
|
||||
ldxi(_RBP_REGNO, _RSP_REGNO, 0);
|
||||
|
|
260
lib/jit_x86.c
260
lib/jit_x86.c
|
@ -273,11 +273,11 @@ _jit_init(jit_state_t *_jit)
|
|||
static jit_bool_t first = 1;
|
||||
#endif
|
||||
|
||||
_jit->reglen = jit_size(_rvs) - 1;
|
||||
_jitc->reglen = jit_size(_rvs) - 1;
|
||||
#if __WORDSIZE == 32
|
||||
if (first) {
|
||||
if (!jit_cpu.sse2) {
|
||||
for (regno = _jit->reglen; regno >= 0; regno--) {
|
||||
for (regno = _jitc->reglen; regno >= 0; regno--) {
|
||||
if (_rvs[regno].spec & jit_class_xpr)
|
||||
_rvs[regno].spec = 0;
|
||||
}
|
||||
|
@ -292,53 +292,53 @@ _jit_prolog(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
if (_jit->function)
|
||||
if (_jitc->function)
|
||||
jit_epilog();
|
||||
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jit->regsav, 0);
|
||||
offset = _jit->functions.offset;
|
||||
if (offset >= _jit->functions.length) {
|
||||
_jit->functions.ptr = realloc(_jit->functions.ptr,
|
||||
(_jit->functions.length + 16) *
|
||||
assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
|
||||
jit_regset_set_ui(_jitc->regsav, 0);
|
||||
offset = _jitc->functions.offset;
|
||||
if (offset >= _jitc->functions.length) {
|
||||
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
|
||||
(_jitc->functions.length + 16) *
|
||||
sizeof(jit_function_t));
|
||||
memset(_jit->functions.ptr + _jit->functions.length, 0,
|
||||
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
|
||||
16 * sizeof(jit_function_t));
|
||||
_jit->functions.length += 16;
|
||||
_jitc->functions.length += 16;
|
||||
}
|
||||
_jit->function = _jit->functions.ptr + _jit->functions.offset++;
|
||||
_jit->function->self.size = stack_framesize;
|
||||
_jit->function->self.argi = _jit->function->self.argf =
|
||||
_jit->function->self.aoff = _jit->function->self.alen = 0;
|
||||
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
|
||||
_jitc->function->self.size = stack_framesize;
|
||||
_jitc->function->self.argi = _jitc->function->self.argf =
|
||||
_jitc->function->self.aoff = _jitc->function->self.alen = 0;
|
||||
/* sse/x87 conversion */
|
||||
_jit->function->self.aoff = -8;
|
||||
_jit->function->self.call = jit_call_default;
|
||||
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t));
|
||||
_jitc->function->self.aoff = -8;
|
||||
_jitc->function->self.call = jit_call_default;
|
||||
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
|
||||
|
||||
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jit->function->prolog);
|
||||
_jit->function->prolog->w.w = offset;
|
||||
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
|
||||
jit_link(_jitc->function->prolog);
|
||||
_jitc->function->prolog->w.w = offset;
|
||||
_jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
|
||||
/* u: label value
|
||||
* v: offset in blocks vector
|
||||
* w: offset in functions vector
|
||||
*/
|
||||
_jit->function->epilog->w.w = offset;
|
||||
_jitc->function->epilog->w.w = offset;
|
||||
|
||||
jit_regset_new(_jit->function->regset);
|
||||
jit_regset_new(_jitc->function->regset);
|
||||
}
|
||||
|
||||
jit_int32_t
|
||||
_jit_allocai(jit_state_t *_jit, jit_int32_t length)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
switch (length) {
|
||||
case 0: case 1: break;
|
||||
case 2: _jit->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jit->function->self.aoff &= -4; break;
|
||||
default: _jit->function->self.aoff &= -8; break;
|
||||
case 2: _jitc->function->self.aoff &= -2; break;
|
||||
case 3: case 4: _jitc->function->self.aoff &= -4; break;
|
||||
default: _jitc->function->self.aoff &= -8; break;
|
||||
}
|
||||
_jit->function->self.aoff -= length;
|
||||
return (_jit->function->self.aoff);
|
||||
_jitc->function->self.aoff -= length;
|
||||
return (_jitc->function->self.aoff);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -346,11 +346,11 @@ _jit_ret(jit_state_t *_jit)
|
|||
{
|
||||
jit_node_t *instr;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
|
||||
/* jump to epilog */
|
||||
instr = jit_jmpi();
|
||||
jit_patch_at(instr, _jit->function->epilog);
|
||||
jit_patch_at(instr, _jitc->function->epilog);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -409,10 +409,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
|
|||
void
|
||||
_jit_epilog(jit_state_t *_jit)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jit->function->epilog->next == NULL);
|
||||
jit_link(_jit->function->epilog);
|
||||
_jit->function = NULL;
|
||||
assert(_jitc->function);
|
||||
assert(_jitc->function->epilog->next == NULL);
|
||||
jit_link(_jitc->function->epilog);
|
||||
_jitc->function = NULL;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -420,15 +420,15 @@ _jit_arg(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->self.argi < 6)
|
||||
offset = _jit->function->self.argi++;
|
||||
if (_jitc->function->self.argi < 6)
|
||||
offset = _jitc->function->self.argi++;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_word_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_word_t);
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg, offset));
|
||||
}
|
||||
|
@ -448,18 +448,18 @@ _jit_arg_f(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->self.argf < 8)
|
||||
offset = _jit->function->self.argf++;
|
||||
if (_jitc->function->self.argf < 8)
|
||||
offset = _jitc->function->self.argf++;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
offset = _jit->function->self.size;
|
||||
offset = _jitc->function->self.size;
|
||||
#if __WORDSIZE == 32
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
_jitc->function->self.size += sizeof(jit_float32_t);
|
||||
#else
|
||||
_jit->function->self.size += sizeof(jit_float64_t);
|
||||
_jitc->function->self.size += sizeof(jit_float64_t);
|
||||
#endif
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg_f, offset));
|
||||
|
@ -480,15 +480,15 @@ _jit_arg_d(jit_state_t *_jit)
|
|||
{
|
||||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->self.argf < 8)
|
||||
offset = _jit->function->self.argf++;
|
||||
if (_jitc->function->self.argf < 8)
|
||||
offset = _jitc->function->self.argf++;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_float64_t);
|
||||
offset = _jitc->function->self.size;
|
||||
_jitc->function->self.size += sizeof(jit_float64_t);
|
||||
}
|
||||
return (jit_new_node_w(jit_code_arg_d, offset));
|
||||
}
|
||||
|
@ -599,17 +599,17 @@ _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
|
|||
void
|
||||
_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.argi < 6) {
|
||||
jit_movr(_RDI - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
if (_jitc->function->call.argi < 6) {
|
||||
jit_movr(_RDI - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
jit_stxi(_jit->function->call.size, _RSP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi(_jitc->function->call.size, _RSP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -618,19 +618,19 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.argi < 6) {
|
||||
jit_movi(_RDI - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
if (_jitc->function->call.argi < 6) {
|
||||
jit_movi(_RDI - _jitc->function->call.argi, u);
|
||||
++_jitc->function->call.argi;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
regno = jit_get_reg(jit_class_gpr);
|
||||
jit_movi(regno, u);
|
||||
jit_stxi(_jit->function->call.size, _RSP, regno);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi(_jitc->function->call.size, _RSP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
}
|
||||
|
@ -638,17 +638,17 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
|||
void
|
||||
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.argf < 8) {
|
||||
jit_movr_f(_XMM0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (_jitc->function->call.argf < 8) {
|
||||
jit_movr_f(_XMM0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
jit_stxi_f(_jit->function->call.size, _RSP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi_f(_jitc->function->call.size, _RSP, u);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -657,19 +657,19 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.argf < 8) {
|
||||
jit_movi_f(_XMM0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (_jitc->function->call.argf < 8) {
|
||||
jit_movi_f(_XMM0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
jit_stxi_f(_jit->function->call.size, _RSP, regno);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
jit_stxi_f(_jitc->function->call.size, _RSP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_word_t);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
}
|
||||
|
@ -677,17 +677,17 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
|||
void
|
||||
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.argf < 8) {
|
||||
jit_movr_d(_XMM0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (_jitc->function->call.argf < 8) {
|
||||
jit_movr_d(_XMM0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
jit_stxi_d(_jit->function->call.size, _RSP, u);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size, _RSP, u);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -696,19 +696,19 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
|
|||
{
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
assert(_jitc->function);
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.argf < 8) {
|
||||
jit_movi_d(_XMM0 - _jit->function->call.argf, u);
|
||||
++_jit->function->call.argf;
|
||||
if (_jitc->function->call.argf < 8) {
|
||||
jit_movi_d(_XMM0 - _jitc->function->call.argf, u);
|
||||
++_jitc->function->call.argf;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_d(regno, u);
|
||||
jit_stxi_d(_jit->function->call.size, _RSP, regno);
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
jit_stxi_d(_jitc->function->call.size, _RSP, regno);
|
||||
_jitc->function->call.size += sizeof(jit_float64_t);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
}
|
||||
|
@ -743,17 +743,17 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
|
|||
jit_node_t *call;
|
||||
|
||||
reg = r0;
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
#if __WORDSIZE == 64
|
||||
if (_jit->function->call.call & jit_call_varargs) {
|
||||
if (_jitc->function->call.call & jit_call_varargs) {
|
||||
if (jit_regno(reg) == _RAX) {
|
||||
reg = jit_get_reg(jit_class_gpr);
|
||||
jit_movr(reg, _RAX);
|
||||
}
|
||||
if (_jit->function->call.argf)
|
||||
jit_movi(_RAX, _jit->function->call.argf);
|
||||
if (_jitc->function->call.argf)
|
||||
jit_movi(_RAX, _jitc->function->call.argf);
|
||||
else
|
||||
jit_movi(_RAX, 0);
|
||||
if (reg != r0)
|
||||
|
@ -761,11 +761,11 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
|
|||
}
|
||||
#endif
|
||||
call = jit_callr(reg);
|
||||
call->v.w = _jit->function->call.argi;
|
||||
call->w.w = _jit->function->call.argf;
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
call->v.w = _jitc->function->call.argi;
|
||||
call->w.w = _jitc->function->call.argf;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
}
|
||||
|
||||
jit_node_t *
|
||||
|
@ -776,30 +776,30 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
|
|||
#endif
|
||||
jit_node_t *node;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.alen < _jit->function->call.size)
|
||||
_jit->function->self.alen = _jit->function->call.size;
|
||||
assert(_jitc->function);
|
||||
if (_jitc->function->self.alen < _jitc->function->call.size)
|
||||
_jitc->function->self.alen = _jitc->function->call.size;
|
||||
#if __WORDSIZE == 64
|
||||
/* FIXME preventing %rax allocation is good enough, but for consistency
|
||||
* it should automatically detect %rax is dead, in case it has run out
|
||||
* registers, and not save/restore it, what would be wrong if using the
|
||||
* the return value, otherwise, just a needless noop */
|
||||
/* >> prevent %rax from being allocated as the function pointer */
|
||||
jit_regset_setbit(_jit->regarg, _RAX);
|
||||
jit_regset_setbit(_jitc->regarg, _RAX);
|
||||
reg = jit_get_reg(jit_class_gpr);
|
||||
node = jit_movi(reg, (jit_word_t)i0);
|
||||
jit_finishr(reg);
|
||||
jit_unget_reg(reg);
|
||||
/* << prevent %rax from being allocated as the function pointer */
|
||||
jit_regset_clrbit(_jit->regarg, _RAX);
|
||||
jit_regset_clrbit(_jitc->regarg, _RAX);
|
||||
#else
|
||||
node = jit_calli(i0);
|
||||
node->v.w = _jit->function->call.argi;
|
||||
node->w.w = _jit->function->call.argf;
|
||||
node->v.w = _jitc->function->call.argi;
|
||||
node->w.w = _jitc->function->call.argf;
|
||||
#endif
|
||||
_jit->function->call.argi = _jit->function->call.argf =
|
||||
_jit->function->call.size = 0;
|
||||
_jit->prepare = 0;
|
||||
_jitc->function->call.argi = _jitc->function->call.argf =
|
||||
_jitc->function->call.size = 0;
|
||||
_jitc->prepare = 0;
|
||||
return (node);
|
||||
}
|
||||
|
||||
|
@ -889,7 +889,7 @@ _emit_code(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
|
||||
jit_reglive_setup();
|
||||
|
||||
|
@ -1125,8 +1125,8 @@ _emit_code(jit_state_t *_jit)
|
|||
patch(word, node); \
|
||||
} \
|
||||
break
|
||||
for (node = _jit->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jit->code.end)
|
||||
for (node = _jitc->head; node; node = node->next) {
|
||||
if (_jit->pc.uc >= _jitc->code.end)
|
||||
return (NULL);
|
||||
|
||||
value = jit_classify(node->code);
|
||||
|
@ -1558,17 +1558,17 @@ _emit_code(jit_state_t *_jit)
|
|||
calli(node->u.w);
|
||||
break;
|
||||
case jit_code_prolog:
|
||||
_jit->function = _jit->functions.ptr + node->w.w;
|
||||
_jitc->function = _jitc->functions.ptr + node->w.w;
|
||||
undo.node = node;
|
||||
undo.word = _jit->pc.w;
|
||||
undo.patch_offset = _jit->patches.offset;
|
||||
undo.patch_offset = _jitc->patches.offset;
|
||||
restart_function:
|
||||
_jit->again = 0;
|
||||
_jitc->again = 0;
|
||||
prolog(node);
|
||||
break;
|
||||
case jit_code_epilog:
|
||||
assert(_jit->function == _jit->functions.ptr + node->w.w);
|
||||
if (_jit->again) {
|
||||
assert(_jitc->function == _jitc->functions.ptr + node->w.w);
|
||||
if (_jitc->again) {
|
||||
for (temp = undo.node->next;
|
||||
temp != node; temp = temp->next) {
|
||||
if (temp->code == jit_code_label ||
|
||||
|
@ -1577,7 +1577,7 @@ _emit_code(jit_state_t *_jit)
|
|||
}
|
||||
node = undo.node;
|
||||
_jit->pc.w = undo.word;
|
||||
_jit->patches.offset = undo.patch_offset;
|
||||
_jitc->patches.offset = undo.patch_offset;
|
||||
goto restart_function;
|
||||
}
|
||||
if (node->link &&
|
||||
|
@ -1587,7 +1587,7 @@ _emit_code(jit_state_t *_jit)
|
|||
node->flag |= jit_flag_patch;
|
||||
node->u.w = _jit->pc.w;
|
||||
epilog(node);
|
||||
_jit->function = NULL;
|
||||
_jitc->function = NULL;
|
||||
break;
|
||||
#if __WORDSIZE == 32
|
||||
case jit_code_x86_retval_f:
|
||||
|
@ -1637,10 +1637,10 @@ _emit_code(jit_state_t *_jit)
|
|||
#undef case_fr
|
||||
#undef case_rr
|
||||
|
||||
for (offset = 0; offset < _jit->patches.offset; offset++) {
|
||||
node = _jit->patches.ptr[offset].node;
|
||||
for (offset = 0; offset < _jitc->patches.offset; offset++) {
|
||||
node = _jitc->patches.ptr[offset].node;
|
||||
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
|
||||
patch_at(node, _jit->patches.ptr[offset].inst, word);
|
||||
patch_at(node, _jitc->patches.ptr[offset].inst, word);
|
||||
}
|
||||
|
||||
return (_jit->code.ptr);
|
||||
|
@ -1693,17 +1693,17 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
|
|||
else
|
||||
flag = node->u.n->flag;
|
||||
assert(!(flag & jit_flag_patch));
|
||||
if (_jit->patches.offset >= _jit->patches.length) {
|
||||
_jit->patches.ptr = realloc(_jit->patches.ptr,
|
||||
(_jit->patches.length + 1024) *
|
||||
if (_jitc->patches.offset >= _jitc->patches.length) {
|
||||
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
|
||||
(_jitc->patches.length + 1024) *
|
||||
sizeof(jit_patch_t));
|
||||
memset(_jit->patches.ptr + _jit->patches.length, 0,
|
||||
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
|
||||
1024 * sizeof(jit_patch_t));
|
||||
_jit->patches.length += 1024;
|
||||
_jitc->patches.length += 1024;
|
||||
}
|
||||
_jit->patches.ptr[_jit->patches.offset].inst = instr;
|
||||
_jit->patches.ptr[_jit->patches.offset].node = node;
|
||||
++_jit->patches.offset;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].inst = instr;
|
||||
_jitc->patches.ptr[_jitc->patches.offset].node = node;
|
||||
++_jitc->patches.offset;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
653
lib/lightning.c
653
lib/lightning.c
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue