This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: why mult generated for unsigned int multiply on mips?


> It would, however, be nice if you actually posted an answer to your
> (now solved) question. That way, any casual reader may learn something
> new.
>
Sorry for the unintentional offense, here comes the method:
for 2's complement binary number x31x30...x0,
unsigned value U = 2^(31)*x31 + 2^(30)*x30 + ... + 2^(0)*x0
signed value S = - 2^(31)*x31 + 2^(30)*x30 + ... + 2^(0)*x0
say V =  2^(30)*x30 + ... + 2^(0)*x0, and s = x31
so,  S = U - 2^(32)*s.

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

-- 
Best Regards.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]