Commit 76e050c2e62995f1d6905e28674dea3a7fcff1a5

Authored by bellard
1 parent da2414e9

Fix overflow conditions for MIPS add / subtract (Stefan Weil)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1828 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 4 additions and 2 deletions
target-mips/op.c
@@ -206,7 +206,8 @@ void op_addo (void) @@ -206,7 +206,8 @@ void op_addo (void)
206 206
207 tmp = T0; 207 tmp = T0;
208 T0 += T1; 208 T0 += T1;
209 - if ((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31)) { 209 + if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 31) {
  210 + /* operands of same sign, result different sign */
210 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW); 211 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
211 } 212 }
212 RETURN(); 213 RETURN();
@@ -224,7 +225,8 @@ void op_subo (void) @@ -224,7 +225,8 @@ void op_subo (void)
224 225
225 tmp = T0; 226 tmp = T0;
226 T0 = (int32_t)T0 - (int32_t)T1; 227 T0 = (int32_t)T0 - (int32_t)T1;
227 - if (!((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31))) { 228 + if (((tmp ^ T1) & (tmp ^ T0)) >> 31) {
  229 + /* operands of different sign, first operand and result different sign */
228 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW); 230 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
229 } 231 }
230 RETURN(); 232 RETURN();