提交 276824dd 编写于 作者: Z Zoltan Varga

[jit] Emit div checks if MONO_ARCH_NEED_DIV_CHECK is enabled even when div...

[jit] Emit div checks if MONO_ARCH_NEED_DIV_CHECK is enabled even when div instructions are not emulated. Enable div checks for tvos.
上级 75ad142b
......@@ -447,26 +447,30 @@ mono_decompose_opcode (MonoCompile *cfg, MonoInst *ins)
case OP_IREM:
case OP_IDIV_UN:
case OP_IREM_UN:
if (cfg->backend->emulate_div && !mono_arch_opcode_needs_emulation (cfg, ins->opcode)) {
if (cfg->backend->need_div_check) {
int reg1 = alloc_ireg (cfg);
int reg2 = alloc_ireg (cfg);
/* b == 0 */
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, ins->sreg2, 0);
MONO_EMIT_NEW_COND_EXC (cfg, IEQ, "DivideByZeroException");
if (ins->opcode == OP_IDIV || ins->opcode == OP_IREM) {
/* b == -1 && a == 0x80000000 */
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, ins->sreg2, -1);
MONO_EMIT_NEW_UNALU (cfg, OP_ICEQ, reg1, -1);
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, ins->sreg1, 0x80000000);
MONO_EMIT_NEW_UNALU (cfg, OP_ICEQ, reg2, -1);
MONO_EMIT_NEW_BIALU (cfg, OP_IAND, reg1, reg1, reg2);
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, reg1, 1);
MONO_EMIT_NEW_COND_EXC (cfg, IEQ, "OverflowException");
}
if (cfg->backend->need_div_check) {
int reg1 = alloc_ireg (cfg);
int reg2 = alloc_ireg (cfg);
/* b == 0 */
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, ins->sreg2, 0);
MONO_EMIT_NEW_COND_EXC (cfg, IEQ, "DivideByZeroException");
if (ins->opcode == OP_IDIV || ins->opcode == OP_IREM) {
/* b == -1 && a == 0x80000000 */
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, ins->sreg2, -1);
MONO_EMIT_NEW_UNALU (cfg, OP_ICEQ, reg1, -1);
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, ins->sreg1, 0x80000000);
MONO_EMIT_NEW_UNALU (cfg, OP_ICEQ, reg2, -1);
MONO_EMIT_NEW_BIALU (cfg, OP_IAND, reg1, reg1, reg2);
MONO_EMIT_NEW_ICOMPARE_IMM (cfg, reg1, 1);
MONO_EMIT_NEW_COND_EXC (cfg, IEQ, "OverflowException");
}
MONO_EMIT_NEW_BIALU (cfg, ins->opcode, ins->dreg, ins->sreg1, ins->sreg2);
NULLIFY_INS (ins);
break;
}
if (cfg->backend->emulate_div && !mono_arch_opcode_needs_emulation (cfg, ins->opcode)) {
MONO_EMIT_NEW_BIALU (cfg, ins->opcode, ins->dreg, ins->sreg1, ins->sreg2);
NULLIFY_INS (ins);
} else {
emulate = TRUE;
}
......
......@@ -365,6 +365,11 @@ typedef struct {
#define MONO_ARCH_HAVE_TLS_GET_REG 1
#endif
#if defined(TARGET_APPLETVOS)
/* No signals */
#define MONO_ARCH_NEED_DIV_CHECK 1
#endif
/* Used for optimization, not complete */
#define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册