From 3c5aa6f4d6b05f61b5dd157e7a67bb5021b94562 Mon Sep 17 00:00:00 2001 From: xdec Date: Sun, 28 Dec 2014 02:12:35 -0800 Subject: [PATCH] Fix underflow issue with USAD8/USADA8. --- src/core/arm/interpreter/armemu.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/arm/interpreter/armemu.cpp b/src/core/arm/interpreter/armemu.cpp index 5d26456c7..322e9f706 100644 --- a/src/core/arm/interpreter/armemu.cpp +++ b/src/core/arm/interpreter/armemu.cpp @@ -6672,10 +6672,10 @@ L_stm_s_takeabort: const u32 rm_val = state->Reg[rm_idx]; const u32 rn_val = state->Reg[rn_idx]; - const u8 diff1 = (u8)std::labs((rn_val & 0xFF) - (rm_val & 0xFF)); - const u8 diff2 = (u8)std::labs(((rn_val >> 8) & 0xFF) - ((rm_val >> 8) & 0xFF)); - const u8 diff3 = (u8)std::labs(((rn_val >> 16) & 0xFF) - ((rm_val >> 16) & 0xFF)); - const u8 diff4 = (u8)std::labs(((rn_val >> 24) & 0xFF) - ((rm_val >> 24) & 0xFF)); + const u8 diff1 = (u8)std::labs( ((s32) (rn_val & 0xFF)) - ((s32) (rm_val & 0xFF)) ); + const u8 diff2 = (u8)std::labs( ((s32) ((rn_val >> 8) & 0xFF)) - ((s32) ((rm_val >> 8) & 0xFF)) ); + const u8 diff3 = (u8)std::labs( ((s32) ((rn_val >> 16) & 0xFF)) - ((s32) ((rm_val >> 16) & 0xFF)) ); + const u8 diff4 = (u8)std::labs( ((s32) ((rn_val >> 24) & 0xFF)) - ((s32) ((rm_val >> 24) & 0xFF)) ); u32 finalDif = (diff1 + diff2 + diff3 + diff4);