From e235a33679cb84c6274ebb79447bc53aa91c8f88 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 21 Jul 2022 20:39:36 +0300 Subject: [PATCH] Fix negaive DIV/MOD --- ir_x86.dasc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ir_x86.dasc b/ir_x86.dasc index 78676ac..49cb6aa 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -3038,7 +3038,13 @@ static void ir_emit_mul_div_mod(ir_ctx *ctx, ir_ref def, ir_insn *insn) } } else { if (IR_IS_TYPE_SIGNED(type)) { - | cdq + if (ir_type_size[type] == 8) { + | cqo + } else if (ir_type_size[type] == 4) { + | cdq + } else if (ir_type_size[type] == 2) { + | cwd + } if (op2_reg != IR_REG_NONE) { | ASM_REG_OP idiv, type, op2_reg } else {