Gre7g Luterman wrote:
[...]
Well if size & speed are getting you down, try this:

http://pastie.textmate.org/127218

The calculation takes 22 bytes and executes in 40
clocks.  As an assembly-language programmer, having
that extra MOV in the beginning annoys me, but hey, I
try not to break the asm rules.

Regardless, you'd be hard-pressed to get it much
smaller or faster.

Actually, getting it faster (and possibly smaller) shouldn't be that hard for a _constant_ division like that in a AVR that supports mul instructions.

To do:

a = c/10;
b = c%10;

you can do:

a = (c * 65534) >> 16;
b = c - (a * 10);

leaving you with no divisions to perform.

The main problem is that the first multiplication should be done with some hand optimized assembly to perform a 8x16 bit multiplication, leaving just the upper 8 bits of a 24 bit result, but it should be doable with just 2 mul instructions and one 16 bit addition.

--
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

"The impossible often has a kind of integrity to it which the merely
 improbable lacks."
Douglas Adams


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to