Fix overflow conditions for MIPS add/subtract
PATCH 1/1 Fix overflow conditions for MIPS add/subtract
Fix overflow conditions for MIPS add/subtract as proposed by Daniel Jacobowitz.
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00538.html
Regards
Dirk
op.c renamed from op.c_orig +2 -2
@@ -206,7 +206,7 @@ void op_addo (void) tmp =T0 ;T0 +=T1 ; -if (((tmp ^T1 ^ (-1 )) & (T0 ^T1 )) >>31 ) { +if (~(T0 ^T1 ) & (T0 ^ tmp) &0x80000000 ) {/* operands of same sign, result different sign */ CALL_FROM_TB1 (do_raise_exception_direct,EXCP_OVERFLOW ); }
@@ -225,7 +225,7 @@ void op_subo (void) tmp =T0 ;T0 = (int32_t )T0 - (int32_t )T1 ; -if (((tmp ^T1 ) & (tmp ^T0 )) >>31 ) { +if ((T0 ^T1 ) & (T0 ^ tmp) &0x80000000 ) {/* operands of different sign, first operand and result different sign */ CALL_FROM_TB1 (do_raise_exception_direct,EXCP_OVERFLOW ); }
OK. I hope this is correct now :-)
Just a note : there is already a lot of code in QEMU to compute correctly the overflow and carry flags (for example in the i386 target)... don't spend your time on reinventing them !
Fabrice.
Quoted 43 lines · Dirk Behme
Fix overflow conditions for MIPS add/subtract as proposed by Daniel Jacobowitz.
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00538.html
Regards
Dirk
------------------------------------------------------------------------
op.c renamed from op.c_orig +2
-3@@ -206,7 +206,7 @@ void op_addo (void) tmp =T0 ;T0 +=T1 ; -if (((tmp ^T1 ^ (-1 )) & (T0 ^T1 )) >>31 ) { +if (~(T0 ^T1 ) & (T0 ^ tmp) &0x80000000 ) {/* operands of same sign, result different sign */ CALL_FROM_TB1 (do_raise_exception_direct,EXCP_OVERFLOW ); }@@ -225,7 +225,7 @@ void op_subo (void) tmp =T0 ;T0 = (int32_t )T0 - (int32_t )T1 ; -if (((tmp ^T1 ) & (tmp ^T0 )) >>31 ) { +if ((T0 ^T1 ) & (T0 ^ tmp) &0x80000000 ) {/* operands of different sign, first operand and result different sign */ CALL_FROM_TB1 (do_raise_exception_direct,EXCP_OVERFLOW ); } ------------------------------------------------------------------------_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel