public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeffrey Yasskin <jyasskin@google.com>
To: Andrew MacLeod <amacleod@redhat.com>
Cc: Lawrence Crowl <crowl@google.com>,
	Benjamin Kosnik <bkoz@redhat.com>,
	       Richard Henderson <rth@redhat.com>,
	Aldy Hernandez <aldyh@redhat.com>,        GCC <gcc@gcc.gnu.org>
Subject: Re: C++11 atomic library notes
Date: Wed, 05 Oct 2011 19:07:00 -0000	[thread overview]
Message-ID: <CANh-dXnzJcs_LmtWc1jmM8jo0JDhxzax4gm+8_iGAkne-gb0Jw@mail.gmail.com> (raw)
In-Reply-To: <4E8C5253.5040105@redhat.com>

On Wed, Oct 5, 2011 at 5:49 AM, Andrew MacLeod <amacleod@redhat.com> wrote:
> On 10/05/2011 12:14 AM, Jeffrey Yasskin wrote:
>> I see two ways out:
>> 1) Say that accessing a non-volatile atomic through a volatile
>> reference or pointer causes undefined behavior. The standard doesn't
>> say that, and the casts are implicit, so this is icky.
>> 2) Say that volatile atomic accesses may be implemented with more than
>> one instruction-level access.
>>
>> (2) is something like how volatile reads of 128-bit structs involve
>> multiple mov instructions that execute in an arbitrary order. It's
>> also unlikely to cause problems in existing programs because nobody's
>> using volatile atomics yet, and they'll only start using them in ways
>> that work with what compilers implement.
>
> To clarify, you are suggesting that we say atomic accesses to volatile
> objects may involve more than a single load?
>
> Can we also state that a 'harmless' store may also happen? (ie, a 0 to an
> existing 0, or some other arbitrary value)   Otherwise I don't know how to
> get a 128 bit atomic load on x86-64 :-P  which then means no inlined
> lock-free atomics on 16 byte values.
> Its unpleasant, but...  other suggestions?

Yes, that's what I'm suggesting. The rule for 'volatile' from the
language is just that "Accesses to volatile objects are evaluated
strictly according to the rules of the abstract machine." If the
instruction-level implementation for a 16-byte atomic load is
cmpxchg16b, then that's just how the abstract machine is implemented,
and the rule says you have to do that consistently for volatile
objects rather than sometimes optimizing it away. That's my argument
anyway. If there's another standard you're following beyond "kernel
people tend to ask for it," the situation may be trickier.

Jeffrey

P.S. On x86, cmpxchg's description says, "To simplify the interface to
the processor’s bus, the destination operand receives a write cycle
without regard to the result of the comparison. The destination
operand is written back if the comparison fails; otherwise, the source
operand is written into the destination. (The processor never produces
a locked read without also producing a locked write.)", so 128-bit
atomic loads will always write the original value back.

  reply	other threads:[~2011-10-05 14:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4E862864.2010607@redhat.com>
2011-10-01  6:56 ` Marc Glisse
2011-10-01 23:12   ` Andrew MacLeod
2011-10-02  8:40     ` Marc Glisse
2011-10-02 13:56       ` Andrew MacLeod
2011-10-03 17:31 ` Richard Henderson
2011-10-03 17:54   ` Andrew MacLeod
2011-10-03 18:10     ` Richard Henderson
2011-10-03 19:52     ` Joseph S. Myers
2011-10-05  7:26 ` Jeffrey Yasskin
2011-10-05 18:58   ` Andrew MacLeod
2011-10-05 19:07     ` Jeffrey Yasskin [this message]
2011-10-05 20:12       ` Andrew MacLeod

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANh-dXnzJcs_LmtWc1jmM8jo0JDhxzax4gm+8_iGAkne-gb0Jw@mail.gmail.com \
    --to=jyasskin@google.com \
    --cc=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=bkoz@redhat.com \
    --cc=crowl@google.com \
    --cc=gcc@gcc.gnu.org \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).