From: Ralf Baechle <ralf@linux-mips.org>
To: Fabrice Bellard <fabrice@bellard.org>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Fix test for two's complement overflow
Date: Wed, 15 Feb 2006 16:22:31 +0000 [thread overview]
Message-ID: <20060215162231.GA14397@linux-mips.org> (raw)
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();
}
reply other threads:[~2006-02-15 16:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060215162231.GA14397@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=fabrice@bellard.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).