On 12/14/2015 05:53 PM, Martin Sebor wrote:
The C atomic_init macro is implemented in terms of simple assignment
to the atomic variable pointed to by its first argument.  That's
inefficient since the variable under initialization must not be
accessed by other threads and assignment provides sequentially
consistent semantics.  The inefficiency is apparent in the generated
dumps (e.g. the gimple dump contains calls to __atomic_store (...,
memory_order_seq_cst), and the assembly dump contains the fence
instruction).

The attached patch changes the macro to use atomic_store with relaxed
consistency semantics and adds a test verifying that invocations of
the atomic_init macro emit __atomic_store_N with a zero last argument
(memory_order_relaxed).

This brings GCC on par with Clang.

Tested on powerpc64le and x86_64.

Martin

gcc-68868.patch


gcc/ChangeLog
2015-12-14  Martin Sebor<mse...@redhat.com>

        PR c/68868
        * ginclude/stdatomic.h (atomic_init): Use atomic_store instead
        of plain assignment.

gcc/testsuite/ChangeLog
2015-12-14  Martin Sebor<mse...@redhat.com>

        PR c/68868
        * testsuite/gcc.dg/atomic/stdatomic-init.c: New test.
OK.
jeff

Reply via email to