Combine IR instruction dispatch for all assembler backends.

This commit is contained in:
Mike Pall
2013-04-22 22:32:41 +02:00
parent 2ab5e7c5dc
commit a2c78810ca
5 changed files with 454 additions and 654 deletions

View File

@@ -849,7 +849,7 @@ static void asm_xload(ASMState *as, IRIns *ir)
asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
}
static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
static void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)
{
if (ir->r != RID_SINK) {
Reg src = ra_alloc1z(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
@@ -858,6 +858,8 @@ static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
}
}
#define asm_xstore(as, ir) asm_xstore_(as, ir, 0)
static void asm_ahuvload(ASMState *as, IRIns *ir)
{
IRType1 t = ir->t;
@@ -1083,6 +1085,18 @@ static void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi)
emit_fg(as, mi, dest, left);
}
static void asm_fpmath(ASMState *as, IRIns *ir)
{
if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
return;
if (ir->op2 <= IRFPM_TRUNC)
asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2);
else if (ir->op2 == IRFPM_SQRT)
asm_fpunary(as, ir, MIPSI_SQRT_D);
else
asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
}
static void asm_add(ASMState *as, IRIns *ir)
{
if (irt_isnum(ir->t)) {
@@ -1126,6 +1140,10 @@ static void asm_mul(ASMState *as, IRIns *ir)
}
}
#define asm_div(as, ir) asm_fparith(as, ir, MIPSI_DIV_D)
#define asm_mod(as, ir) asm_callid(as, ir, IRCALL_lj_vm_modi)
#define asm_pow(as, ir) asm_callid(as, ir, IRCALL_lj_vm_powi)
static void asm_neg(ASMState *as, IRIns *ir)
{
if (irt_isnum(ir->t)) {
@@ -1137,6 +1155,10 @@ static void asm_neg(ASMState *as, IRIns *ir)
}
}
#define asm_abs(as, ir) asm_fpunary(as, ir, MIPSI_ABS_D)
#define asm_atan2(as, ir) asm_callid(as, ir, IRCALL_atan2)
#define asm_ldexp(as, ir) asm_callid(as, ir, IRCALL_ldexp)
static void asm_arithov(ASMState *as, IRIns *ir)
{
Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR);
@@ -1170,6 +1192,9 @@ static void asm_arithov(ASMState *as, IRIns *ir)
emit_move(as, RID_TMP, dest == left ? left : right);
}
#define asm_addov(as, ir) asm_arithov(as, ir)
#define asm_subov(as, ir) asm_arithov(as, ir)
static void asm_mulov(ASMState *as, IRIns *ir)
{
#if LJ_DUALNUM
@@ -1263,7 +1288,7 @@ static void asm_neg64(ASMState *as, IRIns *ir)
}
#endif
static void asm_bitnot(ASMState *as, IRIns *ir)
static void asm_bnot(ASMState *as, IRIns *ir)
{
Reg left, right, dest = ra_dest(as, ir, RSET_GPR);
IRIns *irl = IR(ir->op1);
@@ -1277,7 +1302,7 @@ static void asm_bitnot(ASMState *as, IRIns *ir)
emit_dst(as, MIPSI_NOR, dest, left, right);
}
static void asm_bitswap(ASMState *as, IRIns *ir)
static void asm_bswap(ASMState *as, IRIns *ir)
{
Reg dest = ra_dest(as, ir, RSET_GPR);
Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
@@ -1313,6 +1338,10 @@ static void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
emit_dst(as, mi, dest, left, right);
}
#define asm_band(as, ir) asm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI)
#define asm_bor(as, ir) asm_bitop(as, ir, MIPSI_OR, MIPSI_ORI)
#define asm_bxor(as, ir) asm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI)
static void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
{
Reg dest = ra_dest(as, ir, RSET_GPR);
@@ -1326,7 +1355,12 @@ static void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
}
}
static void asm_bitror(ASMState *as, IRIns *ir)
#define asm_bshl(as, ir) asm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL)
#define asm_bshr(as, ir) asm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL)
#define asm_bsar(as, ir) asm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA)
#define asm_brol(as, ir) lua_assert(0)
static void asm_bror(ASMState *as, IRIns *ir)
{
if ((as->flags & JIT_F_MIPS32R2)) {
asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR);
@@ -1375,6 +1409,9 @@ static void asm_min_max(ASMState *as, IRIns *ir, int ismax)
}
}
#define asm_min(as, ir) asm_min_max(as, ir, 0)
#define asm_max(as, ir) asm_min_max(as, ir, 1)
/* -- Comparisons --------------------------------------------------------- */
static void asm_comp(ASMState *as, IRIns *ir)
@@ -1412,7 +1449,7 @@ static void asm_comp(ASMState *as, IRIns *ir)
}
}
static void asm_compeq(ASMState *as, IRIns *ir)
static void asm_equal(ASMState *as, IRIns *ir)
{
Reg right, left = ra_alloc2(as, ir, irt_isnum(ir->t) ? RSET_FPR : RSET_GPR);
right = (left >> 8); left &= 255;
@@ -1486,8 +1523,8 @@ static void asm_hiop(ASMState *as, IRIns *ir)
} else if ((ir-1)->o == IR_XSTORE) {
as->curins--; /* Handle both stores here. */
if ((ir-1)->r != RID_SINK) {
asm_xstore(as, ir, LJ_LE ? 4 : 0);
asm_xstore(as, ir-1, LJ_LE ? 0 : 4);
asm_xstore_(as, ir, LJ_LE ? 4 : 0);
asm_xstore_(as, ir-1, LJ_LE ? 0 : 4);
}
return;
}
@@ -1683,136 +1720,6 @@ static void asm_tail_prep(ASMState *as)
as->invmcp = as->loopref ? as->mcp : NULL;
}
/* -- Instruction dispatch ------------------------------------------------ */
/* Assemble a single instruction. */
static void asm_ir(ASMState *as, IRIns *ir)
{
switch ((IROp)ir->o) {
/* Miscellaneous ops. */
case IR_LOOP: asm_loop(as); break;
case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
case IR_USE:
ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
case IR_PHI: asm_phi(as, ir); break;
case IR_HIOP: asm_hiop(as, ir); break;
case IR_GCSTEP: asm_gcstep(as, ir); break;
/* Guarded assertions. */
case IR_EQ: case IR_NE:
if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {
as->curins--;
asm_href(as, ir-1, (IROp)ir->o);
break;
}
asm_compeq(as, ir);
break;
case IR_LT: case IR_GE: case IR_LE: case IR_GT:
case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
case IR_ABC:
asm_comp(as, ir);
break;
case IR_RETF: asm_retf(as, ir); break;
/* Bit ops. */
case IR_BNOT: asm_bitnot(as, ir); break;
case IR_BSWAP: asm_bitswap(as, ir); break;
case IR_BAND: asm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI); break;
case IR_BOR: asm_bitop(as, ir, MIPSI_OR, MIPSI_ORI); break;
case IR_BXOR: asm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI); break;
case IR_BSHL: asm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL); break;
case IR_BSHR: asm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL); break;
case IR_BSAR: asm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA); break;
case IR_BROL: lua_assert(0); break;
case IR_BROR: asm_bitror(as, ir); break;
/* Arithmetic ops. */
case IR_ADD: asm_add(as, ir); break;
case IR_SUB: asm_sub(as, ir); break;
case IR_MUL: asm_mul(as, ir); break;
case IR_DIV: asm_fparith(as, ir, MIPSI_DIV_D); break;
case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
case IR_NEG: asm_neg(as, ir); break;
case IR_ABS: asm_fpunary(as, ir, MIPSI_ABS_D); break;
case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
case IR_MIN: asm_min_max(as, ir, 0); break;
case IR_MAX: asm_min_max(as, ir, 1); break;
case IR_FPMATH:
if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
break;
if (ir->op2 <= IRFPM_TRUNC)
asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2);
else if (ir->op2 == IRFPM_SQRT)
asm_fpunary(as, ir, MIPSI_SQRT_D);
else
asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
break;
/* Overflow-checking arithmetic ops. */
case IR_ADDOV: asm_arithov(as, ir); break;
case IR_SUBOV: asm_arithov(as, ir); break;
case IR_MULOV: asm_mulov(as, ir); break;
/* Memory references. */
case IR_AREF: asm_aref(as, ir); break;
case IR_HREF: asm_href(as, ir, 0); break;
case IR_HREFK: asm_hrefk(as, ir); break;
case IR_NEWREF: asm_newref(as, ir); break;
case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
case IR_FREF: asm_fref(as, ir); break;
case IR_STRREF: asm_strref(as, ir); break;
/* Loads and stores. */
case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
asm_ahuvload(as, ir);
break;
case IR_FLOAD: asm_fload(as, ir); break;
case IR_XLOAD: asm_xload(as, ir); break;
case IR_SLOAD: asm_sload(as, ir); break;
case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
case IR_FSTORE: asm_fstore(as, ir); break;
case IR_XSTORE: asm_xstore(as, ir, 0); break;
/* Allocations. */
case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
case IR_TNEW: asm_tnew(as, ir); break;
case IR_TDUP: asm_tdup(as, ir); break;
case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
/* Buffer operations. */
case IR_BUFHDR: asm_bufhdr(as, ir); break;
case IR_BUFPUT: asm_bufput(as, ir); break;
case IR_BUFSTR: asm_bufstr(as, ir); break;
/* Write barriers. */
case IR_TBAR: asm_tbar(as, ir); break;
case IR_OBAR: asm_obar(as, ir); break;
/* Type conversions. */
case IR_CONV: asm_conv(as, ir); break;
case IR_TOBIT: asm_tobit(as, ir); break;
case IR_TOSTR: asm_tostr(as, ir); break;
case IR_STRTO: asm_strto(as, ir); break;
/* Calls. */
case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
case IR_CALLXS: asm_callx(as, ir); break;
case IR_CARG: break;
default:
setintV(&as->J->errinfo, ir->o);
lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
break;
}
}
/* -- Trace setup --------------------------------------------------------- */
/* Ensure there are enough stack slots for call arguments. */