Yahoo Groups archive

Lpc2000

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

Message

Re: Faster integer division with KEIL

2005-12-16 by uedogan

Hi,
thanks for the tip of this book!

Unfortunately i just have "normal" numbers in binary format. By the 
way, this are three sensor values which together form a color value. 
Some people gave comments like "try it without division" but i need 
chromaticity. Try to do this without division......

On an LPC2136 with ~58MHz i just have 15us time to sample the three 
16-bit values, check them for over/underflow, limit them, build 
chromaticity and check them against valid ranges. I also have to 
consider a lot of times hich also must be measured. Then set an 
output (if signals are in their ranges) and maybe do "a little" 
communications. Then the next cycle starts. The first goal in this 
project was even to reach a cycle time of 10us! But that is 
impossible or i start writing assembler routines (which i may do with 
the beginning of next year). Now i stay at 19us but not everything is 
done.....

I just need quick "generic" 16-bit (32-bit would be even better 
if "fast enough") unsigned divide routines. Code memory is no 
problem, theres enough. I wonder if it is not possible to use tables. 
Such a table can hold e.g. all possible results of 4-bit divisions 
and the 16-bit division is divided in "actions by 4". But i can not 
find such an algorithm. How do processors like an 8051 or a C166 
divide larger numbers? They have a hardware divider? Does anyone know 
how to divide in such "fractions"?

Ünal


--- In lpc2000@yahoogroups.com, "scsibob" <bobd@a...> wrote:
>
> The book "ARM System Developer's Guide" by Sloss, Symes, Wright has 
> some really cool, mind-blowing algorithms for divides (and other 
> arithmetic functions).  If I understood it correctly, in one 
section 
> it indicates that you can achieve a 16-bit fixed point divide with 
a 
> single 32-bit multiply (using the magic of modulus arithmetic).
> 
> See the discussions on division which start on page 140 (in the 
> edition/printing of the book that I have) and also the section 
> starting on page 216.
> 
> Somebody else already asked the question whether you are always 
> dividing by the same number (I'm not sure if you have answered that 
> yet).  If you always use the same divisor (or some small number of 
> known-in-advance divisors), there may be all sorts of opportunities 
> for optimizing the code.  If you need a generic divide routine that 
> accepts any values, that's another story... (see the book for that)
> 
> scsibob
> 
> 
> --- In lpc2000@yahoogroups.com, "uedogan" <uedogan@g...> 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.
> > 
> > Thanks a lot,
> > Uenal
> >
>

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.