[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] Fix overflow conditions for MIPS add / subtract
From: |
Julian Seward |
Subject: |
Re: [Qemu-devel] [PATCH] Fix overflow conditions for MIPS add / subtract |
Date: |
Fri, 28 Apr 2006 16:52:07 +0100 |
User-agent: |
KMail/1.8.2 |
> > - 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