[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] efficiency of assigning bits
From: |
Jesper Hansen |
Subject: |
Re: [avr-gcc-list] efficiency of assigning bits |
Date: |
Mon, 14 Mar 2005 21:20:13 +0100 |
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.
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......
An often overlooked solution, especially with ports that changes in
a determined way, is to read the contents of the port at an early stage,
then use that as a base for manipulation.
register uint8_t pval = PORTA;
-
-
PORTA = pval | 0x23;
-
PORTA = pval;
e.t.c., you get the idea
This will result in one or two cycle (and instuction) sequnces.
Can save quite a few bytes in the right code.
/Jesper
- [avr-gcc-list] efficiency of assigning bits, Jamie Morken, 2005/03/13
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, David Willmore, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, Erik Walthinsen, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits,
Jesper Hansen <=
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, Erik Walthinsen, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits (OT), Hugo González Monteverde, 2005/03/15
- Re: [avr-gcc-list] efficiency of assigning bits, Dave Hansen, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, Christof Krueger, 2005/03/14
Fwd: Re: [avr-gcc-list] efficiency of assigning bits, Royce & Sharal Pereira, 2005/03/14