- Home
- :
- CodeWarrior
- :
- CodeWarrior for MCU
- :
- CodeWarrior 8- & 16-bit tools: Looking for 16 X 16...

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

CodeWarrior 8- & 16-bit tools: Looking for 16 X 16 bits FAST multiplication trick

01-27-2006
07:07 PM

1,471 Views

marc_paquette

Contributor V

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

To help you find solutions to problems that have already been solved, we have posted this message. It contains an entire topic ported from a separate forum. The original message and all replies are in this single message.

Dear all,

In my application I need to perform 16x16 bits, result on 32 bits multiplications but very fast.

When coding this :

long a;

int c,d;

a = c * d;

int c,d;

a = c * d;

the compiler uses _IMUL because it requires to be casted and of course the result is false but this is performed very fast.

When coding :

a = (long) c * d;

The result is correct and the compiler uses _LMUL library function. The _LMUL routine calls other routines :

ENTER_BINARY_L

LMUL_k_is_k_mul_j

k_is_k_plus_j_l

LMUL_k_is_k_mul_j

k_is_k_plus_j_l

This is very long to perform all these routines and I guess it could be improved

Has anybody got trick on how to code a fast 16x16 multiplication ?

Best regards

Stephane

Stephane

HiStephane,

You might see a slight speed improvement if you specified that the compiler should optimize the code for time (-Ot) instead of size, which will place all the routines as inline code rather than separate functions.

Other than that, it really matters if on what processor you are using and a lot of other things. You'd have to open an service request and even then I cna't assure you that there will be a quick solution.

Ron

** Posted: Jul 16, 2004 - 02:46 AM **

In fact I've coded something less heavy than the library multiplication.

For instance on a HC08QL4 at clk=3.2MHz, , the 16x16 takes 200 us. When coding myslef a 16x16 it takes 60us. Better isn't it ?

But of course my function is less easy to use than the classic multiplication. The C multiplication manages all cases whereas I need to know exactly what I'm going to do when using my multiplication.

Now my problem is how to pass 2 16-bits paramters and how to read a 32-bit returned value

I'm investigating....

Thanks for your answer.

Stephane

Yes our engineers said the best thing would be for you to create your own function and use that instead of the multiplaction operator. Did you try long 16bitMul(short short) to pass 16's and return a 32 bit? (note that HC tools are no where near my area, and that is just a random thought from a C point of view)

Ron

_________________

Ron Liechty

Ombudsman for Metrowerks

Ron Liechty

Ombudsman for Metrowerks

0 Replies