On 2007-03-25, Neil Wyper <[email protected]> wrote:

>> Almost.  But that's nothign to do with my quuestion: For the
>> above code why are u1 and u2 converted to 32-bit values before
>> being passed to the 16x16=>32 multiply routine?
>>
>> > but don't expect other compilers to show the same behavior.
>>
>> I expect any decent compiler to recognize that it only needs to
>> do a 16x16=>32 multiply, but that's got nothing to do with my
>> question.
>
>
> I think the two clr instructions come come from these lines in the machine
> description file (gcc/config/msp430/msp430.c):

Yes. I know that. 

Why are they there?  umulhisi3 is a 16x16=>32 multiply
operation, so why are the operands being converted to 32 bits?

> I'm not an expert on the GCC internals, but it looks like no
> one has taken the time to write a 16 X 16 = 32 bit
> multiplication yet, and it was faked by making the umulhisi3
> take SI arguments before calling __umulhisi3().

That's my guess.  There are other targets that also call mulsi3
from umulhisi3, but the umulhisi3 still accepts 16-bit operands
and converts them to 32 bits before calling umulsi3.  That
would seem to be the proper way to do it rather than making
umulhisi3 require 32-bit operands.

> Note the zero_extend:SI in the define_expand block, and the
> clobber lines in the define_insn block.

Yup.

> So, GCC recognizes that it can do a 16X16 multiply with 32 bit
> result and uses umulhisi3.  The MSP430 port, in turn, forces
> the inputs to umulhisi3 to be zero extended to SI arguments,
> then calls __umulhisi3, which is nothing more than "br
> #__mulsi3" (in libgcc.S).

Right.

> So, the compiler (GCC common code) is smart enough to recognize what you
> expect it to, and the MSP430 port generates code that is functional in all
> situations, but slower than it could be.  It looks like it would be
> straightforward to fix msp430.md and libgcc.S if the two "clr" instructions
> are a problem in your case.

They're not a problem, I was just wondering why the 16->32 bit
conversion isn't done by umulhisi3, which one would expect to
accept 16-bit operands.

-- 
Grant Edwards                   grante             Yow!  CHUBBY CHECKER just
                                  at               had a CHICKEN SANDWICH in
                               visi.com            downtown DULUTH!


Reply via email to