On 2008-04-28, David Brown <[email protected]> wrote:
> Grant Edwards wrote:

>>>> Cast one or both operands to 32-bit and C will give you a 32
>>>> bit result. Or copy one to a 32-bit and use that as the
>>>> result.
>>>
>>> but, if you promote operands to 32-bit, the compiler will use
>>> 32x32->32 multiply, which is not implemented in hardware on
>>> msp430 (presumably it'll be a library call). The relevant
>>> question is how to trigger the code generator to emit the MPY
>>> instruction that takes two 16-bit operands and produces a
>>> 32-bit result.
>> 
>> That question has come up a couple times in the past, and IIRC,
>> the answer is that there's no practical way to get GCC to do
>> that.

I must have mis-remembered the previous threads, because
casting either or both of the operands does exactly what the OP
wants:

#include <stdint.h>
uint32_t foo(uint16_t a, uint16_t b)
{
  return (uint32_t)a * b;
}


foo:
        push    r2
        dint
        nop
        mov     r15, &__MPY
        mov     r14, &__OP2
        mov     &__RESLO, r14
        mov     &__RESHI, r15
        pop     r2
        ret

I get the same generated code if I cast both operands, so I
don't really understand what the OP is complaining about...

-- 
Grant Edwards                   grante             Yow! DIDI ... is that a
                                  at               MARTIAN name, or, are we
                               visi.com            in ISRAEL?


Reply via email to