This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help with SH2E -O2 instruction ordering with volatile


On Sun, 2015-12-20 at 21:52 +1100, Alex Brown wrote:
> Hi,
> 
> Thanks for that.
> 
> I was trying to avoid using a memory barrier (ever time I write non
> portable code, I shed a small tear),

Well, change the #define memory_barrier to whatever your toolchain
supports and make it portable in the build setup :)

You can also make all the stores that need to be strictly ordered store
to volatile mems (like you did in one of your working examples). 
 However, using volatile alone is sometimes not enough when doing
hardware access/communication, because the compiler doesn't know about
the side effects of memory mapped IO.

>  but I am guessing that because I
> only access the address of the text variable, rather than the value,
> GCC can't know that it needs to fill in the values before the
> assignment ?

Yes, it only treats that volatile store as volatile.  Whether the
stored value is an address or not doesn't matter at that point.

Cheers,
Oleg


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]