All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix test for two's complement overflow
@ 2006-02-15 16:22 Ralf Baechle
  0 siblings, 0 replies; only message in thread
From: Ralf Baechle @ 2006-02-15 16:22 UTC (permalink / raw)
  To: Fabrice Bellard, qemu-devel

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();
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-02-15 16:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-15 16:22 [Qemu-devel] [PATCH] Fix test for two's complement overflow Ralf Baechle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.