http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #2 from brag <unixoid2003 at mail dot ru> 2012-04-23 13:19:03 UTC
---
The simpler example:
struct aa{
volatile unsigned short a;
};
struct aa AAmem;
void f(){
AAmem.a=0xff;
AAmem.a=0xff;
}
00000000 <_Z1fv>:
0: f240 0300 movw r3, #0
4: f2c0 0300 movt r3, #0
8: 22ff movs r2, #255 ; 0xff
a: 801a strh r2, [r3, #0] ; <<--- one write here
c: 4770 bx lr
e: bf00 nop
There is one write but should be two.
Reads seems to work good:
struct aa{
volatile unsigned short a;
};
#define AAmem ((struct aa *) 256)
void f(){
int t;
t=AAmem->a;
t=AAmem->a;
}
00000000 <_Z1fv>:
0: f44f 7380 mov.w r3, #256 ; 0x100
4: 881a ldrh r2, [r3, #0] ;<<---| two reads here
6: 881b ldrh r3, [r3, #0] ;<<---|
8: 4770 bx lr
a: bf00 nop
Simple volatile variable seems to work OK:
#define s (*((volatile unsigned short*)128))
void f(){
s=0xff;
s=0xff;
}
00000000 <_Z1fv>:
0: 2380 movs r3, #128 ; 0x80
2: 22ff movs r2, #255 ; 0xff
4: 801a strh r2, [r3, #0] ;<<---| two writes here
6: 801a strh r2, [r3, #0] ;<<---|
8: 4770 bx lr
a: bf00 nop