comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Portable memory barrier?
Date: Mon, 15 May 2017 17:45:33 -0500
Date: 2017-05-15T17:45:33-05:00	[thread overview]
Message-ID: <ofdb2d$jan$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: fcf4a91a-bfdf-44ee-a888-7bb9a1c52b48@googlegroups.com

"Robert Eachus" <rieachus@comcast.net> wrote in message 
news:fcf4a91a-bfdf-44ee-a888-7bb9a1c52b48@googlegroups.com...
On Wednesday, May 10, 2017 at 9:02:22 PM UTC-4, Randy Brukardt wrote:

>> Write_Index needs to be atomic in order for the OP's algorithm to work.
>> Atomic objects fall under C.6(20/5) -- all reads and updates are included 
>> in
>> the external effect of the program. Optimizing them out (in any way) is
>> wrong (excepting of course a true as-if optimization, but that doesn't 
>> make
>> any sense in this case). In particular, saving the value in a register is
>> useless, because you still have to read the object again at the next
>> reference.

>Even if there is no intervening read or write of anything?

Yes.

>It seems to me that must be an "as if," since there is no way to prove 
>otherwise.
>You may be thinking of reads of memory external to the CPU, part of some
>other hardware, where the other hardware can intervene.

I'm not "thinking" that, the language defines it that way (it's part of the 
external effect of the program, C.6(20) and 1.1.3(8-14)). I don't know how a 
compiler could possibly know if someone has a way to see the external 
effects (some CPU monitor, active memory, etc.), so one has to assume that 
they CAN tell. And in any case, the intent of the language designers is 
crystal-clear -- ignore that at your peril.

...
>Hmm. You need to read the (x86 and most other) rules for prefetching memory 
>locations.
>As I stated earlier in this thread, any CPU core is allowed to do a 
>prefetch of any location,
>as long as it does not cause an action like an interrupt.  This is 
>necessary, or you wouldn't
>be able to have any Atomic accesses. The CPU reads an entire cache line, 
>usually 64, 128,
>or 256 bytes into the cache, but even the widest of CPU writes are only 64 
>bytes wide, and
>those are multiple floating-point values.

I have the compiler generate the "correct" code and don't worry much about 
what the CPU does to it. (That's one reason I was completely in favor of 
removing the bogus requirement to read/write all the way to memory -- it 
doesn't make sense on CPUs that do caching.) That's out of my hands in any 
case as a software guy. (Refer to my response to Jere.) There's a 
requirement to prevent CPU reordering, but nothing else.

But I wouldn't be implementing the language if I started ignoring the 
requirements on the compiler by leaning on an as-if optimization, especially 
one that can be detected with active hardware. Especially as if I did so, 
there would be no possibility of ever writing portable synchonization 
code...

                                Randy.





  reply	other threads:[~2017-05-15 22:45 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06  2:23 Portable memory barrier? Jere
2017-05-06  8:47 ` Jeffrey R. Carter
2017-05-06 14:17   ` Jere
2017-05-06 19:08     ` Dennis Lee Bieber
2017-05-06 19:26     ` Jeffrey R. Carter
2017-05-06 19:41     ` Jeffrey R. Carter
2017-05-06 20:42       ` Niklas Holsti
2017-05-09 19:49     ` Randy Brukardt
2017-05-09 22:07       ` Jere
2017-05-11  1:14         ` Randy Brukardt
2017-05-10 18:28       ` Shark8
2017-05-11  1:17         ` Randy Brukardt
2017-05-11 16:23           ` Jeffrey R. Carter
2017-05-07 20:18 ` Robert Eachus
2017-05-08  7:45   ` Dmitry A. Kazakov
2017-05-08 15:56     ` Robert Eachus
2017-05-08 16:22       ` Dmitry A. Kazakov
2017-05-08 18:39         ` Robert Eachus
2017-05-08 19:18         ` Robert Eachus
2017-05-08 21:09           ` Dmitry A. Kazakov
2017-05-08 23:24             ` Robert Eachus
2017-05-09  0:30               ` Jere
2017-05-09  4:02                 ` Robert Eachus
2017-05-09  4:32                 ` Robert Eachus
2017-05-09  4:44                   ` Robert Eachus
2017-05-09 22:26                   ` Jere
2017-05-09 20:01                 ` Randy Brukardt
2017-05-09 19:57               ` Randy Brukardt
2017-05-10  0:51                 ` Jere
2017-05-10  5:25                   ` J-P. Rosen
2017-05-10 22:56                     ` Jere
2017-05-11  7:36                       ` Dmitry A. Kazakov
2017-05-13 20:25                         ` Jere
2017-05-10  7:13                   ` Dmitry A. Kazakov
2017-05-10 16:45                     ` Robert Eachus
2017-05-10 17:28                       ` Simon Wright
2017-05-10 23:21                     ` Jere
2017-05-11  0:47                       ` Randy Brukardt
2017-05-13 20:11                         ` Jere
2017-05-15 22:33                           ` Randy Brukardt
2017-05-10 23:30                     ` Jere
2017-05-11  0:38                     ` Randy Brukardt
2017-05-10 16:38                   ` Jeffrey R. Carter
2017-05-10 23:40                     ` Jere
2017-05-10 16:19                 ` Robert Eachus
2017-05-11  1:02                   ` Randy Brukardt
2017-05-11  1:51                     ` Robert Eachus
2017-05-15 22:45                       ` Randy Brukardt [this message]
2017-05-08 20:29         ` Niklas Holsti
2017-05-08 21:09           ` Dmitry A. Kazakov
2017-05-09  4:34             ` Niklas Holsti
2017-05-09  6:16               ` Niklas Holsti
2017-05-09  8:34                 ` Dmitry A. Kazakov
2017-05-09 20:18                 ` Randy Brukardt
2017-05-09 20:10           ` Randy Brukardt
2017-05-09  0:05         ` Jere
2017-05-09  8:26           ` Dmitry A. Kazakov
2017-05-09 19:53         ` Randy Brukardt
2017-05-09 20:27           ` Dmitry A. Kazakov
2017-05-11  0:35             ` Randy Brukardt
2017-05-11  8:24               ` Dmitry A. Kazakov
2017-05-15 22:53                 ` Randy Brukardt
2017-05-18 17:44                   ` Dmitry A. Kazakov
2017-05-18 21:01                     ` Randy Brukardt
2017-05-19  7:54                       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox