Rework signed multiplication. Fixed an edge case and passes all tests. (#174)

This commit is contained in:
riperiperi 2018-06-20 14:45:20 +01:00 committed by gdkchan
parent 7084bf58a4
commit 32900cc223

View file

@ -153,13 +153,9 @@ namespace ChocolArm64.Instruction
public static long SMulHi128(long LHS, long RHS) public static long SMulHi128(long LHS, long RHS)
{ {
bool LSign = (LHS < 0); long Result = (long)UMulHi128((ulong)(LHS), (ulong)(RHS));
bool RSign = (RHS < 0); if (LHS < 0) Result -= RHS;
if (RHS < 0) Result -= LHS;
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
return Result; return Result;
} }