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: David Willmore
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Mon, 14 Mar 2005 14:23:59 -0500

> >PORTD = (PORTD & ~PD1) & ~PD4;
> >
> >or:
> >
> >cbi(PORTD, PD1); 
> >cbi(PORTD, PD4);
> >I am assuming these are equivalent.
> 
> Not quite. Do this:
> 
> PORTD &= ~(_BV(PD1) | _BV(PD4));
> 
> That will clear the two bits at the same time.

Hello, all.  I'm a bit confused by many of the comments in this
thread.  Where is there a guarentee that the two bits will be
set at the same time in any of the shown examples?

If I understand correctly, any of:

PORTD &= ~_BV(PD1);
PORTD &= ~_BV(PD4);

or

PORTD &= ~(_BV(PD1) | _BV(PD4));

or other variants are completely the same in what kind of code
they may generate when it gets down to machine language, no?

There is no implied simultinaity in any of these statements--
all C offers you is that the user code won't be able to tell
the difference--unless PORTD is defined as a volatile.  Which
may be the default and would explain my confusion.

Is that the critical bit that I'm missing?

Cheers,
David




reply via email to

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