* [committed] Use ACQ_REL __atomic_fetch_add in atomicity.h (PR libstdc++/51798)
@ 2012-01-27 20:32 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2012-01-27 20:32 UTC (permalink / raw)
To: Benjamin Kosnik; +Cc: gcc-patches, libstdc++
Hi!
As reported by David, PowerPC* has been using (contrary to documentation)
__ATOMIC_ACQ_REL semantics (i.e. lwsync insn before and isync after)
__sync_fetch_and_add intrinsics, which is heavily used in libstdc++.
As this worked before, and there is no need for the strong consistency
among the __exchange_and_add and __atomic_add users, this patch
changes those to use __atomic_fetch_add with __ATOMIC_ACQ_REL, which
generates on powerpc* the same insn sequence as before, while
__sync_fetch_and_add now generates the more expensive sync insn before and
isync after.
Bootstrapped/regtested on x86_64-linux, i686-linux, s390-linux, s390x-linux,
powerpc64-linux 32-bit and 64-bit, approved in the PR by Benjamin, committed
to trunk.
2012-01-27 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/51798
* config/cpu/generic/atomicity_builtins/atomicity.h
(__exchange_and_add, __atomic_add): Use __atomic_fetch_add
with __ATOMIC_ACQ_REL semantics instead of __sync_fetch_and_add.
* include/ext/atomicity.h (__exchange_and_add, __atomic_add):
Likewise.
--- libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h.jj 2011-01-31 14:11:47.000000000 +0100
+++ libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h 2012-01-27 12:10:10.395649890 +0100
@@ -1,7 +1,7 @@
// Low-level functions for atomic operations: version for CPUs providing
// atomic builtins -*- C++ -*-
-// Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2006, 2009, 2010, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -33,12 +33,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Atomic_word
__attribute__ ((__unused__))
__exchange_and_add(volatile _Atomic_word* __mem, int __val) throw ()
- { return __sync_fetch_and_add(__mem, __val); }
+ { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
void
__attribute__ ((__unused__))
__atomic_add(volatile _Atomic_word* __mem, int __val) throw ()
- { __sync_fetch_and_add(__mem, __val); }
+ { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
--- libstdc++-v3/include/ext/atomicity.h.jj 2011-12-01 11:45:00.000000000 +0100
+++ libstdc++-v3/include/ext/atomicity.h 2012-01-27 12:11:09.286306232 +0100
@@ -1,6 +1,6 @@
// Support for atomic operations -*- C++ -*-
-// Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011
+// Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011, 2012
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -45,11 +45,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifdef _GLIBCXX_ATOMIC_BUILTINS
static inline _Atomic_word
__exchange_and_add(volatile _Atomic_word* __mem, int __val)
- { return __sync_fetch_and_add(__mem, __val); }
+ { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
static inline void
__atomic_add(volatile _Atomic_word* __mem, int __val)
- { __sync_fetch_and_add(__mem, __val); }
+ { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
#else
_Atomic_word
__attribute__ ((__unused__))
Jakub
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-01-27 20:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 20:32 [committed] Use ACQ_REL __atomic_fetch_add in atomicity.h (PR libstdc++/51798) Jakub Jelinek
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).