avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] dev and mod may not be optimized


From: Paulo Marques
Subject: Re: [avr-gcc-list] dev and mod may not be optimized
Date: Wed, 12 Dec 2007 12:39:21 +0000
User-agent: Thunderbird 1.5.0.12 (X11/20070509)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]