Fix test for two's complement overflow
PATCH 1/1 Fix test for two's complement overflow
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(-)
target-mips/op.c 15 Feb 2006 16:15:45 -0000 renamed from target-mips/op.c 5 Dec 2005 19:59:36 -0000 +9 -9
@@ -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(); }