From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLZW9-0002mL-Sb for qemu-devel@nongnu.org; Wed, 11 Feb 2015 10:47:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLZW3-0005bb-U8 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 10:47:57 -0500 Received: from mail.uni-paderborn.de ([131.234.142.9]:38782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLZW3-0005bJ-Op for qemu-devel@nongnu.org; Wed, 11 Feb 2015 10:47:51 -0500 From: Bastian Koppelmann Date: Wed, 11 Feb 2015 16:48:59 +0000 Message-Id: <1423673343-25688-3-git-send-email-kbastian@mail.uni-paderborn.de> In-Reply-To: <1423673343-25688-1-git-send-email-kbastian@mail.uni-paderborn.de> References: <1423673343-25688-1-git-send-email-kbastian@mail.uni-paderborn.de> Subject: [Qemu-devel] [PATCH v2 2/6] target-tricore: fix msub32_suov return wrong results List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: rth@twiddle.net If the signed result of the multiplication overflows, we would get a negative value, which would result in a addition instead of a subtraction. Now we do the overflow calculation and saturation by hand instead of using suov32_neg. Signed-off-by: Bastian Koppelmann --- target-tricore/op_helper.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/target-tricore/op_helper.c b/target-tricore/op_helper.c index ed26b30..08bf4ae 100644 --- a/target-tricore/op_helper.c +++ b/target-tricore/op_helper.c @@ -443,13 +443,28 @@ target_ulong helper_msub32_ssov(CPUTriCoreState *env, target_ulong r1, target_ulong helper_msub32_suov(CPUTriCoreState *env, target_ulong r1, target_ulong r2, target_ulong r3) { - int64_t t1 = extract64(r1, 0, 32); - int64_t t2 = extract64(r2, 0, 32); - int64_t t3 = extract64(r3, 0, 32); - int64_t result; + uint64_t t1 = extract64(r1, 0, 32); + uint64_t t2 = extract64(r2, 0, 32); + uint64_t t3 = extract64(r3, 0, 32); + uint64_t result; + uint64_t mul; - result = t2 - (t1 * t3); - return suov32_neg(env, result); + mul = (t1 * t3); + result = t2 - mul; + + env->PSW_USB_AV = result ^ result * 2u; + env->PSW_USB_SAV |= env->PSW_USB_AV; + /* we calculate ovf by hand here, because the multiplication can overflow on + the host, which would give false results if we compare to less than + zero */ + if (mul > t2) { + env->PSW_USB_V = (1 << 31); + env->PSW_USB_SV = (1 << 31); + result = 0; + } else { + env->PSW_USB_V = 0; + } + return result; } uint64_t helper_msub64_ssov(CPUTriCoreState *env, target_ulong r1, -- 2.3.0