From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F9PSh-0007hO-5G for qemu-devel@nongnu.org; Wed, 15 Feb 2006 11:25:03 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F9PSb-0007ct-Nt for qemu-devel@nongnu.org; Wed, 15 Feb 2006 11:25:01 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F9PSb-0007c9-Cm for qemu-devel@nongnu.org; Wed, 15 Feb 2006 11:24:57 -0500 Received: from [194.74.144.146] (helo=bacchus.dhis.org) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1F9PXX-0004Ls-5Z for qemu-devel@nongnu.org; Wed, 15 Feb 2006 11:30:03 -0500 Date: Wed, 15 Feb 2006 16:22:31 +0000 From: Ralf Baechle Message-ID: <20060215162231.GA14397@linux-mips.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] Fix test for two's complement overflow Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fabrice Bellard , qemu-devel@nongnu.org Hi Fabrice, A sequence like addiu $r0, $r0, 1 addi $r0, $r0, -1 would result in an integer overflow exception on MIPS targets. This test fixes the test for a signed overflow done by the add, addi, sub and subi instructions. target-mips/op.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) --- suckage/target-mips/op.c 5 Dec 2005 19:59:36 -0000 +++ suckage/target-mips/op.c 15 Feb 2006 16:15:45 -0000 @@ -202,13 +202,13 @@ void op_addo (void) { - target_ulong tmp; + uint64_t tmp; - tmp = T0; - T0 += T1; - if ((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31)) { + tmp = (int64_t) (int32_t) T0 + (int64_t) (int32_t) T1; + if (((tmp >> 32) ^ (tmp >> 31)) & 1) CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW); - } + + T0 = tmp; RETURN(); } @@ -222,11 +222,11 @@ { target_ulong tmp; - tmp = T0; - T0 = (int32_t)T0 - (int32_t)T1; - if (!((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31))) { + tmp = (int64_t) (int32_t) T0 - (int64_t) (int32_t) T1; + if (((tmp >> 32) ^ (tmp >> 31)) & 1) CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW); - } + + T0 = tmp; RETURN(); }