This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: __sync_swap* with acq/rel/full memory barrier semantics
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Aldy Hernandez <aldyh at redhat dot com>
- Cc: Andrew MacLeod <amacleod at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>, Richard Henderson <rth at redhat dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 2 Jun 2011 21:25:14 +0200
- Subject: Re: __sync_swap* with acq/rel/full memory barrier semantics
- References: <4DDAE516.4010307@redhat.com> <Pine.LNX.4.64.1105232300520.28552@digraph.polyomino.org.uk> <4DE3F8ED.6020109@redhat.com> <4DE7E0A6.9070400@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Jun 02, 2011 at 02:12:38PM -0500, Aldy Hernandez wrote:
> +/* This function expands a fine grained atomic exchange operation:
> + atomically store VAL in MEM and return the previous value in MEM.
> +
> + MEMMODEL is the memory model variant to use.
> + TARGET is an option place to stick the return value. */
> +
> +rtx
> +expand_sync_mem_exchange (enum memmodel model, rtx mem, rtx val, rtx target)
> +{
> + enum machine_mode mode = GET_MODE (mem);
> + enum insn_code icode;
> + direct_optab op;
> +
> + switch (model)
> + {
> + case MEMMODEL_RELAXED:
> + /* ?? Eventually we should either just emit the atomic
> + instruction without any barriers (and thus allow movements
> + and transformations), or emit a relaxed builtin.
> +
> + It is still not clear whether any transformations are
> + permissible on the atomics (for example, CSE might break
> + coherence), so we might need to emit a relaxed builtin.
> +
> + Until we figure this out, be conservative and fall
> + through. */
> + case MEMMODEL_SEQ_CST:
> + op = sync_mem_exchange_seq_cst_optab;
> + break;
> + case MEMMODEL_ACQUIRE:
> + op = sync_mem_exchange_acq_optab;
> + break;
> + case MEMMODEL_RELEASE:
> + op = sync_mem_exchange_rel_optab;
> + break;
> + case MEMMODEL_ACQ_REL:
> + op = sync_mem_exchange_acq_rel_optab;
> + break;
Wouldn't it be better to pass the model (as an extra CONST_INT
operand) to the expanders? Targets where atomic instructions always act
as full barriers could just ignore that argument, other could decide what
to do based on the value.
Jakub