Amker.Cheng wrote:
now think about two number U1, U2, the corresponding signed value are S1, S2. S1 * S2 = (U1-2^32 *s1 ) * (U2-2^32 *s2) = U1*U2 - 2^32*s2*U1 - 2^32*s1*U2 + 2^64*s1*s2 It's easy to prove that the lower 32 bit of S1*S2 is determined by the lower part of U1*U2.Maybe this is the reason gcc can safely use mult for unsigned multiplication for mips. Hope this is right and it's hard to edit equations in plain text -_-
Yes this is right, it's well known that for multiplication of 32 x 32 => 32, unsigned and signed are equivalent except for overflow considerations. The only reason a processor would have separate signed and unsigned single length multiplication instructions is if there are overflow traps, or overflow or other arithmetic flags set. In other words the same situation as for addition/subtraction. Note that for a double length result multplication, the results are quite different. Consider -1 * -1, the result is +1 signed, so FFFF*FFFF signed = 0000_0001 but FFFF*FFFF unsigned is FFFE_0001 Note that as we expect, the low order 32 bits is the same. For division, even the single length quotient is different, so there you need two instructions, or if the processor has only unsigned division, then you have to fiddle to get a signed result.
