[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] multiplication order effects machine cycles?
From: |
Galen Seitz |
Subject: |
Re: [avr-gcc-list] multiplication order effects machine cycles? |
Date: |
Thu, 13 Oct 2005 10:36:05 -0700 |
intiha Ho gai <address@hidden> wrote:
> Hello everyone,
> In one of the programs that I am trying to optimize there is a long
> multiplication (I am using Atmega128L). Using GPIO toggling across the lines
> of code I get the following result
>
>
> double skew_;
> int32_t offset_;//can also be negative
> uint32_t full;
>
> //assume full to be initialize dto something
> GPIO(on)//my own MACRO
> full = (uint32_t)(skew_*(double)full + offset_); //this gives me 348usec on
> the scope
> GPIO(off)
>
> REPLACEMENT CODE FOR ABOVE LINE
> GPIO(on)
> full+=offset_;
> full =(uint32_t) skew_ *(double)full; //AFFAN: by observing the scope
> results, for some reason this results in less time spent (180 us as opposed
> to 348 usec above)
> GPIO(off)
>
> Can anyone explain why this significantly large change has happened. I know
> I cna lok at the disassembly, but is there any intuitive reason/principal
> that I can lear from this about how to code multiplication.
In your first example the offset_ add is a floating point add. In the
second example the offset_ add is a 32 bit integer add. Floating point
adds are sometimes slow due to normalization(lots of shifting).
galen