Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #1841

Re: forcing the compiler to reload from memory with c++0x

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!postnews.google.com!o7g2000prn.googlegroups.com!not-for-mail
From Joshua Maurice <joshuamaurice@gmail.com>
Newsgroups comp.programming.threads
Subject Re: forcing the compiler to reload from memory with c++0x
Date Tue, 1 Feb 2011 15:19:48 -0800 (PST)
Organization http://groups.google.com
Lines 64
Message-ID <1fff7f23-005c-4f0a-9a28-1566bd1da544@o7g2000prn.googlegroups.com> (permalink)
References <4d3cee42$0$1209$426a74cc@news.free.fr> <1d21ad0a-db55-460e-aeb6-66f6d19369ea@i13g2000yqe.googlegroups.com> <4d3e2e3f$0$21517$426a34cc@news.free.fr> <4D40A4C7.16E6F9AE@web.de> <69d82db7-34be-4de7-86c4-2f39cc1e6df3@m13g2000yqb.googlegroups.com> <4d4221e9$0$17247$426a74cc@news.free.fr> <947b33d5-2509-4f0c-9256-a7c3de35578e@24g2000yqa.googlegroups.com> <87mxmlxxry.fsf@justsoftwaresolutions.co.uk> <ihv8t6$bmr$1@news.eternal-september.org> <87oc6yxdcw.fsf@justsoftwaresolutions.co.uk> <ii745u$5q3$1@news.eternal-september.org> <87sjw8w4b5.fsf@justsoftwaresolutions.co.uk> <4D480800.1C5132D7@web.de> <87k4hjx3ph.fsf@justsoftwaresolutions.co.uk> <4D482797.CBE41A86@web.de>
NNTP-Posting-Host 12.108.188.134
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1296602389 3102 127.0.0.1 (1 Feb 2011 23:19:49 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 1 Feb 2011 23:19:49 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info o7g2000prn.googlegroups.com; posting-host=12.108.188.134; posting-account=C7XBLgoAAAAxMpmeFo8Iv_pud1pyFhjy
User-Agent G2/1.0
X-HTTP-UserAgent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe)
Xref csiph.com comp.programming.threads:1841

Show key headers only | View raw


On Feb 1, 7:32 am, Alexander Terekhov <terek...@web.de> wrote:
> Anthony Williams wrote:
> > The C++ Standard defines "observable behaviour" to be the set of
> > accesses to volatile variables and I/O performed by the program.
>
> > The only requirement on a compiled program is that it produce the same
> > set of observable behaviour as that required by the abstract machine,
> > which includes accesses to volatile variables.
>
> > How you are supposed to observe the accesses to volatile variables is
> > not specified.
>
> Yet you call it observable? <chuckles>

I'm pretty sure the C and C++ standards are phrased such that a
conforming implementation could compile the code to whatever target
language entirely ignoring the volatile keyword. Yes volatile reads
and writes are observable behavior, but what "observable behavior"
means is entirely platform specific.

One of volatile's major purposes is a hook to provide MMIO, which is
inherently platform specific. Talking about volatile MMIO and memory
reads and writes observable behavior in terms of the C or C++ standard
is silly. You need to look at the platform specs at that point.

> > > int main() {
> > >   volatile int i;
> > >   // volatile write = has no observable effect
> > >   i = 1;
> > >   // volatile read = has no observable effect
> > >   int n = i;
> > >   // output: 1
> > >   std::cout << n;
> > > }
>
> > > int main() {
> > >   // output: 1
> > >   std::cout << 1;
> > > }
>
> > > can be translated into the same executable code.
>
> > FYI, gcc doesn't treat them the same, even with -O3: the first gets
> > translated to a store of 1 to a stack variable followed by a load from
> > that stack variable into a register, then a call to write that to
> > cout. The second just gets translated into a load of 1 into a register,
> > then a call to write that to cout. If you omit the "volatile" from the
> > first example then it is translated the same as the second.
>
> The gcc' utter stupidity doesn't prove anything.

I don't think that this is utterly stupid.

First, as mentioned above, it's was intended in part to be a hook for
platform specific MMIO operations. Perhaps the way gcc compiles it
down is required for MMIO on that platform. (From my knowledge -
unlikely. James Kanze has mentioned that volatile alone is not
sufficient for MMIO on a large number of desktop and server
platforms.)

Second, volatile still has purposes besides MMIO operations. It's
other two original purposes is communication with signal handlers and
communication across setjump longjump nonsense. What gcc does with
volatile could be explained in terms of that as well.

Back to comp.programming.threads | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: forcing the compiler to reload from memory with c++0x Alexander Terekhov <terekhov@web.de> - 2011-02-01 14:17 +0100
  Re: forcing the compiler to reload from memory with c++0x Alexander Terekhov <terekhov@web.de> - 2011-02-02 14:45 +0100
    Re: forcing the compiler to reload from memory with c++0x Dmitriy Vyukov <dvyukov@gmail.com> - 2011-02-02 07:02 -0800
      Re: forcing the compiler to reload from memory with c++0x Alexander Terekhov <terekhov@web.de> - 2011-02-02 16:33 +0100
  Re: forcing the compiler to reload from memory with c++0x Alexander Terekhov <terekhov@web.de> - 2011-02-01 16:32 +0100
    Re: forcing the compiler to reload from memory with c++0x Alexander Terekhov <terekhov@web.de> - 2011-02-02 12:13 +0100
      Re: forcing the compiler to reload from memory with c++0x Dmitriy Vyukov <dvyukov@gmail.com> - 2011-02-02 04:54 -0800
    Re: forcing the compiler to reload from memory with c++0x Dmitriy Vyukov <dvyukov@gmail.com> - 2011-02-01 21:02 -0800
    Re: forcing the compiler to reload from memory with c++0x Joshua Maurice <joshuamaurice@gmail.com> - 2011-02-01 15:19 -0800
  Re: forcing the compiler to reload from memory with c++0x Anthony Williams <anthony.ajw@gmail.com> - 2011-02-01 13:51 +0000

csiph-web