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

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

RE: AW: [avr-gcc-list] Gcc bug??


From: Dave Hylands
Subject: RE: AW: [avr-gcc-list] Gcc bug??
Date: Thu, 4 Mar 2004 12:55:23 -0800

Hi Dave,

Hmmm. I think that you're correct. I found an interesting PDF file that
talks about this:
http://h21007.www2.hp.com/dspp/files/unprotected/ddk/memoryaccesses/opt-
mem-access.pdf 

I've experienced cases where the ordering of accesses to volatile
objects was not preserved, and these were probably "compiler bugs", and
using the barrier technique caused the problems to go away.

The compilers I was using were certainly pre C99.

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

> -----Original Message-----
> From: Dave Hansen [mailto:address@hidden 
> Sent: Thursday, March 04, 2004 6:55 AM
> To: Dave Hylands; address@hidden; address@hidden
> Cc: address@hidden
> Subject: RE: AW: [avr-gcc-list] Gcc bug??
> 
> 
> From: "Dave Hylands" <address@hidden>
> [...]
> >While we're talking about volatile, here's an example where volatile 
> >might not help you (I've helped several people with this who had 
> >misconceptions about what volatile does). Let's say I have a 
> peripheral 
> >which has a two register interface, the first register being 
> an index 
> >into an internal register and the second register gets the value.
> >
> >struct hw
> >{
> >     uint8_t reg;
> >     uint8_t val;
> >};
> >
> >struct hw *p;
> >
> >void SetReg( uint8_t inReg, uint8_t inVal )
> >{
> >     p->reg = inReg;
> >     p->val = inVal;
> >}
> >
> >It's possible for the compiler to reorder these to set val first and 
> >then set reg. Declaring p as volatile will NOT change this behaviour.
> 
> But declaring what p points to _should_ work, right?  e.g.
> 
>    struct hw * volatile p;
> 
> makes p volatile, but
> 
>    struct hw volatile * p;
> 
> makes what p points to volatile.
> 
> In any case, I believe you can modify your data structure as 
> follows to make 
> it work without a barrier function:
> 
>    struct hw
>    {
>       uint8_t volatile reg;
>       uint8_t volatile val;
>    };
> 
> Regards,
>    -=Dave
> 
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar - get it now! 
> http://clk.atdmt.com/AVE/go/onm00200415ave/direct/01/
> 
> 
> 


_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

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