mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 06:20:30 +02:00
Correct mips backend implementation to pass initial tests.
* include/lightning/jit_mips.h, lib/jit_mips-cpu.c, lib/jit_mips-fpu.c, lib/jit_mips.c: Correct float/double argument handling and make the mips backend pass the initial test cases. * include/lightning.h, ib/jit_print.c, lib/lightning.c: Add extra enum values for argument handling functions that could not be abstracted to the current codes, that is, when float values need to move from/to gpr from/to fpr. It would be more tempting to add such primitives, but they would have wordsize limitations, and it is not expected to add codes with one gpr argument for 64 bit and two for 32 bit. * lib/jit_ppc.c: Check _jit->function before calling jit_epilog() to avoid a runtime exception.
This commit is contained in:
parent
01be83d480
commit
760fab8d37
9 changed files with 201 additions and 51 deletions
|
@ -76,7 +76,7 @@ typedef union {
|
|||
# define sti(u, v) sti_i(u, v)
|
||||
# define stxi(u, v, w) stxi_i(u, v, w)
|
||||
# else
|
||||
# define stack_framesize 142
|
||||
# define stack_framesize 144
|
||||
# define ldi(u, v) ldi_l(u, v)
|
||||
# define ldxi(u, v, w) ldxi_l(u, v, w)
|
||||
# define sti(u, v) sti_l(u, v)
|
||||
|
|
|
@ -208,6 +208,10 @@ static void _divi_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_float64_t*);
|
|||
# define absr_d(r0,r1) ABS_D(r0,r1)
|
||||
# define negr_f(r0,r1) NEG_S(r0,r1)
|
||||
# define negr_d(r0,r1) NEG_D(r0,r1)
|
||||
# define getarg_f(r0, r1) MTC1(r1, r0)
|
||||
# define pushargr_f(r0, r1) MFC1(r1, r0)
|
||||
# define pushargi_f(r0, i0) _pushargi_f(_jit, r0, i0)
|
||||
static void _pushargi_f(jit_state_t*,jit_int32_t,jit_float32_t*);
|
||||
# define extr_f(r0, r1) _extr_f(_jit, r0, r1)
|
||||
static void _extr_f(jit_state_t*,jit_int32_t,jit_int32_t);
|
||||
# define truncr_f_i(r0, r1) _truncr_f_i(_jit, r0, r1)
|
||||
|
@ -235,6 +239,12 @@ static void _stxi_f(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
|
|||
static void _movr_f(jit_state_t*,jit_int32_t,jit_int32_t);
|
||||
# define movi_f(r0, i0) _movi_f(_jit, r0, i0)
|
||||
static void _movi_f(jit_state_t*,jit_int32_t,jit_float32_t*);
|
||||
# define getarg_d(r0, r1) _getarg_d(_jit, r0, r1)
|
||||
static void _getarg_d(jit_state_t*,jit_int32_t,jit_int32_t);
|
||||
# define pushargr_d(r0, r1) _pushargr_d(_jit, r0, r1)
|
||||
static void _pushargr_d(jit_state_t*,jit_int32_t,jit_int32_t);
|
||||
# define pushargi_d(r0, i0) _pushargi_d(_jit, r0, i0)
|
||||
static void _pushargi_d(jit_state_t*,jit_int32_t,jit_float64_t*);
|
||||
# define extr_d(r0, r1) _extr_d(_jit, r0, r1)
|
||||
static void _extr_d(jit_state_t*,jit_int32_t,jit_int32_t);
|
||||
# define truncr_d_i(r0, r1) _truncr_d_i(_jit, r0, r1)
|
||||
|
@ -566,6 +576,18 @@ fopi(sub)
|
|||
fopi(mul)
|
||||
fopi(div)
|
||||
|
||||
static void
|
||||
_pushargi_f(jit_state_t *_jit, jit_int32_t r0, jit_float32_t *i0)
|
||||
{
|
||||
union {
|
||||
jit_int32_t i;
|
||||
jit_float32_t f;
|
||||
} data;
|
||||
|
||||
data.f = *i0;
|
||||
movi(r0, data.i);
|
||||
}
|
||||
|
||||
static void
|
||||
_extr_f(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
|
||||
{
|
||||
|
@ -706,6 +728,46 @@ dopi(sub)
|
|||
dopi(mul)
|
||||
dopi(div)
|
||||
|
||||
static void
|
||||
_getarg_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
|
||||
{
|
||||
# if __WORDSIZE == 32
|
||||
MTC1(r1, r0);
|
||||
MTC1(r1 + 1, r0 + 1);
|
||||
# else
|
||||
DMTC1(r1, r0);
|
||||
# endif
|
||||
}
|
||||
|
||||
static void
|
||||
_pushargr_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
|
||||
{
|
||||
# if __WORDSIZE == 32
|
||||
MFC1(r0, r1);
|
||||
MFC1(r0 + 1, r1 + 1);
|
||||
# else
|
||||
DMFC1(r0, r1);
|
||||
# endif
|
||||
}
|
||||
|
||||
static void
|
||||
_pushargi_d(jit_state_t *_jit, jit_int32_t r0, jit_float64_t *i0)
|
||||
{
|
||||
union {
|
||||
jit_int32_t i[2];
|
||||
jit_int64_t l;
|
||||
jit_float64_t d;
|
||||
} data;
|
||||
|
||||
data.d = *i0;
|
||||
# if __WORDSIZE == 64
|
||||
movi(r0, data.l);
|
||||
# else
|
||||
movi(r0, data.i[0]);
|
||||
movi(r0 + 1, data.i[1]);
|
||||
# endif
|
||||
}
|
||||
|
||||
static void
|
||||
_extr_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
|
||||
{
|
||||
|
|
149
lib/jit_mips.c
149
lib/jit_mips.c
|
@ -240,6 +240,10 @@ _jit_arg(jit_state_t *_jit)
|
|||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argf) {
|
||||
_jit->function->self.argi = _jit->function->self.argf;
|
||||
_jit->function->self.argf = 0;
|
||||
}
|
||||
if (_jit->function->self.argi < 4)
|
||||
offset = _jit->function->self.argi++;
|
||||
else
|
||||
|
@ -260,27 +264,26 @@ _jit_arg_f(jit_state_t *_jit)
|
|||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi) {
|
||||
if (_jit->function->self.argi & 1)
|
||||
++_jit->function->self.argi;
|
||||
_jit->function->self.argf = _jit->function->self.argi;
|
||||
}
|
||||
if ((offset = _jit->function->self.argf) < 4) {
|
||||
offset = _jit->function->self.argf;
|
||||
_jit->function->self.argf += 2;
|
||||
if (_jit->function->self.argi)
|
||||
_jit->function->self.argi = _jit->function->self.argf;
|
||||
offset = (_jit->function->self.size - stack_framesize) >> 2;
|
||||
if (offset < 4) {
|
||||
if (!_jit->function->self.argi) {
|
||||
offset += 4;
|
||||
_jit->function->self.argf += 2;
|
||||
}
|
||||
else
|
||||
_jit->function->self.argi += 2;
|
||||
}
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
_jit->function->self.size += sizeof(jit_word_t);
|
||||
_jit->function->self.size += sizeof(jit_float32_t);
|
||||
return (offset);
|
||||
}
|
||||
|
||||
jit_bool_t
|
||||
_jit_arg_f_reg_p(jit_state_t *_jit, jit_int32_t offset)
|
||||
{
|
||||
return (offset >= 0 && offset < 4);
|
||||
/* 0-3 integer register, 4-7 float register */
|
||||
return (offset >= 0 && offset < 8);
|
||||
}
|
||||
|
||||
jit_int32_t
|
||||
|
@ -289,16 +292,21 @@ _jit_arg_d(jit_state_t *_jit)
|
|||
jit_int32_t offset;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->self.argi) {
|
||||
if (_jit->function->self.argi & 1)
|
||||
++_jit->function->self.argi;
|
||||
_jit->function->self.argf = _jit->function->self.argi;
|
||||
}
|
||||
if ((offset = _jit->function->self.argf) < 4) {
|
||||
offset = _jit->function->self.argf;
|
||||
_jit->function->self.argf += 2;
|
||||
if (_jit->function->self.argi)
|
||||
if (_jit->function->self.size & 7) {
|
||||
_jit->function->self.size += 4;
|
||||
if (_jit->function->self.size < 16 && !_jit->function->self.argi) {
|
||||
_jit->function->self.argi = _jit->function->self.argf;
|
||||
_jit->function->self.argf = 0;
|
||||
}
|
||||
}
|
||||
offset = (_jit->function->self.size - stack_framesize) >> 2;
|
||||
if (offset < 4) {
|
||||
if (!_jit->function->self.argi) {
|
||||
offset += 4;
|
||||
_jit->function->self.argf += 2;
|
||||
}
|
||||
else
|
||||
_jit->function->self.argi += 2;
|
||||
}
|
||||
else
|
||||
offset = _jit->function->self.size;
|
||||
|
@ -386,9 +394,9 @@ void
|
|||
_jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_int32_t v)
|
||||
{
|
||||
if (v < 4)
|
||||
jit_extr_f(u, _A0 - v);
|
||||
jit_new_node_ww(jit_code_getarg_f, u, _A0 - (v >> 1));
|
||||
else if (v < 8)
|
||||
jit_movr_f(u, _F12 + ((v - 4) >> 1));
|
||||
jit_movr_f(u, _F12 - ((v - 4) >> 1));
|
||||
else
|
||||
jit_ldxi_f(u, _FP, v);
|
||||
}
|
||||
|
@ -397,9 +405,9 @@ void
|
|||
_jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_int32_t v)
|
||||
{
|
||||
if (v < 4)
|
||||
jit_extr_d(u, _A0 - v);
|
||||
jit_new_node_ww(jit_code_getarg_d, u, _A0 - (v >> 1));
|
||||
else if (v < 8)
|
||||
jit_movr_d(u, _F12 + ((v - 4) >> 1));
|
||||
jit_movr_d(u, _F12 - ((v - 4) >> 1));
|
||||
else
|
||||
jit_ldxi_d(u, _FP, v);
|
||||
}
|
||||
|
@ -408,6 +416,10 @@ void
|
|||
_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf) {
|
||||
_jit->function->call.argi = _jit->function->call.argf;
|
||||
_jit->function->call.argf = 0;
|
||||
}
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movr(_A0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
|
@ -423,6 +435,10 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
|
|||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf) {
|
||||
_jit->function->call.argi = _jit->function->call.argf;
|
||||
_jit->function->call.argf = 0;
|
||||
}
|
||||
if (_jit->function->call.argi < 4) {
|
||||
jit_movi(_A0 - _jit->function->call.argi, u);
|
||||
++_jit->function->call.argi;
|
||||
|
@ -440,44 +456,60 @@ void
|
|||
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 4) {
|
||||
jit_movr_f(JIT_FA0 - (_jit->function->call.argf >> 1), u);
|
||||
if (_jit->function->call.argi) {
|
||||
jit_new_node_ww(jit_code_pushargr_f,
|
||||
_A0 - _jit->function->call.argi, u);
|
||||
_jit->function->call.argi += 2;
|
||||
}
|
||||
else if (_jit->function->call.argf < 4) {
|
||||
jit_movr_f(_F12 - (_jit->function->call.argf >> 1), u);
|
||||
_jit->function->call.argf += 2;
|
||||
/* if _jit->function->call.argi, actually move to integer register */
|
||||
}
|
||||
else
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, u);
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
|
||||
{
|
||||
jit_int32_t regno;
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 4) {
|
||||
jit_movi_f(JIT_FA0 - _jit->function->call.argf, u);
|
||||
if (_jit->function->call.argi) {
|
||||
if (_jit->function->call.argi & 1)
|
||||
++_jit->function->call.argi;
|
||||
jit_new_node_wf(jit_code_pushargi_f,
|
||||
_A0 - _jit->function->call.argi, u);
|
||||
_jit->function->call.argi += 2;
|
||||
}
|
||||
else if (_jit->function->call.argf < 4) {
|
||||
jit_movi_f(_F12 - (_jit->function->call.argf >> 1), u);
|
||||
_jit->function->call.argf += 2;
|
||||
/* if _jit->function->call.argi, actually move to integer register */
|
||||
}
|
||||
else {
|
||||
assert(_jit->function);
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_f(regno, u);
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
_jit->function->call.size += sizeof(jit_word_t);
|
||||
_jit->function->call.size += sizeof(jit_float32_t);
|
||||
}
|
||||
|
||||
void
|
||||
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
||||
{
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 4) {
|
||||
jit_movr_d(JIT_FA0 - (_jit->function->call.argf >> 1), u);
|
||||
if (_jit->function->call.argi) {
|
||||
if (_jit->function->call.argi & 1)
|
||||
++_jit->function->call.argi;
|
||||
jit_new_node_ww(jit_code_pushargr_d,
|
||||
_A0 - _jit->function->call.argi, u);
|
||||
_jit->function->call.argi += 2;
|
||||
}
|
||||
else if (_jit->function->call.argf < 4) {
|
||||
jit_movr_d(_F12 - (_jit->function->call.argf >> 1), u);
|
||||
_jit->function->call.argf += 2;
|
||||
/* if _jit->function->call.argi, actually move to integer register */
|
||||
}
|
||||
else
|
||||
jit_stxi_d(_jit->function->call.size, JIT_SP, u);
|
||||
|
@ -487,18 +519,24 @@ _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
|
|||
void
|
||||
_jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
|
||||
{
|
||||
jit_int32_t regno;
|
||||
jit_int32_t regno;
|
||||
|
||||
assert(_jit->function);
|
||||
if (_jit->function->call.argf < 4) {
|
||||
jit_movi_d(JIT_FA0 - _jit->function->call.argf, u);
|
||||
if (_jit->function->call.argi) {
|
||||
if (_jit->function->call.argi & 1)
|
||||
++_jit->function->call.argi;
|
||||
jit_new_node_wd(jit_code_pushargi_d,
|
||||
_A0 - _jit->function->call.argi, u);
|
||||
_jit->function->call.argi += 2;
|
||||
}
|
||||
else if (_jit->function->call.argf < 4) {
|
||||
jit_movi_d(_F12 - (_jit->function->call.argf >> 1), u);
|
||||
_jit->function->call.argf += 2;
|
||||
/* if _jit->function->call.argi, actually move to integer register */
|
||||
}
|
||||
else {
|
||||
assert(_jit->function);
|
||||
regno = jit_get_reg(jit_class_fpr);
|
||||
jit_movi_d(regno, u);
|
||||
jit_stxi_d(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_movi_f(regno, u);
|
||||
jit_stxi_f(_jit->function->call.size, JIT_SP, regno);
|
||||
jit_unget_reg(regno);
|
||||
}
|
||||
_jit->function->call.size += sizeof(jit_float64_t);
|
||||
|
@ -639,7 +677,8 @@ _jit_emit(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
jit_epilog();
|
||||
if (_jit->function)
|
||||
jit_epilog();
|
||||
jit_optimize();
|
||||
|
||||
_jit->emit = 1;
|
||||
|
@ -862,6 +901,8 @@ _jit_emit(jit_state_t *_jit)
|
|||
else
|
||||
movi(rn(node->u.w), node->v.w);
|
||||
break;
|
||||
case_rr(neg,);
|
||||
case_rr(com,);
|
||||
case_rrr(lt,);
|
||||
case_rrw(lt,);
|
||||
case_rrr(lt, _u);
|
||||
|
@ -1142,6 +1183,22 @@ _jit_emit(jit_state_t *_jit)
|
|||
epilog(node);
|
||||
_jit->function = NULL;
|
||||
break;
|
||||
case jit_code_getarg_f:
|
||||
getarg_f(rn(node->u.w), rn(node->v.w));
|
||||
break;
|
||||
case_rr(pusharg, _f);
|
||||
case jit_code_pushargi_f:
|
||||
assert(node->flag & jit_flag_data);
|
||||
pushargi_f(rn(node->u.w), (jit_float32_t *)node->v.n->u.w);
|
||||
break;
|
||||
case jit_code_getarg_d:
|
||||
getarg_d(rn(node->u.w), rn(node->v.w));
|
||||
break;
|
||||
case_rr(pusharg, _d);
|
||||
case jit_code_pushargi_d:
|
||||
assert(node->flag & jit_flag_data);
|
||||
pushargi_d(rn(node->u.w), (jit_float64_t *)node->v.n->u.w);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
|
|
@ -564,7 +564,8 @@ _jit_emit(jit_state_t *_jit)
|
|||
jit_int32_t patch_offset;
|
||||
} undo;
|
||||
|
||||
jit_epilog();
|
||||
if (_jit->function)
|
||||
jit_epilog();
|
||||
jit_optimize();
|
||||
|
||||
_jit->emit = 1;
|
||||
|
|
|
@ -118,6 +118,7 @@ static char *code_name[] = {
|
|||
"jmpr", "jmpi",
|
||||
"callr", "calli",
|
||||
"epilog",
|
||||
"getarg_f",
|
||||
"addr_f", "addi_f",
|
||||
"subr_f", "subi_f",
|
||||
"mulr_f", "muli_f",
|
||||
|
@ -159,7 +160,9 @@ static char *code_name[] = {
|
|||
"bltgtr_f", "bltgti_f",
|
||||
"bordr_f", "bordi_f",
|
||||
"bunordr_f", "bunordi_f",
|
||||
"pushargr_f", "pushargi_f",
|
||||
"retval_f",
|
||||
"getarg_d",
|
||||
"addr_d", "addi_d",
|
||||
"subr_d", "subi_d",
|
||||
"mulr_d", "muli_d",
|
||||
|
@ -201,6 +204,7 @@ static char *code_name[] = {
|
|||
"bltgtr_d", "bltgti_d",
|
||||
"bordr_d", "bordi_d",
|
||||
"bunordr_d", "bunordi_d",
|
||||
"pushargr_d", "pushargi_d",
|
||||
"retval_d",
|
||||
};
|
||||
|
||||
|
|
|
@ -765,6 +765,9 @@ _jit_classify(jit_state_t *_jit, jit_code_t code)
|
|||
case jit_code_callr: case jit_code_jmpr:
|
||||
mask = jit_cc_a0_reg|jit_cc_a0_jmp;
|
||||
break;
|
||||
case jit_code_pushargr_f: case jit_code_pushargr_d:
|
||||
mask = jit_cc_a0_reg|jit_cc_a1_reg;
|
||||
break;
|
||||
case jit_code_retval_f: case jit_code_retval_d:
|
||||
mask = jit_cc_a0_reg|jit_cc_a0_chg;
|
||||
break;
|
||||
|
@ -774,10 +777,10 @@ _jit_classify(jit_state_t *_jit, jit_code_t code)
|
|||
case jit_code_ldi_d:
|
||||
mask = jit_cc_a0_reg|jit_cc_a0_chg|jit_cc_a1_int;
|
||||
break;
|
||||
case jit_code_movi_f:
|
||||
case jit_code_movi_f: case jit_code_pushargi_f:
|
||||
mask = jit_cc_a0_reg|jit_cc_a0_chg|jit_cc_a1_flt;
|
||||
break;
|
||||
case jit_code_movi_d:
|
||||
case jit_code_movi_d: case jit_code_pushargi_d:
|
||||
mask = jit_cc_a0_reg|jit_cc_a0_chg|jit_cc_a1_dbl;
|
||||
break;
|
||||
case jit_code_negr: case jit_code_comr: case jit_code_movr:
|
||||
|
@ -793,6 +796,7 @@ _jit_classify(jit_state_t *_jit, jit_code_t code)
|
|||
case jit_code_negr_d: case jit_code_absr_d: case jit_code_sqrtr_d:
|
||||
case jit_code_movr_d: case jit_code_extr_d: case jit_code_extr_f_d:
|
||||
case jit_code_ldr_d:
|
||||
case jit_code_getarg_f: case jit_code_getarg_d:
|
||||
mask = jit_cc_a0_reg|jit_cc_a0_chg|jit_cc_a1_reg;
|
||||
break;
|
||||
case jit_code_addi: case jit_code_addxi: case jit_code_addci:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue