From 772cbe11d1ef6628009b38e3fe56ad1629248b3c Mon Sep 17 00:00:00 2001 From: bellard Date: Sun, 23 Apr 2006 15:18:58 +0000 Subject: [PATCH] Fix overflow conditions for MIPS add / subtract (Stefan Weil) --- target-mips/op.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target-mips/op.c b/target-mips/op.c index 71abd95b..e0d3463b 100644 --- a/target-mips/op.c +++ b/target-mips/op.c @@ -206,7 +206,8 @@ void op_addo (void) tmp = T0; T0 += T1; - if ((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31)) { + if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 31) { + /* operands of same sign, result different sign */ CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW); } RETURN(); @@ -224,7 +225,8 @@ void op_subo (void) tmp = T0; T0 = (int32_t)T0 - (int32_t)T1; - if (!((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31))) { + if (((tmp ^ T1) & (tmp ^ T0)) >> 31) { + /* operands of different sign, first operand and result different sign */ CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW); } RETURN(); -- 2.39.5