|
From: | Dave Hansen |
Subject: | Re: [avr-gcc-list] efficiency of assigning bits |
Date: | Mon, 14 Mar 2005 14:49:11 -0500 |
From: David Willmore <address@hidden> [...]
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?
Yup. --- begin included file --- C:\Dave>type sfr.c #include <avr/io.h> void foo(void) { PORTD &= 0xFC; } C:\Dave>avr-gcc -mmcu=atmega16 -E sfr.c > sfr.out C:\Dave>tail sfr.out# 176 "C:/WinAVR/bin/../lib/gcc/avr/3.4.1/../../../../avr/include/avr/io.h" 2 3 # 241 "C:/WinAVR/bin/../lib/gcc/avr/3.4.1/../../../../avr/include/avr/io.h" 3 # 1 "C:/WinAVR/bin/../lib/gcc/avr/3.4.1/../../../../avr/include/avr/portpins.h"
1 3# 242 "C:/WinAVR/bin/../lib/gcc/avr/3.4.1/../../../../avr/include/avr/io.h" 2 3
# 2 "sfr.c" 2 void foo(void) { (*(volatile uint8_t *)((0x12) + 0x20)) &= 0xFC; } --- end included file --- Note: (volatile uint8_t *) Regards, -=Dave
[Prev in Thread] | Current Thread | [Next in Thread] |