1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +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:
pcpa 2013-03-06 16:49:26 -03:00
parent f39eee6694
commit 9afca85921
16 changed files with 1328 additions and 1299 deletions

View file

@ -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> 2013-03-06 Paulo Andrade <pcpa@gnu.org>
* lib/lightning.c: Make data and code buffer readonly. * lib/lightning.c: Make data and code buffer readonly.

View file

@ -79,9 +79,9 @@
#define jit_size(vector) (sizeof(vector) / sizeof((vector)[0])) #define jit_size(vector) (sizeof(vector) / sizeof((vector)[0]))
#define jit_reg_free_p(regno) \ #define jit_reg_free_p(regno) \
(!jit_regset_tstbit(_jit->reglive, regno) && \ (!jit_regset_tstbit(_jitc->reglive, regno) && \
!jit_regset_tstbit(_jit->regarg, regno) && \ !jit_regset_tstbit(_jitc->regarg, regno) && \
!jit_regset_tstbit(_jit->regsav, regno)) !jit_regset_tstbit(_jitc->regsav, regno))
/* /*
* Private jit_class bitmasks * Private jit_class bitmasks
@ -152,8 +152,8 @@ jit_regset_scan1(jit_regset_t, jit_int32_t);
#define jit_reglive_setup() \ #define jit_reglive_setup() \
do { \ do { \
jit_regset_set_ui(_jit->reglive, 0); \ jit_regset_set_ui(_jitc->reglive, 0); \
jit_regset_set_ui(_jit->regmask, 0); \ jit_regset_set_ui(_jitc->regmask, 0); \
} while (0) } while (0)
/* /*
@ -164,6 +164,7 @@ typedef struct jit_note jit_note_t;
typedef struct jit_line jit_line_t; typedef struct jit_line jit_line_t;
typedef struct jit_block jit_block_t; typedef struct jit_block jit_block_t;
typedef struct jit_value jit_value_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_function jit_function_t;
typedef struct jit_register jit_register_t; typedef struct jit_register jit_register_t;
#if __arm__ #if __arm__
@ -264,14 +265,8 @@ struct jit_function {
jit_int32_t stack; jit_int32_t stack;
}; };
struct jit_state { /* data used only during jit generation */
union { struct jit_compiler {
jit_uint8_t *uc;
jit_uint16_t *us;
jit_uint32_t *ui;
jit_uint64_t *ul;
jit_word_t w;
} pc;
jit_node_t *head; jit_node_t *head;
jit_node_t *tail; jit_node_t *tail;
jit_uint32_t done : 1; /* emit state finished */ jit_uint32_t done : 1; /* emit state finished */
@ -285,17 +280,13 @@ struct jit_state {
jit_regset_t regmask; /* register mask to update reglive */ jit_regset_t regmask; /* register mask to update reglive */
mpz_t blockmask; /* mask of visited basic blocks */ mpz_t blockmask; /* mask of visited basic blocks */
struct { struct {
jit_uint8_t *ptr;
jit_uint8_t *end; jit_uint8_t *end;
jit_word_t length;
} code; } code;
struct { struct {
jit_uint8_t *ptr; /* constant pool */
jit_node_t **table; /* very simple hash table */ jit_node_t **table; /* very simple hash table */
jit_word_t size; /* number of vectors in table */ jit_word_t size; /* number of vectors in table */
jit_word_t count; /* number of hash table entries */ jit_word_t count; /* number of hash table entries */
jit_word_t offset; /* offset in bytes in ptr */ jit_word_t offset; /* offset in bytes in ptr */
jit_word_t length; /* length in bytes of ptr */
} data; } data;
jit_node_t **spill; jit_node_t **spill;
jit_int32_t *gen; /* ssa like "register version" */ jit_int32_t *gen; /* ssa like "register version" */
@ -323,10 +314,8 @@ struct jit_state {
} pool; } pool;
jit_node_t *list; jit_node_t *list;
struct { struct {
jit_note_t *ptr;
jit_node_t *head; /* first note node */ jit_node_t *head; /* first note node */
jit_node_t *tail; /* linked list insertion */ jit_node_t *tail; /* linked list insertion */
jit_word_t length;
/* fields to store temporary state information */ /* fields to store temporary state information */
jit_word_t size; jit_word_t size;
@ -361,6 +350,30 @@ struct jit_state {
#endif #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 { struct jit_register {
jit_reg_t spec; jit_reg_t spec;
char *name; char *name;

View file

@ -2558,7 +2558,7 @@ _jmpi(jit_state_t *_jit, jit_word_t i0)
jit_word_t d; jit_word_t d;
w = _jit->pc.w; w = _jit->pc.w;
/* if thumb and in thumb mode */ /* if thumb and in thumb mode */
if (jit_thumb_p() && _jit->thumb) { if (jit_thumb_p() && _jitc->thumb) {
d = ((i0 - w) >> 1) - 2; d = ((i0 - w) >> 1) - 2;
if (d >= -1024 && d <= 1023) if (d >= -1024 && d <= 1023)
T1_B(d & 0x7ff); T1_B(d & 0x7ff);
@ -2590,7 +2590,7 @@ _jmpi_p(jit_state_t *_jit, jit_word_t i0)
jit_word_t d; jit_word_t d;
w = _jit->pc.w; w = _jit->pc.w;
/* if thumb and in thumb mode */ /* if thumb and in thumb mode */
if (jit_thumb_p() && _jit->thumb) { if (jit_thumb_p() && _jitc->thumb) {
d = ((i0 - w) >> 1) - 2; d = ((i0 - w) >> 1) - 2;
assert(_s24P(d)); assert(_s24P(d));
T2_B(encode_thumb_jump(d)); T2_B(encode_thumb_jump(d));
@ -3692,9 +3692,9 @@ _calli_p(jit_state_t *_jit, jit_word_t i0)
static void static void
_prolog(jit_state_t *_jit, jit_node_t *node) _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 */ /* align stack at 8 bytes */
_jit->function->self.aoff) + 7) & -8; _jitc->function->self.aoff) + 7) & -8;
if (jit_thumb_p()) { if (jit_thumb_p()) {
/* switch to thumb mode (better approach would be to /* 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) */ * a pointer to a jit function) */
ADDI(_R12_REGNO, _R15_REGNO, 1); ADDI(_R12_REGNO, _R15_REGNO, 1);
BX(_R12_REGNO); BX(_R12_REGNO);
if (!_jit->thumb) if (!_jitc->thumb)
_jit->thumb = _jit->pc.w; _jitc->thumb = _jit->pc.w;
if (jit_cpu.abi) { if (jit_cpu.abi) {
T2_PUSH(0x3f0|(1<<_FP_REGNO)|(1<<_LR_REGNO)); T2_PUSH(0x3f0|(1<<_FP_REGNO)|(1<<_LR_REGNO));
VPUSH_F64(_D8_REGNO, 8); 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)); PUSH(0x3ff|(1<<_FP_REGNO)|(1<<_LR_REGNO));
} }
movr(_FP_REGNO, _SP_REGNO); movr(_FP_REGNO, _SP_REGNO);
subi(_SP_REGNO, _SP_REGNO, _jit->function->stack); subi(_SP_REGNO, _SP_REGNO, _jitc->function->stack);
} }
static void static void
@ -3753,7 +3753,7 @@ _patch_at(jit_state_t *_jit,
} u; } u;
u.w = instr; u.w = instr;
if (kind == arm_patch_jump) { 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]); code2thumb(thumb.s[0], thumb.s[1], u.s[0], u.s[1]);
if ((thumb.i & THUMB2_B) == THUMB2_B) { if ((thumb.i & THUMB2_B) == THUMB2_B) {
d = ((label - instr) >> 1) - 2; d = ((label - instr) >> 1) - 2;

View file

@ -187,7 +187,7 @@ _jit_init(jit_state_t *_jit)
jit_int32_t regno; jit_int32_t regno;
static jit_bool_t first = 1; static jit_bool_t first = 1;
_jit->reglen = jit_size(_rvs) - 1; _jitc->reglen = jit_size(_rvs) - 1;
if (first) { if (first) {
/* jit_get_cpu() should have been already called, and only once */ /* jit_get_cpu() should have been already called, and only once */
if (!jit_cpu.vfp) { if (!jit_cpu.vfp) {
@ -209,58 +209,58 @@ _jit_prolog(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
if (_jit->function) if (_jitc->function)
jit_epilog(); jit_epilog();
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0); assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
jit_regset_set_ui(_jit->regsav, 0); jit_regset_set_ui(_jitc->regsav, 0);
offset = _jit->functions.offset; offset = _jitc->functions.offset;
if (offset >= _jit->functions.length) { if (offset >= _jitc->functions.length) {
_jit->functions.ptr = realloc(_jit->functions.ptr, _jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jit->functions.length + 16) * (_jitc->functions.length + 16) *
sizeof(jit_function_t)); 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)); 16 * sizeof(jit_function_t));
_jit->functions.length += 16; _jitc->functions.length += 16;
} }
_jit->function = _jit->functions.ptr + _jit->functions.offset++; _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
_jit->function->self.size = stack_framesize; _jitc->function->self.size = stack_framesize;
if (jit_cpu.abi) if (jit_cpu.abi)
_jit->function->self.size += 64; _jitc->function->self.size += 64;
_jit->function->self.argi = _jit->function->self.argf = _jitc->function->self.argi = _jitc->function->self.argf =
_jit->function->self.alen = 0; _jitc->function->self.alen = 0;
if (jit_swf_p()) if (jit_swf_p())
/* 8 soft float registers */ /* 8 soft float registers */
_jit->function->self.aoff = -64; _jitc->function->self.aoff = -64;
else else
_jit->function->self.aoff = 0; _jitc->function->self.aoff = 0;
_jit->function->self.call = jit_call_default; _jitc->function->self.call = jit_call_default;
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t)); _jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog); _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jit->function->prolog); jit_link(_jitc->function->prolog);
_jit->function->prolog->w.w = offset; _jitc->function->prolog->w.w = offset;
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog); _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
/* u: label value /* u: label value
* v: offset in blocks vector * v: offset in blocks vector
* w: offset in functions 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_int32_t
_jit_allocai(jit_state_t *_jit, jit_int32_t length) _jit_allocai(jit_state_t *_jit, jit_int32_t length)
{ {
assert(_jit->function); assert(_jitc->function);
switch (length) { switch (length) {
case 0: case 1: break; case 0: case 1: break;
case 2: _jit->function->self.aoff &= -2; break; case 2: _jitc->function->self.aoff &= -2; break;
case 3: case 4: _jit->function->self.aoff &= -4; break; case 3: case 4: _jitc->function->self.aoff &= -4; break;
default: _jit->function->self.aoff &= -8; break; default: _jitc->function->self.aoff &= -8; break;
} }
_jit->function->self.aoff -= length; _jitc->function->self.aoff -= length;
return (_jit->function->self.aoff); return (_jitc->function->self.aoff);
} }
void void
@ -268,11 +268,11 @@ _jit_ret(jit_state_t *_jit)
{ {
jit_node_t *instr; jit_node_t *instr;
assert(_jit->function); assert(_jitc->function);
/* jump to epilog */ /* jump to epilog */
instr = jit_jmpi(); instr = jit_jmpi();
jit_patch_at(instr, _jit->function->epilog); jit_patch_at(instr, _jitc->function->epilog);
} }
void void
@ -352,10 +352,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
void void
_jit_epilog(jit_state_t *_jit) _jit_epilog(jit_state_t *_jit)
{ {
assert(_jit->function); assert(_jitc->function);
assert(_jit->function->epilog->next == NULL); assert(_jitc->function->epilog->next == NULL);
jit_link(_jit->function->epilog); jit_link(_jitc->function->epilog);
_jit->function = NULL; _jitc->function = NULL;
} }
jit_node_t * jit_node_t *
@ -363,12 +363,12 @@ _jit_arg(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argi < 4) if (_jitc->function->self.argi < 4)
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
else { else {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_word_t); _jitc->function->self.size += sizeof(jit_word_t);
} }
return (jit_new_node_w(jit_code_arg, offset)); return (jit_new_node_w(jit_code_arg, offset));
} }
@ -384,21 +384,21 @@ _jit_arg_f(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (jit_cpu.abi && !(_jit->function->self.call & jit_call_varargs)) { if (jit_cpu.abi && !(_jitc->function->self.call & jit_call_varargs)) {
if (_jit->function->self.argf < 16) { if (_jitc->function->self.argf < 16) {
offset = _jit->function->self.argf++; offset = _jitc->function->self.argf++;
goto done; goto done;
} }
} }
else { else {
if (_jit->function->self.argi < 4) { if (_jitc->function->self.argi < 4) {
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
goto done; goto done;
} }
} }
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float32_t); _jitc->function->self.size += sizeof(jit_float32_t);
done: done:
return (jit_new_node_w(jit_code_arg_f, offset)); 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; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (jit_cpu.abi && !(_jit->function->self.call & jit_call_varargs)) { if (jit_cpu.abi && !(_jitc->function->self.call & jit_call_varargs)) {
if (_jit->function->self.argf < 15) { if (_jitc->function->self.argf < 15) {
if (_jit->function->self.argf & 1) if (_jitc->function->self.argf & 1)
++_jit->function->self.argf; ++_jitc->function->self.argf;
offset = _jit->function->self.argf; offset = _jitc->function->self.argf;
_jit->function->self.argf += 2; _jitc->function->self.argf += 2;
goto done; goto done;
} }
} }
else { else {
if (_jit->function->self.argi < 3) { if (_jitc->function->self.argi < 3) {
if (_jit->function->self.argi & 1) if (_jitc->function->self.argi & 1)
++_jit->function->self.argi; ++_jitc->function->self.argi;
offset = _jit->function->self.argi; offset = _jitc->function->self.argi;
_jit->function->self.argi += 2; _jitc->function->self.argi += 2;
goto done; goto done;
} }
} }
if (_jit->function->self.size & 7) if (_jitc->function->self.size & 7)
_jit->function->self.size += 4; _jitc->function->self.size += 4;
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float64_t); _jitc->function->self.size += sizeof(jit_float64_t);
done: done:
return (jit_new_node_w(jit_code_arg_d, offset)); 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 void
_jit_pushargr(jit_state_t *_jit, jit_int32_t u) _jit_pushargr(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argi < 4) { if (_jitc->function->call.argi < 4) {
jit_movr(JIT_RA0 - _jit->function->call.argi, u); jit_movr(JIT_RA0 - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
jit_stxi(_jit->function->call.size, JIT_SP, u); jit_stxi(_jitc->function->call.size, JIT_SP, u);
_jit->function->call.size += sizeof(jit_word_t); _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; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argi < 4) { if (_jitc->function->call.argi < 4) {
jit_movi(JIT_RA0 - _jit->function->call.argi, u); jit_movi(JIT_RA0 - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
regno = jit_get_reg(jit_class_gpr); regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u); 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_unget_reg(regno);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
} }
void void
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u) _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) { if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
if (_jit->function->call.argf < 16) { if (_jitc->function->call.argf < 16) {
jit_movr_f(JIT_FA0 - _jit->function->call.argf, u); jit_movr_f(JIT_FA0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
return; return;
} }
} }
else { else {
if (_jit->function->call.argi < 4) { if (_jitc->function->call.argi < 4) {
jit_movr_f_w(JIT_RA0 - _jit->function->call.argi, u); jit_movr_f_w(JIT_RA0 - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
return; return;
} }
} }
jit_stxi_f(_jit->function->call.size, JIT_SP, u); jit_stxi_f(_jitc->function->call.size, JIT_SP, u);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
void void
@ -600,63 +600,63 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
{ {
jit_int32_t regno; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) { if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
if (_jit->function->call.argf < 16) { if (_jitc->function->call.argf < 16) {
/* cannot jit_movi_f in the argument register because /* cannot jit_movi_f in the argument register because
* float arguments are packed, and that would cause * float arguments are packed, and that would cause
* either an assertion in debug mode, or overwritting * either an assertion in debug mode, or overwritting
* two registers */ * two registers */
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u); 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_unget_reg(regno);
++_jit->function->call.argf; ++_jitc->function->call.argf;
return; return;
} }
} }
else { else {
if (_jit->function->call.argi < 4) { if (_jitc->function->call.argi < 4) {
jit_movi_f_w(JIT_RA0 - _jit->function->call.argi, u); jit_movi_f_w(JIT_RA0 - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
return; return;
} }
} }
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u); 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_unget_reg(regno);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
void void
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u) _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) { if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
if (_jit->function->call.argf < 15) { if (_jitc->function->call.argf < 15) {
if (_jit->function->call.argf & 1) if (_jitc->function->call.argf & 1)
++_jit->function->call.argf; ++_jitc->function->call.argf;
jit_movr_d(JIT_FA0 - _jit->function->call.argf, u); jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
_jit->function->call.argf += 2; _jitc->function->call.argf += 2;
return; return;
} }
} }
else { else {
if (_jit->function->call.argi & 1) if (_jitc->function->call.argi & 1)
++_jit->function->call.argi; ++_jitc->function->call.argi;
if (_jit->function->call.argi < 4) { if (_jitc->function->call.argi < 4) {
jit_movr_d_ww(JIT_RA0 - _jit->function->call.argi, jit_movr_d_ww(JIT_RA0 - _jitc->function->call.argi,
JIT_RA0 - (_jit->function->call.argi + 1), JIT_RA0 - (_jitc->function->call.argi + 1),
u); u);
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
return; return;
} }
} }
if (_jit->function->call.size & 7) if (_jitc->function->call.size & 7)
_jit->function->call.size += 4; _jitc->function->call.size += 4;
jit_stxi_d(_jit->function->call.size, JIT_SP, u); jit_stxi_d(_jitc->function->call.size, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
} }
void void
@ -664,34 +664,34 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
{ {
jit_int32_t regno; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
if (jit_cpu.abi && !(_jit->function->call.call & jit_call_varargs)) { if (jit_cpu.abi && !(_jitc->function->call.call & jit_call_varargs)) {
if (_jit->function->call.argf < 15) { if (_jitc->function->call.argf < 15) {
if (_jit->function->call.argf & 1) if (_jitc->function->call.argf & 1)
++_jit->function->call.argf; ++_jitc->function->call.argf;
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u); jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
_jit->function->call.argf += 2; _jitc->function->call.argf += 2;
return; return;
} }
} }
else { else {
if (_jit->function->call.argi & 1) if (_jitc->function->call.argi & 1)
++_jit->function->call.argi; ++_jitc->function->call.argi;
if (_jit->function->call.argi < 4) { if (_jitc->function->call.argi < 4) {
jit_movi_d_ww(JIT_RA0 - _jit->function->call.argi, jit_movi_d_ww(JIT_RA0 - _jitc->function->call.argi,
JIT_RA0 - (_jit->function->call.argi + 1), JIT_RA0 - (_jitc->function->call.argi + 1),
u); u);
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
return; return;
} }
} }
if (_jit->function->call.size & 7) if (_jitc->function->call.size & 7)
_jit->function->call.size += 4; _jitc->function->call.size += 4;
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u); 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_unget_reg(regno);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
} }
jit_bool_t jit_bool_t
@ -719,15 +719,15 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
{ {
jit_node_t *node; jit_node_t *node;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
node = jit_callr(r0); node = jit_callr(r0);
node->v.w = _jit->function->self.argi; node->v.w = _jitc->function->self.argi;
node->w.w = _jit->function->call.argf; node->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
} }
jit_node_t * jit_node_t *
@ -735,15 +735,15 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
{ {
jit_node_t *node; jit_node_t *node;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
node = jit_calli(i0); node = jit_calli(i0);
node->v.w = _jit->function->call.argi; node->v.w = _jitc->function->call.argi;
node->w.w = _jit->function->call.argf; node->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
return (node); return (node);
} }
@ -818,7 +818,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset; jit_int32_t patch_offset;
} undo; } undo;
_jit->function = NULL; _jitc->function = NULL;
jit_reglive_setup(); jit_reglive_setup();
@ -1034,8 +1034,8 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \ patch(word, node); \
} \ } \
break break
for (node = _jit->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jit->code.end) if (_jit->pc.uc >= _jitc->code.end)
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);
@ -1415,22 +1415,22 @@ _emit_code(jit_state_t *_jit)
calli(node->u.w); calli(node->u.w);
break; break;
case jit_code_prolog: case jit_code_prolog:
_jit->function = _jit->functions.ptr + node->w.w; _jitc->function = _jitc->functions.ptr + node->w.w;
undo.node = node; undo.node = node;
undo.word = _jit->pc.w; undo.word = _jit->pc.w;
undo.data = _jit->consts.data; undo.data = _jitc->consts.data;
undo.thumb = _jit->thumb; undo.thumb = _jitc->thumb;
undo.const_offset = _jit->consts.offset; undo.const_offset = _jitc->consts.offset;
undo.patch_offset = _jit->patches.offset; undo.patch_offset = _jitc->patches.offset;
if (_jit->data_info.ptr) if (_jitc->data_info.ptr)
undo.info_offset = _jit->data_info.offset; undo.info_offset = _jitc->data_info.offset;
restart_function: restart_function:
_jit->again = 0; _jitc->again = 0;
prolog(node); prolog(node);
break; break;
case jit_code_epilog: case jit_code_epilog:
assert(_jit->function == _jit->functions.ptr + node->w.w); assert(_jitc->function == _jitc->functions.ptr + node->w.w);
if (_jit->again) { if (_jitc->again) {
for (temp = undo.node->next; for (temp = undo.node->next;
temp != node; temp = temp->next) { temp != node; temp = temp->next) {
if (temp->code == jit_code_label || if (temp->code == jit_code_label ||
@ -1440,19 +1440,19 @@ _emit_code(jit_state_t *_jit)
node = undo.node; node = undo.node;
_jit->pc.w = undo.word; _jit->pc.w = undo.word;
invalidate_consts(); invalidate_consts();
_jit->consts.data = undo.data; _jitc->consts.data = undo.data;
_jit->thumb = undo.thumb; _jitc->thumb = undo.thumb;
_jit->consts.offset = undo.const_offset; _jitc->consts.offset = undo.const_offset;
_jit->patches.offset = undo.patch_offset; _jitc->patches.offset = undo.patch_offset;
if (_jit->data_info.ptr) if (_jitc->data_info.ptr)
_jit->data_info.offset = undo.info_offset; _jitc->data_info.offset = undo.info_offset;
goto restart_function; goto restart_function;
} }
/* remember label is defined */ /* remember label is defined */
node->flag |= jit_flag_patch; node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w; node->u.w = _jit->pc.w;
epilog(node); epilog(node);
_jit->function = NULL; _jitc->function = NULL;
flush_consts(); flush_consts();
break; break;
case jit_code_movr_w_f: case jit_code_movr_w_f:
@ -1504,7 +1504,7 @@ _emit_code(jit_state_t *_jit)
/* update register live state */ /* update register live state */
jit_reglive(node); 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 /* longest sequence should be 64 bytes, but preventively
* do not let it go past 128 remaining bytes before a flush */ * do not let it go past 128 remaining bytes before a flush */
if (node->next && if (node->next &&
@ -1541,10 +1541,10 @@ _emit_code(jit_state_t *_jit)
#undef case_rr #undef case_rr
flush_consts(); flush_consts();
for (offset = 0; offset < _jit->patches.offset; offset++) { for (offset = 0; offset < _jitc->patches.offset; offset++) {
assert(_jit->patches.ptr[offset].kind & arm_patch_node); assert(_jitc->patches.ptr[offset].kind & arm_patch_node);
node = _jit->patches.ptr[offset].node; node = _jitc->patches.ptr[offset].node;
word = _jit->patches.ptr[offset].inst; word = _jitc->patches.ptr[offset].inst;
if (!jit_thumb_p() && if (!jit_thumb_p() &&
(node->code == jit_code_movi || node->code == jit_code_calli)) { (node->code == jit_code_movi || node->code == jit_code_calli)) {
/* calculate where to patch word */ /* calculate where to patch word */
@ -1560,7 +1560,7 @@ _emit_code(jit_state_t *_jit)
word = word + 8 + value; word = word + 8 + value;
} }
value = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w; 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); __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 * return JIT_NOREG if fail, as the cost of spills is greater
* than splitting a double load/store in two operations. */ * than splitting a double load/store in two operations. */
if (jit_reg_free_p(_R0) && jit_reg_free_p(_R1)) { if (jit_reg_free_p(_R0) && jit_reg_free_p(_R1)) {
jit_regset_setbit(_jit->regarg, _R0); jit_regset_setbit(_jitc->regarg, _R0);
jit_regset_setbit(_jit->regarg, _R1); jit_regset_setbit(_jitc->regarg, _R1);
return (_R0); return (_R0);
} }
if (jit_reg_free_p(_R2) && jit_reg_free_p(_R3)) { if (jit_reg_free_p(_R2) && jit_reg_free_p(_R3)) {
jit_regset_setbit(_jit->regarg, _R2); jit_regset_setbit(_jitc->regarg, _R2);
jit_regset_setbit(_jit->regarg, _R3); jit_regset_setbit(_jitc->regarg, _R3);
return (_R2); return (_R2);
} }
if (jit_reg_free_p(_R4) && jit_reg_free_p(_R5)) { if (jit_reg_free_p(_R4) && jit_reg_free_p(_R5)) {
jit_regset_setbit(_jit->regarg, _R4); jit_regset_setbit(_jitc->regarg, _R4);
jit_regset_setbit(_jit->regarg, _R5); jit_regset_setbit(_jitc->regarg, _R5);
return (_R4); return (_R4);
} }
if (jit_reg_free_p(_R6) && jit_reg_free_p(_R7)) { if (jit_reg_free_p(_R6) && jit_reg_free_p(_R7)) {
jit_regset_setbit(_jit->regarg, _R6); jit_regset_setbit(_jitc->regarg, _R6);
jit_regset_setbit(_jit->regarg, _R7); jit_regset_setbit(_jitc->regarg, _R7);
return (_R6); return (_R6);
} }
if (jit_reg_free_p(_R8) && jit_reg_free_p(_R9)) { if (jit_reg_free_p(_R8) && jit_reg_free_p(_R9)) {
jit_regset_setbit(_jit->regarg, _R8); jit_regset_setbit(_jitc->regarg, _R8);
jit_regset_setbit(_jit->regarg, _R9); jit_regset_setbit(_jitc->regarg, _R9);
return (_R8); return (_R8);
} }
return (JIT_NOREG); 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 */ /* 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; w = (jit_word_t)data;
/* maximum backwards offset */ /* maximum backwards offset */
base = (_jit->pc.w + 8) - 4092; 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; base = 0;
else else
base = (base - w) >> 2; base = (base - w) >> 2;
size = _jit->consts.size >> 2; size = _jitc->consts.size >> 2;
for (offset = size - 1; offset >= base; offset--) { for (offset = size - 1; offset >= base; offset--) {
if (data[offset] == i0) { if (data[offset] == i0) {
w = (jit_word_t)(data + offset); 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 else
assert(i0 == 0); 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 */ /* (probably) positive forward offset */
LDRI(r0, _R15_REGNO, 0); LDRI(r0, _R15_REGNO, 0);
if (!uniq) { if (!uniq) {
/* search already requested values */ /* search already requested values */
for (offset = 0; offset < _jit->consts.length; offset++) { for (offset = 0; offset < _jitc->consts.length; offset++) {
if (_jit->consts.values[offset] == i0) { if (_jitc->consts.values[offset] == i0) {
_jit->consts.patches[_jit->consts.offset++] = offset; _jitc->consts.patches[_jitc->consts.offset++] = offset;
return; 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 #if DEBUG
/* cannot run out of space because of limited range /* cannot run out of space because of limited range
* but assert anyway to catch logic errors */ * but assert anyway to catch logic errors */
assert(_jit->consts.length < 1024); assert(_jitc->consts.length < 1024);
assert(_jit->consts.offset < 2048); assert(_jitc->consts.offset < 2048);
#endif #endif
_jit->consts.patches[_jit->consts.offset++] = _jit->consts.length; _jitc->consts.patches[_jitc->consts.offset++] = _jitc->consts.length;
_jit->consts.values[_jit->consts.length++] = i0; _jitc->consts.values[_jitc->consts.length++] = i0;
} }
static void static void
@ -1734,35 +1734,35 @@ _flush_consts(jit_state_t *_jit)
jit_int32_t offset; jit_int32_t offset;
/* if no forward constants */ /* if no forward constants */
if (!_jit->consts.length) if (!_jitc->consts.length)
return; return;
assert(!jit_thumb_p()); assert(!jit_thumb_p());
word = _jit->pc.w; word = _jit->pc.w;
_jit->consts.data = _jit->pc.uc; _jitc->consts.data = _jit->pc.uc;
_jit->consts.size = _jit->consts.length << 2; _jitc->consts.size = _jitc->consts.length << 2;
/* FIXME check will not overrun, otherwise, need to reallocate /* FIXME check will not overrun, otherwise, need to reallocate
* code buffer and start over */ * code buffer and start over */
memcpy(_jit->consts.data, _jit->consts.values, _jit->consts.size); memcpy(_jitc->consts.data, _jitc->consts.values, _jitc->consts.size);
_jit->pc.w += _jit->consts.size; _jit->pc.w += _jitc->consts.size;
if (_jit->data_info.ptr) { if (_jitc->data_info.ptr) {
if (_jit->data_info.offset >= _jit->data_info.length) { if (_jitc->data_info.offset >= _jitc->data_info.length) {
_jit->data_info.ptr = realloc(_jit->data_info.ptr, _jitc->data_info.ptr = realloc(_jitc->data_info.ptr,
(_jit->data_info.length + 1024) * (_jitc->data_info.length + 1024) *
sizeof(jit_data_info_t)); 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)); 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; _jitc->data_info.ptr[_jitc->data_info.offset].code = word;
_jit->data_info.ptr[_jit->data_info.offset].length = _jit->consts.size; _jitc->data_info.ptr[_jitc->data_info.offset].length = _jitc->consts.size;
++_jit->data_info.offset; ++_jitc->data_info.offset;
} }
for (offset = 0; offset < _jit->consts.offset; offset += 2) for (offset = 0; offset < _jitc->consts.offset; offset += 2)
patch_at(arm_patch_load, _jit->consts.patches[offset], patch_at(arm_patch_load, _jitc->consts.patches[offset],
word + (_jit->consts.patches[offset + 1] << 2)); word + (_jitc->consts.patches[offset + 1] << 2));
_jit->consts.length = _jit->consts.offset = 0; _jitc->consts.length = _jitc->consts.offset = 0;
} }
/* to be called if needing to start over a function */ /* to be called if needing to start over a function */
@ -1770,8 +1770,8 @@ static void
_invalidate_consts(jit_state_t *_jit) _invalidate_consts(jit_state_t *_jit)
{ {
/* if no forward constants */ /* if no forward constants */
if (_jit->consts.length) if (_jitc->consts.length)
_jit->consts.length = _jit->consts.offset = 0; _jitc->consts.length = _jitc->consts.offset = 0;
} }
static void static void
@ -1794,16 +1794,16 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
} }
assert(!(flag & jit_flag_patch)); assert(!(flag & jit_flag_patch));
kind |= arm_patch_node; kind |= arm_patch_node;
if (_jit->patches.offset >= _jit->patches.length) { if (_jitc->patches.offset >= _jitc->patches.length) {
_jit->patches.ptr = realloc(_jit->patches.ptr, _jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jit->patches.length + 1024) * (_jitc->patches.length + 1024) *
sizeof(jit_patch_t)); 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)); 1024 * sizeof(jit_patch_t));
_jit->patches.length += 1024; _jitc->patches.length += 1024;
} }
_jit->patches.ptr[_jit->patches.offset].kind = kind; _jitc->patches.ptr[_jitc->patches.offset].kind = kind;
_jit->patches.ptr[_jit->patches.offset].inst = instr; _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
_jit->patches.ptr[_jit->patches.offset].node = node; _jitc->patches.ptr[_jitc->patches.offset].node = node;
++_jit->patches.offset; ++_jitc->patches.offset;
} }

View file

@ -287,15 +287,15 @@ _disassemble(jit_state_t *_jit, jit_pointer_t code, jit_int32_t length)
#if __arm__ #if __arm__
again: again:
if (data_info) { if (data_info) {
while (_jit->data_info.ptr[data_offset].code < pc) { while (_jitc->data_info.ptr[data_offset].code < pc) {
data_offset += 2; data_offset += 2;
if (data_offset >= _jit->data_info.length) { if (data_offset >= _jitc->data_info.length) {
data_info = 0; data_info = 0;
goto again; goto again;
} }
} }
if (pc == _jit->data_info.ptr[data_offset].code) { if (pc == _jitc->data_info.ptr[data_offset].code) {
offset = _jit->data_info.ptr[data_offset].length; offset = _jitc->data_info.ptr[data_offset].length;
for (; offset >= 4; offset -= 4, pc += 4) { for (; offset >= 4; offset -= 4, pc += 4) {
bytes = sprintf(buffer, address_buffer_format, pc); bytes = sprintf(buffer, address_buffer_format, pc);
(*disasm_info.fprintf_func)(disasm_stream, (*disasm_info.fprintf_func)(disasm_stream,

View file

@ -2773,79 +2773,79 @@ _calli_p(jit_state_t *_jit, jit_word_t i0)
static void static void
_prolog(jit_state_t *_jit, jit_node_t *node) _prolog(jit_state_t *_jit, jit_node_t *node)
{ {
_jit->function->stack = ((/* first 16 bytes must be allocated */ _jitc->function->stack = ((/* first 16 bytes must be allocated */
(_jit->function->self.alen > 16 ? (_jitc->function->self.alen > 16 ?
_jit->function->self.alen : 16) - _jitc->function->self.alen : 16) -
/* align stack at 8 bytes */ /* align stack at 8 bytes */
_jit->function->self.aoff) + 7) & -8; _jitc->function->self.aoff) + 7) & -8;
/* callee save registers */ /* callee save registers */
subi(_SP_REGNO, _SP_REGNO, stack_framesize); subi(_SP_REGNO, _SP_REGNO, stack_framesize);
#if __WORDSIZE == 32 #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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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( 8, _SP_REGNO, _S0_REGNO);
stxi( 4, _SP_REGNO, _RA_REGNO); stxi( 4, _SP_REGNO, _RA_REGNO);
#else #else
if (jit_regset_tstbit(_jit->function->regset, _F30)) if (jit_regset_tstbit(_jitc->function->regset, _F30))
stxi_d(136, _SP_REGNO, _F30_REGNO); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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(16, _SP_REGNO, _S0_REGNO);
stxi( 8, _SP_REGNO, _RA_REGNO); stxi( 8, _SP_REGNO, _RA_REGNO);
#endif #endif
@ -2853,7 +2853,7 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
movr(_BP_REGNO, _SP_REGNO); movr(_BP_REGNO, _SP_REGNO);
/* alloca */ /* alloca */
subi(_SP_REGNO, _SP_REGNO, _jit->function->stack); subi(_SP_REGNO, _SP_REGNO, _jitc->function->stack);
} }
static void static void
@ -2862,71 +2862,71 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
/* callee save registers */ /* callee save registers */
movr(_SP_REGNO, _BP_REGNO); movr(_SP_REGNO, _BP_REGNO);
#if __WORDSIZE == 32 #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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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(_S0_REGNO, _SP_REGNO, 8);
ldxi(_RA_REGNO, _SP_REGNO, 4); ldxi(_RA_REGNO, _SP_REGNO, 4);
#else #else
if (jit_regset_tstbit(_jit->function->regset, _F30)) if (jit_regset_tstbit(_jitc->function->regset, _F30))
ldxi_d(_F30_REGNO, _SP_REGNO, 136); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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(_S0_REGNO, _SP_REGNO, 16);
ldxi(_RA_REGNO, _SP_REGNO, 8); ldxi(_RA_REGNO, _SP_REGNO, 8);
#endif #endif

View file

@ -109,7 +109,7 @@ jit_get_cpu(void)
void void
_jit_init(jit_state_t *_jit) _jit_init(jit_state_t *_jit)
{ {
_jit->reglen = jit_size(_rvs) - 1; _jitc->reglen = jit_size(_rvs) - 1;
jit_carry = _NOREG; jit_carry = _NOREG;
} }
@ -118,51 +118,51 @@ _jit_prolog(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
if (_jit->function) if (_jitc->function)
jit_epilog(); jit_epilog();
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0); assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
jit_regset_set_ui(_jit->regsav, 0); jit_regset_set_ui(_jitc->regsav, 0);
offset = _jit->functions.offset; offset = _jitc->functions.offset;
if (offset >= _jit->functions.length) { if (offset >= _jitc->functions.length) {
_jit->functions.ptr = realloc(_jit->functions.ptr, _jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jit->functions.length + 16) * (_jitc->functions.length + 16) *
sizeof(jit_function_t)); 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)); 16 * sizeof(jit_function_t));
_jit->functions.length += 16; _jitc->functions.length += 16;
} }
_jit->function = _jit->functions.ptr + _jit->functions.offset++; _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
_jit->function->self.size = stack_framesize; _jitc->function->self.size = stack_framesize;
_jit->function->self.argi = _jit->function->self.argf = _jitc->function->self.argi = _jitc->function->self.argf =
_jit->function->self.aoff = _jit->function->self.alen = 0; _jitc->function->self.aoff = _jitc->function->self.alen = 0;
_jit->function->self.call = jit_call_default; _jitc->function->self.call = jit_call_default;
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t)); _jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog); _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jit->function->prolog); jit_link(_jitc->function->prolog);
_jit->function->prolog->w.w = offset; _jitc->function->prolog->w.w = offset;
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog); _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
/* u: label value /* u: label value
* v: offset in blocks vector * v: offset in blocks vector
* w: offset in functions 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_int32_t
_jit_allocai(jit_state_t *_jit, jit_int32_t length) _jit_allocai(jit_state_t *_jit, jit_int32_t length)
{ {
assert(_jit->function); assert(_jitc->function);
switch (length) { switch (length) {
case 0: case 1: break; case 0: case 1: break;
case 2: _jit->function->self.aoff &= -2; break; case 2: _jitc->function->self.aoff &= -2; break;
case 3: case 4: _jit->function->self.aoff &= -4; break; case 3: case 4: _jitc->function->self.aoff &= -4; break;
default: _jit->function->self.aoff &= -8; break; default: _jitc->function->self.aoff &= -8; break;
} }
_jit->function->self.aoff -= length; _jitc->function->self.aoff -= length;
return (_jit->function->self.aoff); return (_jitc->function->self.aoff);
} }
void void
@ -170,11 +170,11 @@ _jit_ret(jit_state_t *_jit)
{ {
jit_node_t *instr; jit_node_t *instr;
assert(_jit->function); assert(_jitc->function);
/* jump to epilog */ /* jump to epilog */
instr = jit_jmpi(); instr = jit_jmpi();
jit_patch_at(instr, _jit->function->epilog); jit_patch_at(instr, _jitc->function->epilog);
} }
void void
@ -232,10 +232,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
void void
_jit_epilog(jit_state_t *_jit) _jit_epilog(jit_state_t *_jit)
{ {
assert(_jit->function); assert(_jitc->function);
assert(_jit->function->epilog->next == NULL); assert(_jitc->function->epilog->next == NULL);
jit_link(_jit->function->epilog); jit_link(_jitc->function->epilog);
_jit->function = NULL; _jitc->function = NULL;
} }
jit_node_t * jit_node_t *
@ -243,12 +243,12 @@ _jit_arg(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
offset = (_jit->function->self.size - stack_framesize) >> 2; offset = (_jitc->function->self.size - stack_framesize) >> 2;
_jit->function->self.argi = 1; _jitc->function->self.argi = 1;
if (offset >= 4) if (offset >= 4)
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_word_t); _jitc->function->self.size += sizeof(jit_word_t);
return (jit_new_node_w(jit_code_arg, offset)); return (jit_new_node_w(jit_code_arg, offset));
} }
@ -263,21 +263,21 @@ _jit_arg_f(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
offset = (_jit->function->self.size - stack_framesize) >> 2; offset = (_jitc->function->self.size - stack_framesize) >> 2;
if (offset < 4) { if (offset < 4) {
if (!_jit->function->self.argi) { if (!_jitc->function->self.argi) {
if (offset == 0) if (offset == 0)
offset = 4; offset = 4;
else { else {
offset = 6; offset = 6;
_jit->function->self.argi = 1; _jitc->function->self.argi = 1;
} }
} }
} }
else else
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float32_t); _jitc->function->self.size += sizeof(jit_float32_t);
return (jit_new_node_w(jit_code_arg_f, offset)); 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; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.size & 7) { if (_jitc->function->self.size & 7) {
_jit->function->self.size += 4; _jitc->function->self.size += 4;
_jit->function->self.argi = 1; _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 (offset < 4) {
if (!_jit->function->self.argi) if (!_jitc->function->self.argi)
offset += 4; offset += 4;
} }
else else
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float64_t); _jitc->function->self.size += sizeof(jit_float64_t);
return (jit_new_node_w(jit_code_arg_d, offset)); 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; jit_word_t offset;
assert(_jit->function); assert(_jitc->function);
offset = _jit->function->call.size >> 2; offset = _jitc->function->call.size >> 2;
_jit->function->call.argi = 1; _jitc->function->call.argi = 1;
if (offset < 4) if (offset < 4)
jit_movr(_A0 - offset, u); jit_movr(_A0 - offset, u);
else else
jit_stxi(_jit->function->call.size, JIT_SP, u); jit_stxi(_jitc->function->call.size, JIT_SP, u);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
void void
@ -429,18 +429,18 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
jit_int32_t regno; jit_int32_t regno;
jit_word_t offset; jit_word_t offset;
assert(_jit->function); assert(_jitc->function);
offset = _jit->function->call.size >> 2; offset = _jitc->function->call.size >> 2;
++_jit->function->call.argi; ++_jitc->function->call.argi;
if (offset < 4) if (offset < 4)
jit_movi(_A0 - offset, u); jit_movi(_A0 - offset, u);
else { else {
regno = jit_get_reg(jit_class_gpr); regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u); 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_unget_reg(regno);
} }
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
void void
@ -448,19 +448,19 @@ _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
{ {
jit_word_t offset; jit_word_t offset;
assert(_jit->function); assert(_jitc->function);
offset = _jit->function->call.size >> 2; offset = _jitc->function->call.size >> 2;
if (offset < 2 && !_jit->function->call.argi) { if (offset < 2 && !_jitc->function->call.argi) {
++_jit->function->call.argf; ++_jitc->function->call.argf;
jit_movr_f(_F12 - offset, u); jit_movr_f(_F12 - offset, u);
} }
else if (offset < 4) { else if (offset < 4) {
++_jit->function->call.argi; ++_jitc->function->call.argi;
jit_movr_f_w(_A0 - offset, u); jit_movr_f_w(_A0 - offset, u);
} }
else else
jit_stxi_f(_jit->function->call.size, JIT_SP, u); jit_stxi_f(_jitc->function->call.size, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
} }
void void
@ -469,23 +469,23 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
jit_int32_t regno; jit_int32_t regno;
jit_word_t offset; jit_word_t offset;
assert(_jit->function); assert(_jitc->function);
offset = _jit->function->call.size >> 2; offset = _jitc->function->call.size >> 2;
if (offset < 2 && !_jit->function->call.argi) { if (offset < 2 && !_jitc->function->call.argi) {
++_jit->function->call.argf; ++_jitc->function->call.argf;
jit_movi_f(_F12 - offset, u); jit_movi_f(_F12 - offset, u);
} }
else if (offset < 4) { else if (offset < 4) {
++_jit->function->call.argi; ++_jitc->function->call.argi;
jit_movi_f_w(_A0 - offset, u); jit_movi_f_w(_A0 - offset, u);
} }
else { else {
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u); 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_unget_reg(regno);
} }
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
} }
void void
@ -494,26 +494,26 @@ _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
jit_bool_t adjust; jit_bool_t adjust;
jit_word_t offset; jit_word_t offset;
assert(_jit->function); assert(_jitc->function);
adjust = !!_jit->function->call.argi; adjust = !!_jitc->function->call.argi;
if (_jit->function->call.size & 7) { if (_jitc->function->call.size & 7) {
_jit->function->call.size += 4; _jitc->function->call.size += 4;
adjust = 1; adjust = 1;
} }
offset = _jit->function->call.size >> 2; offset = _jitc->function->call.size >> 2;
if (offset < 3) { if (offset < 3) {
if (adjust) { if (adjust) {
jit_movr_d_ww(_A0 - offset, _A0 - (offset + 1), u); jit_movr_d_ww(_A0 - offset, _A0 - (offset + 1), u);
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
} }
else { else {
jit_movr_d(_F12 - (offset >> 1), u); jit_movr_d(_F12 - (offset >> 1), u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
} }
} }
else else
jit_stxi_d(_jit->function->call.size, JIT_SP, u); jit_stxi_d(_jitc->function->call.size, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
} }
void void
@ -523,30 +523,30 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
jit_bool_t adjust; jit_bool_t adjust;
jit_word_t offset; jit_word_t offset;
assert(_jit->function); assert(_jitc->function);
adjust = !!_jit->function->call.argi; adjust = !!_jitc->function->call.argi;
if (_jit->function->call.size & 7) { if (_jitc->function->call.size & 7) {
_jit->function->call.size += 4; _jitc->function->call.size += 4;
adjust = 1; adjust = 1;
} }
offset = _jit->function->call.size >> 2; offset = _jitc->function->call.size >> 2;
if (offset < 3) { if (offset < 3) {
if (adjust) { if (adjust) {
jit_movi_d_ww(_A0 - offset, _A0 - (offset + 1), u); jit_movi_d_ww(_A0 - offset, _A0 - (offset + 1), u);
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
} }
else { else {
jit_movi_d(_F12 - (offset >> 1), u); jit_movi_d(_F12 - (offset >> 1), u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
} }
} }
else { else {
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u); 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_unget_reg(regno);
} }
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
} }
jit_bool_t jit_bool_t
@ -576,16 +576,16 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
{ {
jit_node_t *call; jit_node_t *call;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
jit_movr(_T9, r0); jit_movr(_T9, r0);
call = jit_callr(_T9); call = jit_callr(_T9);
call->v.w = _jit->function->self.argi; call->v.w = _jitc->function->self.argi;
call->w.w = _jit->function->self.argf; call->w.w = _jitc->function->self.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
} }
jit_node_t * jit_node_t *
@ -594,16 +594,16 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
jit_node_t *call; jit_node_t *call;
jit_node_t *node; jit_node_t *node;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
node = jit_movi(_T9, (jit_word_t)i0); node = jit_movi(_T9, (jit_word_t)i0);
call = jit_callr(_T9); call = jit_callr(_T9);
call->v.w = _jit->function->call.argi; call->v.w = _jitc->function->call.argi;
call->w.w = _jit->function->call.argf; call->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
return (node); return (node);
} }
@ -685,7 +685,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset; jit_int32_t patch_offset;
} undo; } undo;
_jit->function = NULL; _jitc->function = NULL;
jit_reglive_setup(); jit_reglive_setup();
@ -775,8 +775,8 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \ patch(word, node); \
} \ } \
break break
for (node = _jit->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jit->code.end) if (_jit->pc.uc >= _jitc->code.end)
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);
@ -1169,17 +1169,17 @@ _emit_code(jit_state_t *_jit)
calli(node->u.w); calli(node->u.w);
break; break;
case jit_code_prolog: case jit_code_prolog:
_jit->function = _jit->functions.ptr + node->w.w; _jitc->function = _jitc->functions.ptr + node->w.w;
undo.node = node; undo.node = node;
undo.word = _jit->pc.w; undo.word = _jit->pc.w;
undo.patch_offset = _jit->patches.offset; undo.patch_offset = _jitc->patches.offset;
restart_function: restart_function:
_jit->again = 0; _jitc->again = 0;
prolog(node); prolog(node);
break; break;
case jit_code_epilog: case jit_code_epilog:
assert(_jit->function == _jit->functions.ptr + node->w.w); assert(_jitc->function == _jitc->functions.ptr + node->w.w);
if (_jit->again) { if (_jitc->again) {
for (temp = undo.node->next; for (temp = undo.node->next;
temp != node; temp = temp->next) { temp != node; temp = temp->next) {
if (temp->code == jit_code_label || if (temp->code == jit_code_label ||
@ -1188,14 +1188,14 @@ _emit_code(jit_state_t *_jit)
} }
node = undo.node; node = undo.node;
_jit->pc.w = undo.word; _jit->pc.w = undo.word;
_jit->patches.offset = undo.patch_offset; _jitc->patches.offset = undo.patch_offset;
goto restart_function; goto restart_function;
} }
/* remember label is defined */ /* remember label is defined */
node->flag |= jit_flag_patch; node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w; node->u.w = _jit->pc.w;
epilog(node); epilog(node);
_jit->function = NULL; _jitc->function = NULL;
break; break;
case jit_code_movr_w_f: case jit_code_movr_w_f:
movr_w_f(rn(node->u.w), rn(node->v.w)); 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_rw
#undef case_rr #undef case_rr
for (offset = 0; offset < _jit->patches.offset; offset++) { for (offset = 0; offset < _jitc->patches.offset; offset++) {
node = _jit->patches.ptr[offset].node; node = _jitc->patches.ptr[offset].node;
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w; 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__) #if defined(__linux__)
@ -1315,15 +1315,15 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
else else
flag = node->u.n->flag; flag = node->u.n->flag;
assert(!(flag & jit_flag_patch)); assert(!(flag & jit_flag_patch));
if (_jit->patches.offset >= _jit->patches.length) { if (_jitc->patches.offset >= _jitc->patches.length) {
_jit->patches.ptr = realloc(_jit->patches.ptr, _jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jit->patches.length + 1024) * (_jitc->patches.length + 1024) *
sizeof(jit_patch_t)); 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)); 1024 * sizeof(jit_patch_t));
_jit->patches.length += 1024; _jitc->patches.length += 1024;
} }
_jit->patches.ptr[_jit->patches.offset].inst = instr; _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
_jit->patches.ptr[_jit->patches.offset].node = node; _jitc->patches.ptr[_jitc->patches.offset].node = node;
++_jit->patches.offset; ++_jitc->patches.offset;
} }

View file

@ -54,17 +54,17 @@ _jit_name(jit_state_t *_jit, char *name)
node->v.n = jit_data(name, strlen(name) + 1, 1); node->v.n = jit_data(name, strlen(name) + 1, 1);
else else
node->v.p = NULL; node->v.p = NULL;
if (_jit->note.head == NULL) if (_jitc->note.head == NULL)
_jit->note.head = _jit->note.tail = node; _jitc->note.head = _jitc->note.tail = node;
else { else {
_jit->note.tail->link = node; _jitc->note.tail->link = node;
_jit->note.tail = node; _jitc->note.tail = node;
} }
++_jit->note.length; ++_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 */ /* remember previous note is invalid due to name change */
_jit->note.note = NULL; _jitc->note.note = NULL;
return (_jit->note.name = node); return (_jitc->note.name = node);
} }
jit_node_t * jit_node_t *
@ -78,20 +78,20 @@ _jit_note(jit_state_t *_jit, char *name, int line)
else else
node->v.p = NULL; node->v.p = NULL;
node->w.w = line; node->w.w = line;
if (_jit->note.head == NULL) if (_jitc->note.head == NULL)
_jit->note.head = _jit->note.tail = node; _jitc->note.head = _jitc->note.tail = node;
else { else {
_jit->note.tail->link = node; _jitc->note.tail->link = node;
_jit->note.tail = node; _jitc->note.tail = node;
} }
if (_jit->note.note == NULL || if (_jitc->note.note == NULL ||
(name == NULL && _jit->note.note != NULL) || (name == NULL && _jitc->note.note != NULL) ||
(name != NULL && _jit->note.note == NULL) || (name != NULL && _jitc->note.note == NULL) ||
(name != NULL && _jit->note.note != NULL && (name != NULL && _jitc->note.note != NULL &&
strcmp(name, (char *)_jit->data.ptr + _jit->note.note->v.n->u.w))) strcmp(name, (char *)_jit->data.ptr + _jitc->note.note->v.n->u.w)))
_jit->note.size += sizeof(jit_line_t); _jitc->note.size += sizeof(jit_line_t);
_jit->note.size += sizeof(jit_int32_t) * 2; _jitc->note.size += sizeof(jit_int32_t) * 2;
return (_jit->note.note = node); return (_jitc->note.note = node);
} }
void void
@ -105,11 +105,11 @@ _jit_annotate(jit_state_t *_jit)
jit_word_t line_offset; jit_word_t line_offset;
/* initialize pointers in mmaped data area */ /* 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; _jit->note.length = 0;
note = NULL; 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) if (node->code == jit_code_name)
note = new_note(node->u.p, node->v.p ? node->v.n->u.p : NULL); note = new_note(node->u.p, node->v.p ? node->v.n->u.p : NULL);
else if (node->v.p) { 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++) { for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
note = _jit->note.ptr + note_offset; note = _jit->note.ptr + note_offset;
length = sizeof(jit_line_t) * note->length; length = sizeof(jit_line_t) * note->length;
assert(_jit->note.base + length < _jit->data.ptr + _jit->data.length); assert(_jitc->note.base + length < _jit->data.ptr + _jit->data.length);
memcpy(_jit->note.base, note->lines, length); memcpy(_jitc->note.base, note->lines, length);
free(note->lines); free(note->lines);
note->lines = (jit_line_t *)_jit->note.base; note->lines = (jit_line_t *)_jitc->note.base;
_jit->note.base += length; _jitc->note.base += length;
} }
/* relocate offset and line number information */ /* 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++) { for (line_offset = 0; line_offset < note->length; line_offset++) {
line = note->lines + line_offset; line = note->lines + line_offset;
length = sizeof(jit_int32_t) * line->length; length = sizeof(jit_int32_t) * line->length;
assert(_jit->note.base + length < assert(_jitc->note.base + length <
_jit->data.ptr + _jit->data.length); _jit->data.ptr + _jit->data.length);
memcpy(_jit->note.base, line->linenos, length); memcpy(_jitc->note.base, line->linenos, length);
free(line->linenos); free(line->linenos);
line->linenos = (jit_int32_t *)_jit->note.base; line->linenos = (jit_int32_t *)_jitc->note.base;
_jit->note.base += length; _jitc->note.base += length;
assert(_jit->note.base + length < assert(_jitc->note.base + length <
_jit->data.ptr + _jit->data.length); _jit->data.ptr + _jit->data.length);
memcpy(_jit->note.base, line->offsets, length); memcpy(_jitc->note.base, line->offsets, length);
free(line->offsets); free(line->offsets);
line->offsets = (jit_int32_t *)_jit->note.base; line->offsets = (jit_int32_t *)_jitc->note.base;
_jit->note.base += length; _jitc->note.base += length;
} }
} }
} }
@ -252,8 +252,8 @@ _new_note(jit_state_t *_jit, jit_uint8_t *code, char *name)
assert(code >= prev->code); assert(code >= prev->code);
prev->size = code - prev->code; prev->size = code - prev->code;
} }
note = (jit_note_t *)_jit->note.base; note = (jit_note_t *)_jitc->note.base;
_jit->note.base += sizeof(jit_note_t); _jitc->note.base += sizeof(jit_note_t);
++_jit->note.length; ++_jit->note.length;
note->code = code; note->code = code;
note->name = name; note->name = name;

View file

@ -2471,20 +2471,20 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
unsigned long regno; unsigned long regno;
jit_word_t offset; jit_word_t offset;
_jit->function->stack = ((_jit->function->self.alen + _jitc->function->stack = ((_jitc->function->self.alen +
_jit->function->self.size - _jitc->function->self.size -
_jit->function->self.aoff) + 15) & -16; _jitc->function->self.aoff) + 15) & -16;
/* return address */ /* return address */
MFLR(_R0_REGNO); MFLR(_R0_REGNO);
/* save any clobbered callee save gpr register */ /* 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) if (regno == ULONG_MAX || regno > _R31)
regno = _R31; /* aka _FP_REGNO */ regno = _R31; /* aka _FP_REGNO */
STMW(rn(regno), _SP_REGNO, -fpr_save_area - (32 * 4) + rn(regno) * 4); STMW(rn(regno), _SP_REGNO, -fpr_save_area - (32 * 4) + rn(regno) * 4);
for (offset = 0; offset < 8; offset++) { 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)); 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 */ * alloca < %r31-80 */
movr(_FP_REGNO, _SP_REGNO); movr(_FP_REGNO, _SP_REGNO);
STWU(_SP_REGNO, _SP_REGNO, -_jit->function->stack); STWU(_SP_REGNO, _SP_REGNO, -_jitc->function->stack);
} }
static void static void
@ -2508,12 +2508,12 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
MTLR(_R0_REGNO); 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) if (regno == ULONG_MAX || regno > _R31)
regno = _R31; /* aka _FP_REGNO */ regno = _R31; /* aka _FP_REGNO */
LMW(rn(regno), _SP_REGNO, -fpr_save_area - (32 * 4) + rn(regno) * 4); LMW(rn(regno), _SP_REGNO, -fpr_save_area - (32 * 4) + rn(regno) * 4);
for (offset = 0; offset < 8; offset++) { 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); ldxi_d(rn(_F14 + offset), _SP_REGNO, -fpr_save_area + offset * 8);
} }
BLR(); BLR();

View file

@ -114,7 +114,7 @@ jit_get_cpu(void)
void void
_jit_init(jit_state_t *_jit) _jit_init(jit_state_t *_jit)
{ {
_jit->reglen = jit_size(_rvs) - 1; _jitc->reglen = jit_size(_rvs) - 1;
} }
void void
@ -122,53 +122,53 @@ _jit_prolog(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
if (_jit->function) if (_jitc->function)
jit_epilog(); jit_epilog();
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0); assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
jit_regset_set_ui(_jit->regsav, 0); jit_regset_set_ui(_jitc->regsav, 0);
offset = _jit->functions.offset; offset = _jitc->functions.offset;
if (offset >= _jit->functions.length) { if (offset >= _jitc->functions.length) {
_jit->functions.ptr = realloc(_jit->functions.ptr, _jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jit->functions.length + 16) * (_jitc->functions.length + 16) *
sizeof(jit_function_t)); 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)); 16 * sizeof(jit_function_t));
_jit->functions.length += 16; _jitc->functions.length += 16;
} }
_jit->function = _jit->functions.ptr + _jit->functions.offset++; _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
_jit->function->self.size = params_offset; _jitc->function->self.size = params_offset;
_jit->function->self.argi = _jit->function->self.argf = _jitc->function->self.argi = _jitc->function->self.argf =
_jit->function->self.alen = 0; _jitc->function->self.alen = 0;
/* float conversion */ /* float conversion */
_jit->function->self.aoff = alloca_offset - 8; _jitc->function->self.aoff = alloca_offset - 8;
_jit->function->self.call = jit_call_default; _jitc->function->self.call = jit_call_default;
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t)); _jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog); _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jit->function->prolog); jit_link(_jitc->function->prolog);
_jit->function->prolog->w.w = offset; _jitc->function->prolog->w.w = offset;
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog); _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
/* u: label value /* u: label value
* v: offset in blocks vector * v: offset in blocks vector
* w: offset in functions 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_int32_t
_jit_allocai(jit_state_t *_jit, jit_int32_t length) _jit_allocai(jit_state_t *_jit, jit_int32_t length)
{ {
assert(_jit->function); assert(_jitc->function);
switch (length) { switch (length) {
case 0: case 1: break; case 0: case 1: break;
case 2: _jit->function->self.aoff &= -2; break; case 2: _jitc->function->self.aoff &= -2; break;
case 3: case 4: _jit->function->self.aoff &= -4; break; case 3: case 4: _jitc->function->self.aoff &= -4; break;
default: _jit->function->self.aoff &= -8; break; default: _jitc->function->self.aoff &= -8; break;
} }
_jit->function->self.aoff -= length; _jitc->function->self.aoff -= length;
return (_jit->function->self.aoff); return (_jitc->function->self.aoff);
} }
void void
@ -176,11 +176,11 @@ _jit_ret(jit_state_t *_jit)
{ {
jit_node_t *instr; jit_node_t *instr;
assert(_jit->function); assert(_jitc->function);
/* jump to epilog */ /* jump to epilog */
instr = jit_jmpi(); instr = jit_jmpi();
jit_patch_at(instr, _jit->function->epilog); jit_patch_at(instr, _jitc->function->epilog);
} }
void void
@ -238,22 +238,22 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
void void
_jit_epilog(jit_state_t *_jit) _jit_epilog(jit_state_t *_jit)
{ {
assert(_jit->function); assert(_jitc->function);
assert(_jit->function->epilog->next == NULL); assert(_jitc->function->epilog->next == NULL);
jit_link(_jit->function->epilog); jit_link(_jitc->function->epilog);
_jit->function = NULL; _jitc->function = NULL;
} }
jit_node_t * jit_node_t *
_jit_arg(jit_state_t *_jit) _jit_arg(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argi < 8) if (_jitc->function->self.argi < 8)
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
else else
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_word_t); _jitc->function->self.size += sizeof(jit_word_t);
return (jit_new_node_w(jit_code_arg, offset)); return (jit_new_node_w(jit_code_arg, offset));
} }
@ -267,12 +267,12 @@ jit_node_t *
_jit_arg_f(jit_state_t *_jit) _jit_arg_f(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argf < 13) if (_jitc->function->self.argf < 13)
offset = _jit->function->self.argf++; offset = _jitc->function->self.argf++;
else else
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float32_t); _jitc->function->self.size += sizeof(jit_float32_t);
return (jit_new_node_w(jit_code_arg_f, offset)); 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_arg_d(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argf < 13) if (_jitc->function->self.argf < 13)
offset = _jit->function->self.argf++; offset = _jitc->function->self.argf++;
else else
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float64_t); _jitc->function->self.size += sizeof(jit_float64_t);
return (jit_new_node_w(jit_code_arg_d, offset)); 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 void
_jit_pushargr(jit_state_t *_jit, jit_int32_t u) _jit_pushargr(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argi < 8) { if (_jitc->function->call.argi < 8) {
jit_movr(JIT_RA0 - _jit->function->call.argi, u); jit_movr(JIT_RA0 - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else else
jit_stxi(_jit->function->call.size + params_offset, JIT_SP, u); jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, u);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
void void
_jit_pushargi(jit_state_t *_jit, jit_word_t u) _jit_pushargi(jit_state_t *_jit, jit_word_t u)
{ {
jit_int32_t regno; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argi < 8) { if (_jitc->function->call.argi < 8) {
jit_movi(JIT_RA0 - _jit->function->call.argi, u); jit_movi(JIT_RA0 - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
regno = jit_get_reg(jit_class_gpr); regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u); 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_unget_reg(regno);
} }
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
void void
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u) _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argf < 13) { if (_jitc->function->call.argf < 13) {
jit_movr_d(JIT_FA0 - _jit->function->call.argf, u); jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
if (!(_jit->function->call.call & jit_call_varargs)) { if (!(_jitc->function->call.call & jit_call_varargs)) {
/* in case of excess arguments */ /* in case of excess arguments */
if (_jit->function->call.argi < 8) if (_jitc->function->call.argi < 8)
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
return; return;
} }
} }
if (_jit->function->call.argi < 8) { if (_jitc->function->call.argi < 8) {
/* use reserved 8 bytes area */ /* use reserved 8 bytes area */
jit_stxi_d(alloca_offset - 8, JIT_FP, u); 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); alloca_offset - 8);
_jit->function->call.argi++; _jitc->function->call.argi++;
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP, jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
alloca_offset - 4); alloca_offset - 4);
_jit->function->call.argi++; _jitc->function->call.argi++;
} }
else else
jit_stxi_f(_jit->function->call.size + params_offset, JIT_SP, u); jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
} }
void void
@ -486,64 +486,64 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
{ {
jit_int32_t regno; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argf < 13) { if (_jitc->function->call.argf < 13) {
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u); jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
if (!(_jit->function->call.call & jit_call_varargs)) { if (!(_jitc->function->call.call & jit_call_varargs)) {
/* in case of excess arguments */ /* in case of excess arguments */
if (_jit->function->call.argi < 8) if (_jitc->function->call.argi < 8)
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
return; return;
} }
} }
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u); jit_movi_f(regno, u);
if (_jit->function->call.argi < 8) { if (_jitc->function->call.argi < 8) {
/* use reserved 8 bytes area */ /* use reserved 8 bytes area */
jit_stxi_d(alloca_offset - 8, JIT_FP, regno); 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); alloca_offset - 8);
_jit->function->call.argi++; _jitc->function->call.argi++;
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP, jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
alloca_offset - 4); alloca_offset - 4);
_jit->function->call.argi++; _jitc->function->call.argi++;
} }
else else
jit_stxi_f(_jit->function->call.size + params_offset, JIT_SP, regno); jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, regno);
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
jit_unget_reg(regno); jit_unget_reg(regno);
} }
void void
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u) _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argf < 13) { if (_jitc->function->call.argf < 13) {
jit_movr_d(JIT_FA0 - _jit->function->call.argf, u); jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
if (!(_jit->function->call.call & jit_call_varargs)) { if (!(_jitc->function->call.call & jit_call_varargs)) {
/* in case of excess arguments */ /* in case of excess arguments */
if (_jit->function->call.argi < 8) if (_jitc->function->call.argi < 8)
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
return; return;
} }
} }
if (_jit->function->call.argi < 8) { if (_jitc->function->call.argi < 8) {
/* use reserved 8 bytes area */ /* use reserved 8 bytes area */
jit_stxi_d(alloca_offset - 8, JIT_FP, u); 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); alloca_offset - 8);
_jit->function->call.argi++; _jitc->function->call.argi++;
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP, jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
alloca_offset - 4); alloca_offset - 4);
_jit->function->call.argi++; _jitc->function->call.argi++;
} }
else else
jit_stxi_d(_jit->function->call.size + params_offset, JIT_SP, u); jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
} }
void void
@ -551,33 +551,33 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
{ {
jit_int32_t regno; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->call.argf < 13) { if (_jitc->function->call.argf < 13) {
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u); jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
if (!(_jit->function->call.call & jit_call_varargs)) { if (!(_jitc->function->call.call & jit_call_varargs)) {
/* in case of excess arguments */ /* in case of excess arguments */
if (_jit->function->call.argi < 8) if (_jitc->function->call.argi < 8)
_jit->function->call.argi += 2; _jitc->function->call.argi += 2;
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
return; return;
} }
} }
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u); jit_movi_d(regno, u);
if (_jit->function->call.argi < 8) { if (_jitc->function->call.argi < 8) {
/* use reserved 8 bytes area */ /* use reserved 8 bytes area */
jit_stxi_d(alloca_offset - 8, JIT_FP, regno); 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); alloca_offset - 8);
_jit->function->call.argi++; _jitc->function->call.argi++;
jit_ldxi(JIT_RA0 - _jit->function->call.argi, JIT_FP, jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
alloca_offset - 4); alloca_offset - 4);
_jit->function->call.argi++; _jitc->function->call.argi++;
} }
else else
jit_stxi_d(_jit->function->call.size + params_offset, JIT_SP, regno); jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, regno);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
jit_unget_reg(regno); jit_unget_reg(regno);
} }
@ -605,28 +605,28 @@ void
_jit_finishr(jit_state_t *_jit, jit_int32_t r0) _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
{ {
jit_node_t *call; jit_node_t *call;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
call = jit_callr(r0); call = jit_callr(r0);
call->v.w = _jit->function->call.argi; call->v.w = _jitc->function->call.argi;
call->w.w = _jit->function->call.argf; call->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = 0; _jitc->function->call.argi = _jitc->function->call.argf = 0;
_jit->prepare = 0; _jitc->prepare = 0;
} }
jit_node_t * jit_node_t *
_jit_finishi(jit_state_t *_jit, jit_pointer_t i0) _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
{ {
jit_node_t *node; jit_node_t *node;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
node = jit_calli(i0); node = jit_calli(i0);
node->v.w = _jit->function->call.argi; node->v.w = _jitc->function->call.argi;
node->w.w = _jit->function->call.argf; node->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = 0; _jitc->function->call.argi = _jitc->function->call.argf = 0;
_jit->prepare = 0; _jitc->prepare = 0;
return (node); return (node);
} }
@ -707,7 +707,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset; jit_int32_t patch_offset;
} undo; } undo;
_jit->function = NULL; _jitc->function = NULL;
jit_reglive_setup(); jit_reglive_setup();
@ -798,8 +798,8 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \ patch(word, node); \
} \ } \
break break
for (node = _jit->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jit->code.end) if (_jit->pc.uc >= _jitc->code.end)
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);
@ -1169,17 +1169,17 @@ _emit_code(jit_state_t *_jit)
calli(node->u.w); calli(node->u.w);
break; break;
case jit_code_prolog: case jit_code_prolog:
_jit->function = _jit->functions.ptr + node->w.w; _jitc->function = _jitc->functions.ptr + node->w.w;
undo.node = node; undo.node = node;
undo.word = _jit->pc.w; undo.word = _jit->pc.w;
undo.patch_offset = _jit->patches.offset; undo.patch_offset = _jitc->patches.offset;
restart_function: restart_function:
_jit->again = 0; _jitc->again = 0;
prolog(node); prolog(node);
break; break;
case jit_code_epilog: case jit_code_epilog:
assert(_jit->function == _jit->functions.ptr + node->w.w); assert(_jitc->function == _jitc->functions.ptr + node->w.w);
if (_jit->again) { if (_jitc->again) {
for (temp = undo.node->next; for (temp = undo.node->next;
temp != node; temp = temp->next) { temp != node; temp = temp->next) {
if (temp->code == jit_code_label || if (temp->code == jit_code_label ||
@ -1188,14 +1188,14 @@ _emit_code(jit_state_t *_jit)
} }
node = undo.node; node = undo.node;
_jit->pc.w = undo.word; _jit->pc.w = undo.word;
_jit->patches.offset = undo.patch_offset; _jitc->patches.offset = undo.patch_offset;
goto restart_function; goto restart_function;
} }
/* remember label is defined */ /* remember label is defined */
node->flag |= jit_flag_patch; node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w; node->u.w = _jit->pc.w;
epilog(node); epilog(node);
_jit->function = NULL; _jitc->function = NULL;
break; break;
case jit_code_live: case jit_code_live:
case jit_code_arg: case jit_code_arg:
@ -1219,10 +1219,10 @@ _emit_code(jit_state_t *_jit)
#undef case_rw #undef case_rw
#undef case_rr #undef case_rr
for (offset = 0; offset < _jit->patches.offset; offset++) { for (offset = 0; offset < _jitc->patches.offset; offset++) {
node = _jit->patches.ptr[offset].node; node = _jitc->patches.ptr[offset].node;
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w; 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); __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 else
flag = node->u.n->flag; flag = node->u.n->flag;
assert(!(flag & jit_flag_patch)); assert(!(flag & jit_flag_patch));
if (_jit->patches.offset >= _jit->patches.length) { if (_jitc->patches.offset >= _jitc->patches.length) {
_jit->patches.ptr = realloc(_jit->patches.ptr, _jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jit->patches.length + 1024) * (_jitc->patches.length + 1024) *
sizeof(jit_patch_t)); 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)); 1024 * sizeof(jit_patch_t));
_jit->patches.length += 1024; _jitc->patches.length += 1024;
} }
_jit->patches.ptr[_jit->patches.offset].inst = instr; _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
_jit->patches.ptr[_jit->patches.offset].node = node; _jitc->patches.ptr[_jitc->patches.offset].node = node;
++_jit->patches.offset; ++_jitc->patches.offset;
} }

View file

@ -227,7 +227,7 @@ _jit_print(jit_state_t *_jit)
jit_int32_t offset; jit_int32_t offset;
first = 0; first = 0;
for (node = _jit->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (!first) if (!first)
print_chr('\n'); print_chr('\n');
else else
@ -237,8 +237,8 @@ _jit_print(jit_state_t *_jit)
print_chr('L'); print_chr('L');
print_dec(node->v.w); print_dec(node->v.w);
print_chr(':'); print_chr(':');
block = _jit->blocks.ptr + node->v.w; block = _jitc->blocks.ptr + node->v.w;
for (offset = 0; offset < _jit->reglen; offset++) { for (offset = 0; offset < _jitc->reglen; offset++) {
if (jit_regset_tstbit(block->reglive, offset)) { if (jit_regset_tstbit(block->reglive, offset)) {
print_chr(' '); print_chr(' ');
print_reg(offset); print_reg(offset);

View file

@ -1619,28 +1619,28 @@ static void
_prolog(jit_state_t *_jit, jit_node_t *node) _prolog(jit_state_t *_jit, jit_node_t *node)
{ {
/* align at 16 bytes boundary */ /* align at 16 bytes boundary */
_jit->function->stack = ((stack_framesize + _jitc->function->stack = ((stack_framesize +
_jit->function->self.alen - _jitc->function->self.alen -
_jit->function->self.aoff) + 15) & -16; _jitc->function->self.aoff) + 15) & -16;
SAVEI(_SP_REGNO, -_jit->function->stack, _SP_REGNO); SAVEI(_SP_REGNO, -_jitc->function->stack, _SP_REGNO);
/* (most) other backends do not save incoming arguments, so, /* (most) other backends do not save incoming arguments, so,
* only save locals here */ * 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); 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); 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); 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); 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); 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); 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); 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); 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, /* (most) other backends do not save incoming arguments, so,
* only save locals here */ * 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); 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); 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); 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); 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); 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); 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); 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); ldxi(_L7_REGNO, _SP_REGNO, 28);
RESTOREI(0, 0, 0); RESTOREI(0, 0, 0);
RETL(); RETL();

View file

@ -95,7 +95,7 @@ jit_get_cpu(void)
void void
_jit_init(jit_state_t *_jit) _jit_init(jit_state_t *_jit)
{ {
_jit->reglen = jit_size(_rvs) - 1; _jitc->reglen = jit_size(_rvs) - 1;
} }
void void
@ -103,53 +103,53 @@ _jit_prolog(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
if (_jit->function) if (_jitc->function)
jit_epilog(); jit_epilog();
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0); assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
jit_regset_set_ui(_jit->regsav, 0); jit_regset_set_ui(_jitc->regsav, 0);
offset = _jit->functions.offset; offset = _jitc->functions.offset;
if (offset >= _jit->functions.length) { if (offset >= _jitc->functions.length) {
_jit->functions.ptr = realloc(_jit->functions.ptr, _jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jit->functions.length + 16) * (_jitc->functions.length + 16) *
sizeof(jit_function_t)); 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)); 16 * sizeof(jit_function_t));
_jit->functions.length += 16; _jitc->functions.length += 16;
} }
_jit->function = _jit->functions.ptr + _jit->functions.offset++; _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
_jit->function->self.size = stack_framesize; _jitc->function->self.size = stack_framesize;
_jit->function->self.argi = _jit->function->self.argf = _jitc->function->self.argi = _jitc->function->self.argf =
_jit->function->self.aoff = _jit->function->self.alen = 0; _jitc->function->self.aoff = _jitc->function->self.alen = 0;
/* float conversion */ /* float conversion */
_jit->function->self.aoff = -8; _jitc->function->self.aoff = -8;
_jit->function->self.call = jit_call_default; _jitc->function->self.call = jit_call_default;
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t)); _jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog); _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jit->function->prolog); jit_link(_jitc->function->prolog);
_jit->function->prolog->w.w = offset; _jitc->function->prolog->w.w = offset;
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog); _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
/* u: label value /* u: label value
* v: offset in blocks vector * v: offset in blocks vector
* w: offset in functions 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_int32_t
_jit_allocai(jit_state_t *_jit, jit_int32_t length) _jit_allocai(jit_state_t *_jit, jit_int32_t length)
{ {
assert(_jit->function); assert(_jitc->function);
switch (length) { switch (length) {
case 0: case 1: break; case 0: case 1: break;
case 2: _jit->function->self.aoff &= -2; break; case 2: _jitc->function->self.aoff &= -2; break;
case 3: case 4: _jit->function->self.aoff &= -4; break; case 3: case 4: _jitc->function->self.aoff &= -4; break;
default: _jit->function->self.aoff &= -8; break; default: _jitc->function->self.aoff &= -8; break;
} }
_jit->function->self.aoff -= length; _jitc->function->self.aoff -= length;
return (_jit->function->self.aoff); return (_jitc->function->self.aoff);
} }
void void
@ -157,11 +157,11 @@ _jit_ret(jit_state_t *_jit)
{ {
jit_node_t *instr; jit_node_t *instr;
assert(_jit->function); assert(_jitc->function);
/* jump to epilog */ /* jump to epilog */
instr = jit_jmpi(); instr = jit_jmpi();
jit_patch_at(instr, _jit->function->epilog); jit_patch_at(instr, _jitc->function->epilog);
} }
void void
@ -218,22 +218,22 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
void void
_jit_epilog(jit_state_t *_jit) _jit_epilog(jit_state_t *_jit)
{ {
assert(_jit->function); assert(_jitc->function);
assert(_jit->function->epilog->next == NULL); assert(_jitc->function->epilog->next == NULL);
jit_link(_jit->function->epilog); jit_link(_jitc->function->epilog);
_jit->function = NULL; _jitc->function = NULL;
} }
jit_node_t * jit_node_t *
_jit_arg(jit_state_t *_jit) _jit_arg(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argi < 6) if (_jitc->function->self.argi < 6)
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
else { else {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_word_t); _jitc->function->self.size += sizeof(jit_word_t);
} }
return (jit_new_node_w(jit_code_arg, offset)); return (jit_new_node_w(jit_code_arg, offset));
} }
@ -248,12 +248,12 @@ jit_node_t *
_jit_arg_f(jit_state_t *_jit) _jit_arg_f(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argi < 6) if (_jitc->function->self.argi < 6)
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
else { else {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float32_t); _jitc->function->self.size += sizeof(jit_float32_t);
} }
return (jit_new_node_w(jit_code_arg_f, offset)); 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_arg_d(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.argi < 5) { if (_jitc->function->self.argi < 5) {
offset = _jit->function->self.argi; offset = _jitc->function->self.argi;
_jit->function->self.argi += 2; _jitc->function->self.argi += 2;
} }
else if (_jit->function->self.argi < 6) { else if (_jitc->function->self.argi < 6) {
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
_jit->function->self.size += sizeof(jit_float32_t); _jitc->function->self.size += sizeof(jit_float32_t);
} }
else { else {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float64_t); _jitc->function->self.size += sizeof(jit_float64_t);
} }
return (jit_new_node_w(jit_code_arg_d, offset)); 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 void
_jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) _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) { if (v->u.w < 6) {
jit_stxi(-4, JIT_FP, _I0 + v->u.w); jit_stxi(-4, JIT_FP, _I0 + v->u.w);
jit_ldxi_f(u, JIT_FP, -4); 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 void
_jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) _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) { if (v->u.w < 5) {
jit_stxi(-8, JIT_FP, _I0 + v->u.w); jit_stxi(-8, JIT_FP, _I0 + v->u.w);
jit_stxi(-4, JIT_FP, _I0 + v->u.w + 1); 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 void
_jit_pushargr(jit_state_t *_jit, jit_int32_t u) _jit_pushargr(jit_state_t *_jit, jit_int32_t u)
{ {
if (_jit->function->call.argi < 6) { if (_jitc->function->call.argi < 6) {
jit_movr(_O0 + _jit->function->call.argi, u); jit_movr(_O0 + _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
jit_stxi(_jit->function->call.size + stack_framesize, JIT_SP, u); jit_stxi(_jitc->function->call.size + stack_framesize, JIT_SP, u);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
} }
@ -394,30 +394,30 @@ void
_jit_pushargi(jit_state_t *_jit, jit_word_t u) _jit_pushargi(jit_state_t *_jit, jit_word_t u)
{ {
jit_int32_t regno; jit_int32_t regno;
if (_jit->function->call.argi < 6) { if (_jitc->function->call.argi < 6) {
jit_movi(_O0 + _jit->function->call.argi, u); jit_movi(_O0 + _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
regno = jit_get_reg(jit_class_gpr); regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u); 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_unget_reg(regno);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
} }
} }
void void
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u) _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_stxi_f(-4, JIT_FP, u);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -4); jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -4);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
jit_stxi_f(_jit->function->call.size + stack_framesize, JIT_SP, u); jit_stxi_f(_jitc->function->call.size + stack_framesize, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float32_t); _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; jit_int32_t regno;
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u); 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_stxi_f(-4, JIT_FP, regno);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -4); jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -4);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else { else {
jit_stxi_f(_jit->function->call.size + stack_framesize, JIT_SP, regno); jit_stxi_f(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
_jit->function->call.size += sizeof(jit_float32_t); _jitc->function->call.size += sizeof(jit_float32_t);
} }
jit_unget_reg(regno); jit_unget_reg(regno);
} }
@ -442,22 +442,22 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
void void
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u) _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_stxi_d(-8, JIT_FP, u);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8); jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
jit_ldxi(_O0 + _jit->function->call.argi + 1, JIT_FP, -4); jit_ldxi(_O0 + _jitc->function->call.argi + 1, JIT_FP, -4);
_jit->function->call.argi += 2; _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_stxi_f(-8, JIT_FP, u);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8); jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
++_jit->function->call.argi; ++_jitc->function->call.argi;
jit_stxi_f(stack_framesize, JIT_SP, u + 1); 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 { else {
jit_stxi_d(_jit->function->call.size + stack_framesize, JIT_SP, u); jit_stxi_d(_jitc->function->call.size + stack_framesize, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float64_t); _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; jit_int32_t regno;
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u); 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_stxi_d(-8, JIT_FP, regno);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8); jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
jit_ldxi(_O0 + _jit->function->call.argi + 1, JIT_FP, -4); jit_ldxi(_O0 + _jitc->function->call.argi + 1, JIT_FP, -4);
_jit->function->call.argi += 2; _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_stxi_f(-8, JIT_FP, regno);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8); jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
++_jit->function->call.argi; ++_jitc->function->call.argi;
jit_stxi_f(stack_framesize, JIT_SP, regno + 1); 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 { else {
jit_stxi_d(_jit->function->call.size + stack_framesize, JIT_SP, regno); jit_stxi_d(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
} }
jit_unget_reg(regno); jit_unget_reg(regno);
} }
@ -508,15 +508,15 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
{ {
jit_node_t *call; jit_node_t *call;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
call = jit_callr(r0); call = jit_callr(r0);
call->v.w = _jit->function->self.argi; call->v.w = _jitc->function->self.argi;
call->w.w = _jit->function->self.argf; call->w.w = _jitc->function->self.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
} }
jit_node_t * jit_node_t *
@ -524,15 +524,15 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
{ {
jit_node_t *node; jit_node_t *node;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
node = jit_calli(i0); node = jit_calli(i0);
node->v.w = _jit->function->call.argi; node->v.w = _jitc->function->call.argi;
node->w.w = _jit->function->call.argf; node->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
return (node); return (node);
} }
@ -595,7 +595,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset; jit_int32_t patch_offset;
} undo; } undo;
_jit->function = NULL; _jitc->function = NULL;
jit_reglive_setup(); jit_reglive_setup();
@ -692,8 +692,8 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \ patch(word, node); \
} \ } \
break break
for (node = _jit->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jit->code.end) if (_jit->pc.uc >= _jitc->code.end)
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);
@ -1059,17 +1059,17 @@ _emit_code(jit_state_t *_jit)
calli(node->u.w); calli(node->u.w);
break; break;
case jit_code_prolog: case jit_code_prolog:
_jit->function = _jit->functions.ptr + node->w.w; _jitc->function = _jitc->functions.ptr + node->w.w;
undo.node = node; undo.node = node;
undo.word = _jit->pc.w; undo.word = _jit->pc.w;
undo.patch_offset = _jit->patches.offset; undo.patch_offset = _jitc->patches.offset;
restart_function: restart_function:
_jit->again = 0; _jitc->again = 0;
prolog(node); prolog(node);
break; break;
case jit_code_epilog: case jit_code_epilog:
assert(_jit->function == _jit->functions.ptr + node->w.w); assert(_jitc->function == _jitc->functions.ptr + node->w.w);
if (_jit->again) { if (_jitc->again) {
for (temp = undo.node->next; for (temp = undo.node->next;
temp != node; temp = temp->next) { temp != node; temp = temp->next) {
if (temp->code == jit_code_label || if (temp->code == jit_code_label ||
@ -1078,14 +1078,14 @@ _emit_code(jit_state_t *_jit)
} }
node = undo.node; node = undo.node;
_jit->pc.w = undo.word; _jit->pc.w = undo.word;
_jit->patches.offset = undo.patch_offset; _jitc->patches.offset = undo.patch_offset;
goto restart_function; goto restart_function;
} }
/* remember label is defined */ /* remember label is defined */
node->flag |= jit_flag_patch; node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w; node->u.w = _jit->pc.w;
epilog(node); epilog(node);
_jit->function = NULL; _jitc->function = NULL;
break; break;
case jit_code_live: case jit_code_live:
case jit_code_arg: case jit_code_arg:
@ -1112,10 +1112,10 @@ _emit_code(jit_state_t *_jit)
#undef case_rw #undef case_rw
#undef case_rr #undef case_rr
for (offset = 0; offset < _jit->patches.offset; offset++) { for (offset = 0; offset < _jitc->patches.offset; offset++) {
node = _jit->patches.ptr[offset].node; node = _jitc->patches.ptr[offset].node;
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w; 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); return (_jit->code.ptr);
@ -1161,15 +1161,15 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
else else
flag = node->u.n->flag; flag = node->u.n->flag;
assert(!(flag & jit_flag_patch)); assert(!(flag & jit_flag_patch));
if (_jit->patches.offset >= _jit->patches.length) { if (_jitc->patches.offset >= _jitc->patches.length) {
_jit->patches.ptr = realloc(_jit->patches.ptr, _jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jit->patches.length + 1024) * (_jitc->patches.length + 1024) *
sizeof(jit_patch_t)); 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)); 1024 * sizeof(jit_patch_t));
_jit->patches.length += 1024; _jitc->patches.length += 1024;
} }
_jit->patches.ptr[_jit->patches.offset].inst = instr; _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
_jit->patches.ptr[_jit->patches.offset].node = node; _jitc->patches.ptr[_jitc->patches.offset].node = node;
++_jit->patches.offset; ++_jitc->patches.offset;
} }

View file

@ -863,22 +863,22 @@ _alui(jit_state_t *_jit, jit_int32_t code, jit_int32_t r0, jit_word_t i0)
static void static void
_save(jit_state_t *_jit, jit_int32_t r0) _save(jit_state_t *_jit, jit_int32_t r0)
{ {
if (!_jit->function->regoff[r0]) { if (!_jitc->function->regoff[r0]) {
_jit->function->regoff[r0] = jit_allocai(sizeof(jit_word_t)); _jitc->function->regoff[r0] = jit_allocai(sizeof(jit_word_t));
_jit->again = 1; _jitc->again = 1;
} }
assert(!jit_regset_tstbit(_jit->regsav, r0)); assert(!jit_regset_tstbit(_jitc->regsav, r0));
jit_regset_setbit(_jit->regsav, r0); jit_regset_setbit(_jitc->regsav, r0);
stxi(_jit->function->regoff[r0], _RBP_REGNO, r0); stxi(_jitc->function->regoff[r0], _RBP_REGNO, r0);
} }
static void static void
_load(jit_state_t *_jit, jit_int32_t r0) _load(jit_state_t *_jit, jit_int32_t r0)
{ {
assert(_jit->function->regoff[r0]); assert(_jitc->function->regoff[r0]);
assert(jit_regset_tstbit(_jit->regsav, r0)); assert(jit_regset_tstbit(_jitc->regsav, r0));
jit_regset_clrbit(_jit->regsav, r0); jit_regset_clrbit(_jitc->regsav, r0);
ldxi(r0, _RBP_REGNO, _jit->function->regoff[r0]); ldxi(r0, _RBP_REGNO, _jitc->function->regoff[r0]);
} }
static void 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)) \ if (set & (1 << rn)) \
(void)jit_get_reg(rv|jit_class_gpr|jit_class_named); \ (void)jit_get_reg(rv|jit_class_gpr|jit_class_named); \
if (sav & (1 << rn)) { \ if (sav & (1 << rn)) { \
if ( jit_regset_tstbit(_jit->regsav, rv) || \ if ( jit_regset_tstbit(_jitc->regsav, rv) || \
!jit_regset_tstbit(_jit->reglive, rv)) \ !jit_regset_tstbit(_jitc->reglive, rv)) \
sav &= ~(1 << rn); \ sav &= ~(1 << rn); \
else \ else \
save(rv); \ save(rv); \
@ -3303,39 +3303,39 @@ static void
_prolog(jit_state_t *_jit, jit_node_t *node) _prolog(jit_state_t *_jit, jit_node_t *node)
{ {
#if __WORDSIZE == 32 #if __WORDSIZE == 32
_jit->function->stack = (((_jit->function->self.alen - _jitc->function->stack = (((_jitc->function->self.alen -
_jit->function->self.aoff) + 15) & -16) + 12; _jitc->function->self.aoff) + 15) & -16) + 12;
#else #else
_jit->function->stack = (((_jit->function->self.alen - _jitc->function->stack = (((_jitc->function->self.alen -
_jit->function->self.aoff) + 15) & -16) + 8; _jitc->function->self.aoff) + 15) & -16) + 8;
#endif #endif
/* callee save registers */ /* callee save registers */
subi(_RSP_REGNO, _RSP_REGNO, stack_framesize - sizeof(jit_word_t)); subi(_RSP_REGNO, _RSP_REGNO, stack_framesize - sizeof(jit_word_t));
#if __WORDSIZE == 32 #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); 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); 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); stxi( 4, _RSP_REGNO, _RBX_REGNO);
#else #else
if (jit_regset_tstbit(_jit->function->regset, _RBX)) if (jit_regset_tstbit(_jitc->function->regset, _RBX))
stxi(40, _RSP_REGNO, _RBX_REGNO); 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); 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); 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); 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); stxi( 8, _RSP_REGNO, _R15_REGNO);
#endif #endif
stxi(0, _RSP_REGNO, _RBP_REGNO); stxi(0, _RSP_REGNO, _RBP_REGNO);
movr(_RBP_REGNO, _RSP_REGNO); movr(_RBP_REGNO, _RSP_REGNO);
/* alloca */ /* alloca */
subi(_RSP_REGNO, _RSP_REGNO, _jit->function->stack); subi(_RSP_REGNO, _RSP_REGNO, _jitc->function->stack);
} }
static void static void
@ -3344,22 +3344,22 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
/* callee save registers */ /* callee save registers */
movr(_RSP_REGNO, _RBP_REGNO); movr(_RSP_REGNO, _RBP_REGNO);
#if __WORDSIZE == 32 #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); 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); 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); ldxi(_RBX_REGNO, _RSP_REGNO, 4);
#else #else
if (jit_regset_tstbit(_jit->function->regset, _RBX)) if (jit_regset_tstbit(_jitc->function->regset, _RBX))
ldxi(_RBX_REGNO, _RSP_REGNO, 40); 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); 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); 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); 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); ldxi(_R15_REGNO, _RSP_REGNO, 8);
#endif #endif
ldxi(_RBP_REGNO, _RSP_REGNO, 0); ldxi(_RBP_REGNO, _RSP_REGNO, 0);

View file

@ -273,11 +273,11 @@ _jit_init(jit_state_t *_jit)
static jit_bool_t first = 1; static jit_bool_t first = 1;
#endif #endif
_jit->reglen = jit_size(_rvs) - 1; _jitc->reglen = jit_size(_rvs) - 1;
#if __WORDSIZE == 32 #if __WORDSIZE == 32
if (first) { if (first) {
if (!jit_cpu.sse2) { 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) if (_rvs[regno].spec & jit_class_xpr)
_rvs[regno].spec = 0; _rvs[regno].spec = 0;
} }
@ -292,53 +292,53 @@ _jit_prolog(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
if (_jit->function) if (_jitc->function)
jit_epilog(); jit_epilog();
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0); assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
jit_regset_set_ui(_jit->regsav, 0); jit_regset_set_ui(_jitc->regsav, 0);
offset = _jit->functions.offset; offset = _jitc->functions.offset;
if (offset >= _jit->functions.length) { if (offset >= _jitc->functions.length) {
_jit->functions.ptr = realloc(_jit->functions.ptr, _jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jit->functions.length + 16) * (_jitc->functions.length + 16) *
sizeof(jit_function_t)); 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)); 16 * sizeof(jit_function_t));
_jit->functions.length += 16; _jitc->functions.length += 16;
} }
_jit->function = _jit->functions.ptr + _jit->functions.offset++; _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
_jit->function->self.size = stack_framesize; _jitc->function->self.size = stack_framesize;
_jit->function->self.argi = _jit->function->self.argf = _jitc->function->self.argi = _jitc->function->self.argf =
_jit->function->self.aoff = _jit->function->self.alen = 0; _jitc->function->self.aoff = _jitc->function->self.alen = 0;
/* sse/x87 conversion */ /* sse/x87 conversion */
_jit->function->self.aoff = -8; _jitc->function->self.aoff = -8;
_jit->function->self.call = jit_call_default; _jitc->function->self.call = jit_call_default;
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t)); _jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog); _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jit->function->prolog); jit_link(_jitc->function->prolog);
_jit->function->prolog->w.w = offset; _jitc->function->prolog->w.w = offset;
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog); _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
/* u: label value /* u: label value
* v: offset in blocks vector * v: offset in blocks vector
* w: offset in functions 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_int32_t
_jit_allocai(jit_state_t *_jit, jit_int32_t length) _jit_allocai(jit_state_t *_jit, jit_int32_t length)
{ {
assert(_jit->function); assert(_jitc->function);
switch (length) { switch (length) {
case 0: case 1: break; case 0: case 1: break;
case 2: _jit->function->self.aoff &= -2; break; case 2: _jitc->function->self.aoff &= -2; break;
case 3: case 4: _jit->function->self.aoff &= -4; break; case 3: case 4: _jitc->function->self.aoff &= -4; break;
default: _jit->function->self.aoff &= -8; break; default: _jitc->function->self.aoff &= -8; break;
} }
_jit->function->self.aoff -= length; _jitc->function->self.aoff -= length;
return (_jit->function->self.aoff); return (_jitc->function->self.aoff);
} }
void void
@ -346,11 +346,11 @@ _jit_ret(jit_state_t *_jit)
{ {
jit_node_t *instr; jit_node_t *instr;
assert(_jit->function); assert(_jitc->function);
/* jump to epilog */ /* jump to epilog */
instr = jit_jmpi(); instr = jit_jmpi();
jit_patch_at(instr, _jit->function->epilog); jit_patch_at(instr, _jitc->function->epilog);
} }
void void
@ -409,10 +409,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
void void
_jit_epilog(jit_state_t *_jit) _jit_epilog(jit_state_t *_jit)
{ {
assert(_jit->function); assert(_jitc->function);
assert(_jit->function->epilog->next == NULL); assert(_jitc->function->epilog->next == NULL);
jit_link(_jit->function->epilog); jit_link(_jitc->function->epilog);
_jit->function = NULL; _jitc->function = NULL;
} }
jit_node_t * jit_node_t *
@ -420,15 +420,15 @@ _jit_arg(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->self.argi < 6) if (_jitc->function->self.argi < 6)
offset = _jit->function->self.argi++; offset = _jitc->function->self.argi++;
else else
#endif #endif
{ {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_word_t); _jitc->function->self.size += sizeof(jit_word_t);
} }
return (jit_new_node_w(jit_code_arg, offset)); return (jit_new_node_w(jit_code_arg, offset));
} }
@ -448,18 +448,18 @@ _jit_arg_f(jit_state_t *_jit)
{ {
jit_int32_t offset; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->self.argf < 8) if (_jitc->function->self.argf < 8)
offset = _jit->function->self.argf++; offset = _jitc->function->self.argf++;
else else
#endif #endif
{ {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
#if __WORDSIZE == 32 #if __WORDSIZE == 32
_jit->function->self.size += sizeof(jit_float32_t); _jitc->function->self.size += sizeof(jit_float32_t);
#else #else
_jit->function->self.size += sizeof(jit_float64_t); _jitc->function->self.size += sizeof(jit_float64_t);
#endif #endif
} }
return (jit_new_node_w(jit_code_arg_f, offset)); 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; jit_int32_t offset;
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->self.argf < 8) if (_jitc->function->self.argf < 8)
offset = _jit->function->self.argf++; offset = _jitc->function->self.argf++;
else else
#endif #endif
{ {
offset = _jit->function->self.size; offset = _jitc->function->self.size;
_jit->function->self.size += sizeof(jit_float64_t); _jitc->function->self.size += sizeof(jit_float64_t);
} }
return (jit_new_node_w(jit_code_arg_d, offset)); 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 void
_jit_pushargr(jit_state_t *_jit, jit_int32_t u) _jit_pushargr(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.argi < 6) { if (_jitc->function->call.argi < 6) {
jit_movr(_RDI - _jit->function->call.argi, u); jit_movr(_RDI - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else else
#endif #endif
{ {
jit_stxi(_jit->function->call.size, _RSP, u); jit_stxi(_jitc->function->call.size, _RSP, u);
_jit->function->call.size += sizeof(jit_word_t); _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; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.argi < 6) { if (_jitc->function->call.argi < 6) {
jit_movi(_RDI - _jit->function->call.argi, u); jit_movi(_RDI - _jitc->function->call.argi, u);
++_jit->function->call.argi; ++_jitc->function->call.argi;
} }
else else
#endif #endif
{ {
regno = jit_get_reg(jit_class_gpr); regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u); jit_movi(regno, u);
jit_stxi(_jit->function->call.size, _RSP, regno); jit_stxi(_jitc->function->call.size, _RSP, regno);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
jit_unget_reg(regno); jit_unget_reg(regno);
} }
} }
@ -638,17 +638,17 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
void void
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u) _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.argf < 8) { if (_jitc->function->call.argf < 8) {
jit_movr_f(_XMM0 - _jit->function->call.argf, u); jit_movr_f(_XMM0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
} }
else else
#endif #endif
{ {
jit_stxi_f(_jit->function->call.size, _RSP, u); jit_stxi_f(_jitc->function->call.size, _RSP, u);
_jit->function->call.size += sizeof(jit_word_t); _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; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.argf < 8) { if (_jitc->function->call.argf < 8) {
jit_movi_f(_XMM0 - _jit->function->call.argf, u); jit_movi_f(_XMM0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
} }
else else
#endif #endif
{ {
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u); jit_movi_f(regno, u);
jit_stxi_f(_jit->function->call.size, _RSP, regno); jit_stxi_f(_jitc->function->call.size, _RSP, regno);
_jit->function->call.size += sizeof(jit_word_t); _jitc->function->call.size += sizeof(jit_word_t);
jit_unget_reg(regno); jit_unget_reg(regno);
} }
} }
@ -677,17 +677,17 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
void void
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u) _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
{ {
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.argf < 8) { if (_jitc->function->call.argf < 8) {
jit_movr_d(_XMM0 - _jit->function->call.argf, u); jit_movr_d(_XMM0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
} }
else else
#endif #endif
{ {
jit_stxi_d(_jit->function->call.size, _RSP, u); jit_stxi_d(_jitc->function->call.size, _RSP, u);
_jit->function->call.size += sizeof(jit_float64_t); _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; jit_int32_t regno;
assert(_jit->function); assert(_jitc->function);
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.argf < 8) { if (_jitc->function->call.argf < 8) {
jit_movi_d(_XMM0 - _jit->function->call.argf, u); jit_movi_d(_XMM0 - _jitc->function->call.argf, u);
++_jit->function->call.argf; ++_jitc->function->call.argf;
} }
else else
#endif #endif
{ {
regno = jit_get_reg(jit_class_fpr); regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u); jit_movi_d(regno, u);
jit_stxi_d(_jit->function->call.size, _RSP, regno); jit_stxi_d(_jitc->function->call.size, _RSP, regno);
_jit->function->call.size += sizeof(jit_float64_t); _jitc->function->call.size += sizeof(jit_float64_t);
jit_unget_reg(regno); jit_unget_reg(regno);
} }
} }
@ -743,17 +743,17 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
jit_node_t *call; jit_node_t *call;
reg = r0; reg = r0;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
#if __WORDSIZE == 64 #if __WORDSIZE == 64
if (_jit->function->call.call & jit_call_varargs) { if (_jitc->function->call.call & jit_call_varargs) {
if (jit_regno(reg) == _RAX) { if (jit_regno(reg) == _RAX) {
reg = jit_get_reg(jit_class_gpr); reg = jit_get_reg(jit_class_gpr);
jit_movr(reg, _RAX); jit_movr(reg, _RAX);
} }
if (_jit->function->call.argf) if (_jitc->function->call.argf)
jit_movi(_RAX, _jit->function->call.argf); jit_movi(_RAX, _jitc->function->call.argf);
else else
jit_movi(_RAX, 0); jit_movi(_RAX, 0);
if (reg != r0) if (reg != r0)
@ -761,11 +761,11 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
} }
#endif #endif
call = jit_callr(reg); call = jit_callr(reg);
call->v.w = _jit->function->call.argi; call->v.w = _jitc->function->call.argi;
call->w.w = _jit->function->call.argf; call->w.w = _jitc->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
} }
jit_node_t * jit_node_t *
@ -776,30 +776,30 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
#endif #endif
jit_node_t *node; jit_node_t *node;
assert(_jit->function); assert(_jitc->function);
if (_jit->function->self.alen < _jit->function->call.size) if (_jitc->function->self.alen < _jitc->function->call.size)
_jit->function->self.alen = _jit->function->call.size; _jitc->function->self.alen = _jitc->function->call.size;
#if __WORDSIZE == 64 #if __WORDSIZE == 64
/* FIXME preventing %rax allocation is good enough, but for consistency /* FIXME preventing %rax allocation is good enough, but for consistency
* it should automatically detect %rax is dead, in case it has run out * 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 * registers, and not save/restore it, what would be wrong if using the
* the return value, otherwise, just a needless noop */ * the return value, otherwise, just a needless noop */
/* >> prevent %rax from being allocated as the function pointer */ /* >> 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); reg = jit_get_reg(jit_class_gpr);
node = jit_movi(reg, (jit_word_t)i0); node = jit_movi(reg, (jit_word_t)i0);
jit_finishr(reg); jit_finishr(reg);
jit_unget_reg(reg); jit_unget_reg(reg);
/* << prevent %rax from being allocated as the function pointer */ /* << prevent %rax from being allocated as the function pointer */
jit_regset_clrbit(_jit->regarg, _RAX); jit_regset_clrbit(_jitc->regarg, _RAX);
#else #else
node = jit_calli(i0); node = jit_calli(i0);
node->v.w = _jit->function->call.argi; node->v.w = _jitc->function->call.argi;
node->w.w = _jit->function->call.argf; node->w.w = _jitc->function->call.argf;
#endif #endif
_jit->function->call.argi = _jit->function->call.argf = _jitc->function->call.argi = _jitc->function->call.argf =
_jit->function->call.size = 0; _jitc->function->call.size = 0;
_jit->prepare = 0; _jitc->prepare = 0;
return (node); return (node);
} }
@ -889,7 +889,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset; jit_int32_t patch_offset;
} undo; } undo;
_jit->function = NULL; _jitc->function = NULL;
jit_reglive_setup(); jit_reglive_setup();
@ -1125,8 +1125,8 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \ patch(word, node); \
} \ } \
break break
for (node = _jit->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jit->code.end) if (_jit->pc.uc >= _jitc->code.end)
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);
@ -1558,17 +1558,17 @@ _emit_code(jit_state_t *_jit)
calli(node->u.w); calli(node->u.w);
break; break;
case jit_code_prolog: case jit_code_prolog:
_jit->function = _jit->functions.ptr + node->w.w; _jitc->function = _jitc->functions.ptr + node->w.w;
undo.node = node; undo.node = node;
undo.word = _jit->pc.w; undo.word = _jit->pc.w;
undo.patch_offset = _jit->patches.offset; undo.patch_offset = _jitc->patches.offset;
restart_function: restart_function:
_jit->again = 0; _jitc->again = 0;
prolog(node); prolog(node);
break; break;
case jit_code_epilog: case jit_code_epilog:
assert(_jit->function == _jit->functions.ptr + node->w.w); assert(_jitc->function == _jitc->functions.ptr + node->w.w);
if (_jit->again) { if (_jitc->again) {
for (temp = undo.node->next; for (temp = undo.node->next;
temp != node; temp = temp->next) { temp != node; temp = temp->next) {
if (temp->code == jit_code_label || if (temp->code == jit_code_label ||
@ -1577,7 +1577,7 @@ _emit_code(jit_state_t *_jit)
} }
node = undo.node; node = undo.node;
_jit->pc.w = undo.word; _jit->pc.w = undo.word;
_jit->patches.offset = undo.patch_offset; _jitc->patches.offset = undo.patch_offset;
goto restart_function; goto restart_function;
} }
if (node->link && if (node->link &&
@ -1587,7 +1587,7 @@ _emit_code(jit_state_t *_jit)
node->flag |= jit_flag_patch; node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w; node->u.w = _jit->pc.w;
epilog(node); epilog(node);
_jit->function = NULL; _jitc->function = NULL;
break; break;
#if __WORDSIZE == 32 #if __WORDSIZE == 32
case jit_code_x86_retval_f: case jit_code_x86_retval_f:
@ -1637,10 +1637,10 @@ _emit_code(jit_state_t *_jit)
#undef case_fr #undef case_fr
#undef case_rr #undef case_rr
for (offset = 0; offset < _jit->patches.offset; offset++) { for (offset = 0; offset < _jitc->patches.offset; offset++) {
node = _jit->patches.ptr[offset].node; node = _jitc->patches.ptr[offset].node;
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w; 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); return (_jit->code.ptr);
@ -1693,17 +1693,17 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
else else
flag = node->u.n->flag; flag = node->u.n->flag;
assert(!(flag & jit_flag_patch)); assert(!(flag & jit_flag_patch));
if (_jit->patches.offset >= _jit->patches.length) { if (_jitc->patches.offset >= _jitc->patches.length) {
_jit->patches.ptr = realloc(_jit->patches.ptr, _jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jit->patches.length + 1024) * (_jitc->patches.length + 1024) *
sizeof(jit_patch_t)); 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)); 1024 * sizeof(jit_patch_t));
_jit->patches.length += 1024; _jitc->patches.length += 1024;
} }
_jit->patches.ptr[_jit->patches.offset].inst = instr; _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
_jit->patches.ptr[_jit->patches.offset].node = node; _jitc->patches.ptr[_jitc->patches.offset].node = node;
++_jit->patches.offset; ++_jitc->patches.offset;
} }
static void static void

File diff suppressed because it is too large Load diff