qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Julian Seward <jseward@acm.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Fix overflow conditions for MIPS add / subtract
Date: Fri, 28 Apr 2006 16:52:07 +0100	[thread overview]
Message-ID: <200604281652.07359.jseward@acm.org> (raw)
In-Reply-To: <20060428132818.GA27384@nevyn.them.org>


> > -    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

The definitive reference for all this bit twiddling magic and
much more besides is an excellent book, "Hacker's Delight", by
Hank Warren.  It has loads of stuff about integer overflow and
whatnot.

J

      parent reply	other threads:[~2006-04-28 15:52 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
2006-04-28 14:51   ` Dirk Behme
2006-04-28 15:47     ` Daniel Jacobowitz
2006-04-28 15:52   ` Julian Seward [this message]

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=200604281652.07359.jseward@acm.org \
    --to=jseward@acm.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).