On 20/02/2012 13:31, Miloslav Semler wrote:
> Thank you,
> my mistake as I have not read specifications in detail. I did some
> solution in assembly (inline function mul16 which multiplies two 16bit
> integers and returns 32bit integer and uses hw multiplier).
>
Did you check the generated assembly when using C properly?
With gcc 4.4.5 (not the latest version, but the one I have handy), I get
optimal assembly code:
int32_t multTest(int16_t a, int16_t b) {
return ((int32_t) a) * b;
}
56 multTest:
57 /* prologue ends here (frame size = 0) */
58 .L__FrameSize_multTest=0x0
GAS LISTING e:\temp\ccI7v7Wb.s page 2
59 .L__FrameOffset_multTest=0x0
60 0000 0212 push r2
61 0002 32C2 dint
62 0004 0343 nop
63 0006 824E 3201 mov r14, &__MPYS ; b
64 000a 824F 3801 mov r15, &__OP2 ; a
65 000e 1E42 3A01 mov &__RESLO, r14 ;
66 0012 1F42 3C01 mov &__RESHI, r15 ;
67 0016 3241 pop r2
68
69 /* epilogue: not required */
70 0018 3041 ret
Don't use inline assembly unless you cannot get the appropriate code
from the compiler - and even then, only if the function is so
time-critical that it is worth using assembly.
mvh.,
David
> -- Miloslav
>> On 02/19/2012 01:43 PM, Miloslav Semler wrote:
>>
>>> Which is wrong for me as it discards high word from result (RESHI is not
>>> copied, instead it is used an sign extension). Routine div32768 accepts
>>> 32bit signed integer.
>>>
>>>
>> You seem to be complaining that a 16X16 multiply returns only a 16 bit
>> result. This is standard across all C compilers.
>>
>>
>> If you need a 32 bit result you have two options:
>>
>> 1) Promote one or both arguments to 32 bits to force a 32X32 multiply
>> with a 32 bit result.
>> 2) Roll your own code if you need something faster.
>>
>> It is possible that buried somewhere in the standard library is a
>> function that does this but I have never seen one.
>>
>>
>>
>
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users