...and, just to say, this is also in the book "Hacker's Delight" (of which I have a copy). There is a slightly different version of this code in Hacker's Delight. It's quite a nice book for bit-twiddlers, but many of the examples in it expect that multiplication and shifting can be done very quickly, and it's not always true that that happens on some microprocessors. The ARM is, of course, lucky to be able to shift quickly. The code for the book is here: http://www.hackersdelight.org/HDcode.htm Take a look at "Figs. 10-2 and 10-3. Computing the magic number for unsigned division." Or just browse around, it's interesting. -- Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors > -----Original Message----- > From: Karl Olsen [mailto:kro@post3.tele.dk] > Sent: 30 November 2004 08:01 > To: lpc2000@yahoogroups.com > Subject: [lpc2000] Re: Slightly OT -- Fast Divide By 10 > > > > --- In lpc2000@yahoogroups.com, "James Dabbs" <jdabbs@t...> wrote: > > > > I'm trying to squeeze a few more cycles out of one my LPC, and I'm > > looking for an optimized way to divide by 10 and leave the quotient > and > > remainder. I.e., a faster way to do this: > > > > #define DIVIDE_BY_10(D, Q, R) Q=D/10; R=D%10; // D is unsigned long > > > Check out "How to optimize for the Pentium family of microprocessors" > http://www.agner.org/assem/pentopt.pdf > > The section "Division (all processors)" has a smart algorithm > for converting division by a constant to a cheaper > multiplication and shift. > > Karl Olsen > > > > > > > ------------------------ Yahoo! Groups Sponsor > --------------------~--> > $9.95 domain names from Yahoo!. Register anything. > http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dN_tlB/TM > -------------------------------------------------------------- > ------~-> > > > Yahoo! Groups Links > > > > > > > > >
Message
RE: [lpc2000] Re: Slightly OT -- Fast Divide By 10
2004-11-30 by Paul Curtis
Attachments
- No local attachments were found for this message.