From ba10efdc410a6c15bb400c07463d0913be5f3339 Mon Sep 17 00:00:00 2001 From: UEPuepUEP <131212563+UEPuepUEP@users.noreply.github.com> Date: Wed, 19 Apr 2023 09:11:33 -0400 Subject: [PATCH 1/3] Update arch_mips.py --- m2c/arch_mips.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/m2c/arch_mips.py b/m2c/arch_mips.py index 7bd0ce23..c8ff4d60 100644 --- a/m2c/arch_mips.py +++ b/m2c/arch_mips.py @@ -871,7 +871,7 @@ def normalize_instruction(cls, instr: AsmInstruction) -> AsmInstruction: return AsmInstruction("li", [args[0], lit]) if instr.mnemonic == "jalr" and args[0] != Register("ra"): raise DecompFailure("Two-argument form of jalr is not supported.") - if instr.mnemonic in ("mult", "multu", "dmult", "dmultu", "madd", "maddu"): + if instr.mnemonic in ("mult", "multu", "dmult", "dmultu", "madd", "maddu", "msub", "msubu"): return AsmInstruction(instr.mnemonic, [Register("zero"), *args]) if instr.mnemonic in LENGTH_THREE: return cls.normalize_instruction( @@ -1182,6 +1182,13 @@ def eval_fn(s: NodeState, a: InstrArgs) -> None: outputs = [Register("hi"), Register("lo")] if args[0] != Register("zero"): outputs.append(args[0]) + + inputs = [args[1], args[2]] + if mnemonic in ("msub", "msubu"): + inputs.append(Register("lo")) + outputs = [Register("hi"), Register("lo")] + if args[0] != Register("zero"): + outputs.append(args[0]) def eval_fn(s: NodeState, a: InstrArgs) -> None: hi, lo = cls.instrs_hi_lo[mnemonic](a) @@ -1441,6 +1448,24 @@ def eval_fn(s: NodeState, a: InstrArgs) -> None: a, ), ), + "msub": lambda a: ( + ErrorExpr("msub top half"), + handle_add_real( + Register("lo"), + a.regs[Register("lo")], + UnaryOp("-", BinaryOp.int(a.reg(1), "*", a.reg(2))), + a, + ), + ), + "msubu": lambda a: ( + ErrorExpr("msubu top half"), + handle_add_real( + Register("lo"), + a.regs[Register("lo")], + UnaryOp("-", BinaryOp.int(a.reg(1), "*", a.reg(2))), + a, + ), + ), } instrs_destination_first: InstrMap = { # Flag-setting instructions From c6cdf6aa922394f0c9832726e34c2c75c6c1aade Mon Sep 17 00:00:00 2001 From: UEPuepUEP <131212563+UEPuepUEP@users.noreply.github.com> Date: Wed, 19 Apr 2023 20:58:52 -0400 Subject: [PATCH 2/3] Update arch_mips.py --- m2c/arch_mips.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/m2c/arch_mips.py b/m2c/arch_mips.py index c8ff4d60..33670dc8 100644 --- a/m2c/arch_mips.py +++ b/m2c/arch_mips.py @@ -1456,16 +1456,16 @@ def eval_fn(s: NodeState, a: InstrArgs) -> None: UnaryOp("-", BinaryOp.int(a.reg(1), "*", a.reg(2))), a, ), - ), - "msubu": lambda a: ( - ErrorExpr("msubu top half"), - handle_add_real( - Register("lo"), - a.regs[Register("lo")], - UnaryOp("-", BinaryOp.int(a.reg(1), "*", a.reg(2))), - a, ), - ), + "msubu": lambda a: ( + ErrorExpr("msubu top half"), + handle_add_real( + Register("lo"), + a.regs[Register("lo")], + UnaryOp("-", BinaryOp.int(a.reg(1), "*", a.reg(2))), + a, + ), + ), } instrs_destination_first: InstrMap = { # Flag-setting instructions From 027ffccee9cef1d2ce08765420c694573c90e385 Mon Sep 17 00:00:00 2001 From: UEPuepUEP <131212563+UEPuepUEP@users.noreply.github.com> Date: Thu, 20 Apr 2023 10:33:04 -0400 Subject: [PATCH 3/3] Update arch_mips.py --- m2c/arch_mips.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/m2c/arch_mips.py b/m2c/arch_mips.py index 33670dc8..23ad4a15 100644 --- a/m2c/arch_mips.py +++ b/m2c/arch_mips.py @@ -1177,14 +1177,7 @@ def eval_fn(s: NodeState, a: InstrArgs) -> None: and isinstance(args[2], Register) ) inputs = [args[1], args[2]] - if mnemonic in ("madd", "maddu"): - inputs.append(Register("lo")) - outputs = [Register("hi"), Register("lo")] - if args[0] != Register("zero"): - outputs.append(args[0]) - - inputs = [args[1], args[2]] - if mnemonic in ("msub", "msubu"): + if mnemonic in ("madd", "maddu", "msub", "msubu"): inputs.append(Register("lo")) outputs = [Register("hi"), Register("lo")] if args[0] != Register("zero"):