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

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

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


From: Jeff Epler
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Sun, 13 Mar 2005 09:58:40 -0600
User-agent: Mutt/1.4.2i

On Sun, Mar 13, 2005 at 07:12:25AM -0800, Parthasaradhi Nayani wrote:
> To turn two bits off, the method I would adopt is
> 
>   PORTD &= 0B11101101;
> 
> This is the fastest method.

Wouldn't it be a better idea to write code that compiles with avr-gcc?
    $ avr-gcc -mmcu=at90s2313 /tmp/nayani.c 
    /tmp/nayani.c:4:14: invalid suffix "B11101101" on integer constant

Jamie Morken <address@hidden> wrote:
> > I am trying to turn two bits off on a port as
> > quickly as possible, how do these two methods
> > compare:

The first method compiles to 3 instructions (in, andi, out),
and the second method compiles to 2 instructions (cbi, cbi).
(In general, the first method always takes 3 instructions to turn off N
different bits, while the second method takes one instruction per bit
turned off).

The first method changes the two bits at the same time (the execution of
the 'out' instruction), while the second method changes one bit at each
cbi instruction.  The cbi() method is not always appropriate, depending
on the details of the hardware you're interfaced to.

Furthermore, I believe the cbi() macro has been removed from the latest
version of avr-gcc.  Check the archives if you want to see more
discussion about that.

Jeff

Attachment: pgp1w9cMpi5Gq.pgp
Description: PGP signature


reply via email to

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