On 2012-01-07, Peter Bigot <big...@acm.org> wrote:
> On Sat, Jan 7, 2012 at 10:28 AM, Grant Edwards
><grant.b.edwa...@gmail.com> wrote:

>> However the "test code" might be non-volatile, and as such GCC is
>> still free to move it outside the set/clear pair (AFAICT).

[...]

>> Anyhow.... I can't find anywhere in GCC docs that say non-volatile
>> accesses can't be moved across sequence points or volatile accesses.
>> If sequence points and volatile accesses only constrain ordering of
>> accesses to volatile objects, and what you're timing doesn't involve
>> volatile objects, then adding sequence points doesn't matter.
>>
>> However, adding a memory barrier ought to do the trick. ?I think.
>
> Yes, today I think you're right.

I've always been a bit fuzzy on this stuff, so don't bet the farm on
my opinions.  It seems to be a common belief in embedded programmers
that compilers aren't allowed to (and won't) move anything past a
volatile access, but I've never been able to find any convincing basis
for that belief.

> In fact, that's what I thought back in early December when I added
> cycle timing to test430 and found a situation where the compiler
> helpfully moved the test code out from between the start/stop counter
> reads.  I did something that stopped that from happening, though I
> don't remember what; it wasn't a memory barrier.
>
> Later in December, the topic arose again in the context of the thread
> at http://gcc.gnu.org/ml/gcc/2011-12/msg00008.html, during which
> discussion I became convinced any such move was a compiler error,
> apparently because I mis-read Richard Guenther's response in
> http://gcc.gnu.org/ml/gcc/2011-12/msg00026.html.  The discussion
> there ultimately revealed an underlying gcc bug that will eventually
> be fixed in a 4.7.x release, so confusion about the issue is common
> even among those who are expected to know better.

I don't have a complete copy of the C standard, but some of the
excerpts I have read certainly didn't make anything any clearer in my
mind. I think reading standards like that is a skillset that takes a
lot more work/practice than I've put in.

>> Pointers to GCC docs actually stating what to expect would be
>> most welcome...
>
> The current version of what you cited
> (http://gcc.gnu.org/onlinedocs/gcc/Volatiles.html) is the best I know
> of,

That is clearer than the older versions.

Now, if only I wasn't perpetually confused over what's a sequence
point and what isn't...

[I know it's well defined, but that doesn't mean I can remember it
correctly.]

-- 
Grant Edwards               grant.b.edwards        Yow! I'm thinking about
                                  at               DIGITAL READ-OUT systems
                              gmail.com            and computer-generated
                                                   IMAGE FORMATIONS ...


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to