[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] Fix test for two's complement overflow
From: |
Ralf Baechle |
Subject: |
[Qemu-devel] [PATCH] Fix test for two's complement overflow |
Date: |
Wed, 15 Feb 2006 16:22:31 +0000 |
User-agent: |
Mutt/1.4.2.1i |
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();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH] Fix test for two's complement overflow,
Ralf Baechle <=