public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew MacLeod <amacleod@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
	       Aldy Hernandez <aldyh@redhat.com>,
	Richard Henderson <rth@redhat.com>,
	       gcc-patches <gcc-patches@gcc.gnu.org>,
	       Benjamin De Kosnik <bkoz@redhat.com>
Subject: Re: __sync_swap* with acq/rel/full memory barrier semantics
Date: Tue, 31 May 2011 15:23:00 -0000	[thread overview]
Message-ID: <4DE4E90A.8080707@redhat.com> (raw)
In-Reply-To: <20110531103822.GP17079@tyan-ft48-01.lab.bos.redhat.com>

On 05/31/2011 06:38 AM, Jakub Jelinek wrote:
>
>> Aldy was just too excited about working on memory model I think :-)
>>
>> I've been looking at this, and I propose we go this way :
>>
>> http://gcc.gnu.org/wiki/Atomic/GCCMM/CodeGen
>>
>> Please feel free to criticize, comment on,  or ask for
>> clarification.  I usually miss something I meant to get across.
> I think the addition of new __sync_* builtins for the different models
> is preferrable and would be generally more usable even for other users than
> C++ atomics. On some targets any atomic insn will act as a full barrier,
> while on others it could generate different insns or code sequences that
> way.  For OpenMP atomics having a none (in addition to full/acq/rel)
> would be useful, I think #pragma omp atomic doesn't impose any ordering
> on memory accesses other than the memory being atomically
> read/written/changed.  Haven't read the C++0x standard in detail why
> it has 6 memory order modes instead of just 4, but if really 6 are needed
> (even for 4 probably), having new builtins with just one constant extra
> argument which says the memory ordering mode would be best.
>
>
I'm not sure if you are agreeing or not, or how much :-)

There is still only the basics of relaxed, consume, release/acquire, and 
seq-cst.  so there are 4 modes.  C++ gives you two more  by separating 
release and acquire for loads and stores, loads using 'acquire' mode, 
stores using 'release'.  I guess It allows for a slightly finer control 
over instructions that can be loads and/or stores. It looks like the 
optimal powerpc sequence for cmpxchg is slightly more efficient when its 
just an acquire or just a release rather than an acquire/release for 
instance. (and all 3 sequences are slightly different)

The table is more or less complete... ie,  a store cant have an 
'acquire' mode...  and I presume that a consumer which doesn't break 
release-acquire down into component parts would use that 'release' 
version of the store as 'release/acquire' mode.

I presume a single builtin with a parameter is the most efficient way to 
build them, but thats just an implementation detail. Presumable you have 
each builtin in the table with each of those possible modes as a valid 
parameter.   The one thing I would care about is i would like to see the 
relaxed version be 'just an insn' rather than a builtin, if thats 
possible... My understanding is that relaxed (as far as C++) has no 
synchronization at all, so therefore you can treat it like a normal 
operation as far as optimization. That seems the same for openMP.  Its 
just thats its atomic operation.  So it would be preferable if we can 
avoid a builtin in the optimizers for that. Thats why I left it out of 
the table.  If all the atomic operations are already builtins, well, 
then I guess it doesn't matter :-P

It would be nice to say something like   emit_atomic_fetch_add 
(memory_order)  and if its  relaxed, emit the atomic fetch_add insn (or 
builtin if thats what it is), and if its something else, emit the 
appropriate builtin.  That would make bits/libstdc++v2/atomic_2.h even 
easier too

I think maybe we are more or less saying the same thing? :-)

Andrew





  reply	other threads:[~2011-05-31 13:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24  8:27 Aldy Hernandez
2011-05-24  9:25 ` Joseph S. Myers
2011-05-30 22:53   ` Andrew MacLeod
2011-05-31 13:12     ` Jakub Jelinek
2011-05-31 15:23       ` Andrew MacLeod [this message]
2011-06-02 19:13     ` Aldy Hernandez
2011-06-02 19:25       ` Jakub Jelinek
2011-06-02 19:53         ` Aldy Hernandez
2011-06-03 14:27           ` Richard Henderson
2011-06-17 22:21             ` Andrew MacLeod
2011-06-18 19:49               ` Richard Henderson
2011-06-20 16:39                 ` Andrew MacLeod
2011-06-20 22:50                   ` Richard Henderson
2011-06-20 23:02                     ` Andrew MacLeod
2011-06-20 23:29                       ` Richard Henderson
2011-06-21 18:56                         ` __sync_swap* [ rename sync builtins ] Andrew MacLeod
2011-06-21 19:03                           ` Richard Henderson
2011-06-21 23:03                             ` Graham Stott
2011-06-21 23:26                               ` Andrew MacLeod
2011-06-22  0:59                                 ` Andrew MacLeod
2011-06-24  0:35                                 ` Ian Lance Taylor
2011-06-24  0:38                                   ` Andrew MacLeod
2011-06-21 23:03                         ` [cxx-mem-model] sync_mem_exchange implementation with memory model parameters Andrew MacLeod
2011-06-22 20:36                           ` Richard Henderson
2011-07-08 17:00                   ` __sync_swap* with acq/rel/full memory barrier semantics Aldy Hernandez
2011-06-18 23:49               ` Richard Henderson

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=4DE4E90A.8080707@redhat.com \
    --to=amacleod@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=bkoz@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=joseph@codesourcery.com \
    --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).