From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 43665 invoked by alias); 9 Apr 2015 09:53:29 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 43255 invoked by uid 48); 9 Apr 2015 09:53:24 -0000 From: "matthew.wahab at arm dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/65697] __atomic memory barriers not strong enough for __sync builtins Date: Thu, 09 Apr 2015 09:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: matthew.wahab at arm dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg00654.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65697 --- Comment #4 from Matthew Wahab --- There is a difference between __syncs and __atomics, assuming the the __atomics are meant to match the C11/C++11 memory model. With C11 atomics, a barrier for an operation on an object only affects memory references related to that object. So __atomic_add_fetch(&foo, 1, __ATOMIC_SEQ_CST) is only a full barrier for references that can affect the value of foo, other references can be moved around it. The documentation for the __sync builtins is clear that the __sync_fetch_and_add is a barrier that affects all memory references. There are C11 fences which make __ATOMIC_SEQ_CST act as a barrier for all memory references but these are distinct from the operations on a memory location. Descriptions of C11 atomics are a little opaque, the relevant sections in the C11 standard seem to be 5.1.2.4-9 Note 4 ("There is a separate order for each atomic object") and 7.17.3-7 (limiting memory_order_seq_cst to affected locations). Torvald Riegels email, linked above, explains it better. It's from a similar discussion about the Aarch64 implementation of MEMMODEL_SEQ_CST for the __atomic builtins.