Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Faster integer division with KEIL

2005-12-13 by Tom Walsh

uedogan wrote:

>Hi everybody,
>
>i'm currently working with the LPC2136 and the latest KEIL C-compiler. 
>Does anybody know some functions that provide a (much) faster 16-bit 
>unsigned integer division than KEIL currently has? I have ~58MHz and 
>the division currently needs about 2us.
>I would even prefer some 32-Bit unsigned integer divisions but these 
>run totaly out of my available timing (KEIL needs ~3.9us for that).
>
>Does anybody know about specialised unsigned integer division 
>functions, e.g. 24bit/16bit or 16bit/8bit?
>
>Unfortunately i'm not familiar with the ARM assembler code. So if 
>anyone can provide code then it would be helpful if it can be simply 
>implemented with the KEIL compiler.
>
>  
>
At some point in time, the rubber has to meet the road...  Assembler is 
about as fast as you get, division + multiplication is a series of 
iterative shifting + adding / substracts.   Various algorithms have been 
devised over the years to produce fast General Purpose multiply & divide 
routines.

The key is "general purposed". If you wish to ONLY multiply or divide by 
a FIXED CONSTANT, then you can futher optimize performance.  BUT, you 
have to write your own assembly language routine(s).  To do so, first 
you have to understand how such operations work in the first place.

In example.  You know that by shifting left one bit you can multiply by 
a power of two?  Ok then, to build a routine that only multiplies by 10:

unsigned multiplyByTen (unsigned foo)
{
    return (foo << 1) + (foo << 3);
}

Division is a wee bit more involved, as there is a remainder (modulus).  
_Good_ books on assembly language would outline these types of operations...

That being said, you now know what a Floating Point Unit is good for: 
hardware acceleration of math calculations...

Regards

TomW



-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.