diff options
Diffstat (limited to 'src/lj_asm.c')
-rw-r--r-- | src/lj_asm.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c index 14d6d849..18944da4 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c | |||
@@ -1641,18 +1641,15 @@ static void asm_conv(ASMState *as, IRIns *ir) | |||
1641 | return; | 1641 | return; |
1642 | #endif | 1642 | #endif |
1643 | } else { /* Integer to FP conversion. */ | 1643 | } else { /* Integer to FP conversion. */ |
1644 | Reg tmp = (LJ_64 && st == IRT_U64) ? ra_scratch(as, RSET_GPR) : RID_NONE; | ||
1645 | Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ? | 1644 | Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ? |
1646 | ra_alloc1(as, lref, RSET_GPR) : | 1645 | ra_alloc1(as, lref, RSET_GPR) : |
1647 | asm_fuseload(as, lref, RSET_GPR); | 1646 | asm_fuseload(as, lref, RSET_GPR); |
1648 | if (LJ_64 && st == IRT_U64) { | 1647 | if (LJ_64 && st == IRT_U64) { |
1649 | Reg tmpn = ra_scratch(as, rset_exclude(RSET_FPR, dest)); | ||
1650 | MCLabel l_end = emit_label(as); | 1648 | MCLabel l_end = emit_label(as); |
1651 | emit_rr(as, XO_ADDSD, dest, tmpn); | 1649 | const void *k = lj_ir_k64_find(as->J, U64x(43f00000,00000000)); |
1652 | emit_rr(as, XO_MOVD, tmpn|REX_64, tmp); | 1650 | emit_rma(as, XO_ADDSD, dest, k); /* Add 2^64 to compensate. */ |
1653 | emit_loadu64(as, tmp, U64x(43f00000,00000000)); | ||
1654 | emit_sjcc(as, CC_NS, l_end); | 1651 | emit_sjcc(as, CC_NS, l_end); |
1655 | emit_rr(as, XO_TEST, left|REX_64, left); | 1652 | emit_rr(as, XO_TEST, left|REX_64, left); /* Check if u64 >= 2^63. */ |
1656 | } | 1653 | } |
1657 | emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS, | 1654 | emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS, |
1658 | dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left); | 1655 | dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left); |
@@ -1675,15 +1672,22 @@ static void asm_conv(ASMState *as, IRIns *ir) | |||
1675 | ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSD2SI : XO_CVTSD2SI) : | 1672 | ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSD2SI : XO_CVTSD2SI) : |
1676 | ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSS2SI : XO_CVTSS2SI); | 1673 | ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSS2SI : XO_CVTSS2SI); |
1677 | if (LJ_64 && irt_isu64(ir->t)) { | 1674 | if (LJ_64 && irt_isu64(ir->t)) { |
1678 | Reg left = ra_alloc1(as, lref, RSET_FPR); | 1675 | const void *k = lj_ir_k64_find(as->J, U64x(c3f00000,00000000)); |
1679 | Reg tmpn = ra_scratch(as, rset_exclude(RSET_FPR, left)); | ||
1680 | MCLabel l_end = emit_label(as); | 1676 | MCLabel l_end = emit_label(as); |
1681 | emit_rr(as, op, dest|REX_64, tmpn); | 1677 | Reg left = IR(lref)->r; |
1682 | emit_rr(as, XO_ADDSD, tmpn, left); | 1678 | /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */ |
1683 | emit_rr(as, XO_MOVD, tmpn|REX_64, dest); | 1679 | if (ra_hasreg(left)) { |
1684 | emit_loadu64(as, dest, U64x(c3f00000,00000000)); | 1680 | Reg tmpn = ra_scratch(as, rset_exclude(RSET_FPR, left)); |
1681 | emit_rr(as, op, dest|REX_64, tmpn); | ||
1682 | emit_rr(as, XO_ADDSD, tmpn, left); | ||
1683 | emit_rma(as, XMM_MOVRM(as), tmpn, k); | ||
1684 | } else { | ||
1685 | left = ra_allocref(as, lref, RSET_FPR); | ||
1686 | emit_rr(as, op, dest|REX_64, left); | ||
1687 | emit_rma(as, XO_ADDSD, left, k); | ||
1688 | } | ||
1685 | emit_sjcc(as, CC_NS, l_end); | 1689 | emit_sjcc(as, CC_NS, l_end); |
1686 | emit_rr(as, XO_TEST, dest|REX_64, dest); | 1690 | emit_rr(as, XO_TEST, dest|REX_64, dest); /* Check if dest < 2^63. */ |
1687 | emit_rr(as, op, dest|REX_64, left); | 1691 | emit_rr(as, op, dest|REX_64, left); |
1688 | } else { | 1692 | } else { |
1689 | Reg left = asm_fuseload(as, lref, RSET_FPR); | 1693 | Reg left = asm_fuseload(as, lref, RSET_FPR); |