On Fri, Dec 7, 2012 at 3:47 AM, Julius Baxter <[email protected]>wrote:

> I thought that unsigned 32-bit x 32-bit going to a 64-bit result
> register can't overflow. I guess signed can, though. 64-bit x 64-bit
> -> 64-bit result register can overflow, of course, so that's in there.
>

These are all 32x32-bit to 64-bit products.  Whether signed or unsigned,
the result always fits in 64 bits.

Unsigned clearly cannot overflow:

(2^32 - 1)*(2^32 - 1) = (2^64 - 2*2^32 - 1) <= 2^64-1

The maximum signed positive 32-bit number is 2^31-1, and the maximum
negative is -2^31.  The maximum positive 64-bit number is 2^63-1, and the
maximum negative is -2^63.

So neither can signed:

Max positive * max positive: (2^31 - 1)*(2^31 - 1) = (2^62 - 2*2^31 + 1) <=
2^63-1

Max positive * max negative: (2^31 - 1)*(-2^31) = (-2^62 + 2^31) >= -2^63

Max negative * max negative: (-2^31)*(-2^31) = (2^62) <= 2^63-1

-Pete
_______________________________________________
OpenRISC mailing list
[email protected]
http://lists.openrisc.net/listinfo/openrisc

Reply via email to