From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FZVGN-0001rm-DC for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:52:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FZVGL-0001rU-9e for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:52:10 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FZVGL-0001rR-6X for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:52:09 -0400 Received: from [81.103.221.48] (helo=mtaout02-winn.ispmail.ntl.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FZVJV-000064-4A for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:55:25 -0400 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20060428155207.DYYK29040.mtaout02-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Fri, 28 Apr 2006 16:52:07 +0100 Received: from suse10.valgrind.org ([82.21.96.252]) by aamtaout02-winn.ispmail.ntl.com with ESMTP id <20060428155207.DWVE24467.aamtaout02-winn.ispmail.ntl.com@suse10.valgrind.org> for ; Fri, 28 Apr 2006 16:52:07 +0100 From: Julian Seward Subject: Re: [Qemu-devel] [PATCH] Fix overflow conditions for MIPS add / subtract Date: Fri, 28 Apr 2006 16:52:07 +0100 References: <443E9D2F.5050807@mail.berlios.de> <20060428132818.GA27384@nevyn.them.org> In-Reply-To: <20060428132818.GA27384@nevyn.them.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200604281652.07359.jseward@acm.org> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.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