From: Daniel Jacobowitz <drow@false.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Fix overflow conditions for MIPS add / subtract
Date: Fri, 28 Apr 2006 09:28:18 -0400 [thread overview]
Message-ID: <20060428132818.GA27384@nevyn.them.org> (raw)
In-Reply-To: <443E9D2F.5050807@mail.berlios.de>
On Thu, Apr 13, 2006 at 08:49:19PM +0200, Stefan Weil wrote:
> - if ((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31)) {
> + if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 31) {
> + /* operands of same sign, result different sign */
> CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
> }
I see this went in, but - huh? The math doesn't make sense.
T0 ^ T1 -> operands of different sign
tmp ^ T1 ^ (-1) -> result has same sign as T1
Which is a "who cares" case. This is addition, it can't overflow if
the operands have the same sign.
> - if (!((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31))) {
> + if (((tmp ^ T1) & (tmp ^ T0)) >> 31) {
> + /* operands of different sign, first operand and result
> different sign */
> CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
> }
tmp ^ T1 -> result and T1 of different sign
tmp ^ T0 -> result and T0 of different sign
Which implies that the operands have the same sign. Again, this case
can't overflow.
I haven't tested the patched qemu, but I did test the expressions
themselves in standalone code, and they definitely do not detect
overflow.
--
Daniel Jacobowitz
CodeSourcery
next prev parent reply other threads:[~2006-04-28 13:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-13 18:49 [Qemu-devel] [PATCH] Fix overflow conditions for MIPS add / subtract Stefan Weil
2006-04-28 13:28 ` Daniel Jacobowitz [this message]
2006-04-28 14:51 ` Dirk Behme
2006-04-28 15:47 ` Daniel Jacobowitz
2006-04-28 15:52 ` Julian Seward
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=20060428132818.GA27384@nevyn.them.org \
--to=drow@false.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).