[Top][All Lists]

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

Re: [avr-gcc-list] efficiency of assigning bits

From: E. Weddington
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Mon, 14 Mar 2005 13:14:46 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Erik Walthinsen wrote:

E. Weddington wrote:
> If you don't care, then you're

free to have them as two statements, but it would also be inefficient in terms of code space. Your choice.

Actually, it's more efficient to code it as two separate statements, *if* the register is one of the first 32 in the chip's register space. Two statements will result in 2 sbi or cbi instructions, while a single statement will result in a read-modify-write sequence of 3 instructions.

Oh, sure! *Very* good point.

If the register is outside that range, then yes, it is more efficient to do it as a single statement, because sbi/cbi don't work and you're back to a read-modify-write sequence for each of the two statements, resulting in 6 instructions.

I went around on this several times while trying to shave one instruction at a time on a project that's filled the 1024-byte code space (512 instructions) of an ATtiny15 to 99+%. Waiting for ATtiny45 samples......

And for everyone else: this is why it pays to understand what your compiler is doing; take a look at the resulting assembly of your C code and never assume anything.


reply via email to

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