From 32900cc2233f06199b00b7009317dc373bd7e131 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Wed, 20 Jun 2018 14:45:20 +0100 Subject: [PATCH] Rework signed multiplication. Fixed an edge case and passes all tests. (#174) --- Instruction/ASoftFallback.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Instruction/ASoftFallback.cs b/Instruction/ASoftFallback.cs index 3f8ab5e..6a407ba 100644 --- a/Instruction/ASoftFallback.cs +++ b/Instruction/ASoftFallback.cs @@ -153,13 +153,9 @@ namespace ChocolArm64.Instruction public static long SMulHi128(long LHS, long RHS) { - bool LSign = (LHS < 0); - bool RSign = (RHS < 0); - - long Result = (long)UMulHi128((ulong)(LSign ? -LHS : LHS), (ulong)(RSign ? -RHS : RHS)); - - if (LSign != RSign && LHS != 0 && RHS != 0) - return ~Result; //for negative results, hi 64-bits start at 0xFFF... and count back + long Result = (long)UMulHi128((ulong)(LHS), (ulong)(RHS)); + if (LHS < 0) Result -= RHS; + if (RHS < 0) Result -= LHS; return Result; }