This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Help with SH2E -O2 instruction ordering with volatile
- From: Oleg Endo <oleg dot endo at t-online dot de>
- To: Alex Brown <alex dot g dot brown at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 20 Dec 2015 19:59:16 +0900
- Subject: Re: Help with SH2E -O2 instruction ordering with volatile
- Authentication-results: sourceware.org; auth=none
- References: <CAB-RZVTLmhdvvqXDHxBc_qAz2Nnm7mRrwHJU6Df8S4HOxxqaaw at mail dot gmail dot com> <1450592312 dot 2951 dot 15 dot camel at t-online dot de> <CAB-RZVT7Fc9s2nUjU8kharvqPKyFXR5P2=G8Uy3hU=Pw3DFbdQ at mail dot gmail dot com> <1450596525 dot 2951 dot 27 dot camel at t-online dot de> <CAB-RZVTT0ysT9g4OC95duD3LN3JeY5HztB_ZakWV+sFmDfv8Bw at mail dot gmail dot com>
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