On 2007-03-23, Ralf Hildebrandt <[email protected]> wrote:
> Grant Edwards wrote:
>> uint32_t r;
>>         
>> void foo(uint16_t u1, uint16_t u2)
>>   {
>>     r = (uint32_t)u1 * (uint32_t)u2;
>>   }
>
> This will result in a 32x32 Bit Multiplication with the result
> cropped to 32 Bits.

Which is identical to a 16x16 multiply with a 32 bit result.

> Try:
>
> r = (uint32_t)u1 * u2;

GCC generates the exact same code (as it should).

> Smart compilers will then recognize that you are demanding a 
> 16x16=>32Bit multiplication. 

I know.

> This is a common problem of C-compilers and it is said that
> most of them recognize it this way.

GCC did recognize it.  That's why it called umulhisi3 instead
of umulsi3.  umulhisi3 is 16x16->32, umulsi3 is 32x32.  

Why does umulhisi3 require 32-bit operands?

-- 
Grant Edwards                   grante             Yow!  ... I want a COLOR
                                  at               T.V. and a VIBRATING BED!!!
                               visi.com            


Reply via email to