2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * Copyright (c) 2010 Helge Bahmann
7 * Copyright (c) 2013 Tim Blechmann
8 * Copyright (c) 2014 Andrey Semashev
11 * \file atomic/detail/ops_gcc_sparc.hpp
13 * This header contains implementation of the \c operations template.
16 #ifndef BOOST_ATOMIC_DETAIL_OPS_GCC_SPARC_HPP_INCLUDED_
17 #define BOOST_ATOMIC_DETAIL_OPS_GCC_SPARC_HPP_INCLUDED_
19 #include <boost/memory_order.hpp>
20 #include <boost/atomic/detail/config.hpp>
21 #include <boost/atomic/detail/storage_type.hpp>
22 #include <boost/atomic/detail/operations_fwd.hpp>
23 #include <boost/atomic/capabilities.hpp>
24 #include <boost/atomic/detail/ops_cas_based.hpp>
25 #include <boost/atomic/detail/ops_extending_cas_based.hpp>
27 #ifdef BOOST_HAS_PRAGMA_ONCE
35 struct gcc_sparc_cas_base
37 static BOOST_CONSTEXPR_OR_CONST bool is_always_lock_free = true;
39 static BOOST_FORCEINLINE void fence_before(memory_order order) BOOST_NOEXCEPT
41 if (order == memory_order_seq_cst)
42 __asm__ __volatile__ ("membar #Sync" ::: "memory");
43 else if ((order & memory_order_release) != 0)
44 __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
47 static BOOST_FORCEINLINE void fence_after(memory_order order) BOOST_NOEXCEPT
49 if (order == memory_order_seq_cst)
50 __asm__ __volatile__ ("membar #Sync" ::: "memory");
51 else if ((order & (memory_order_consume | memory_order_acquire)) != 0)
52 __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
55 static BOOST_FORCEINLINE void fence_after_store(memory_order order) BOOST_NOEXCEPT
57 if (order == memory_order_seq_cst)
58 __asm__ __volatile__ ("membar #Sync" ::: "memory");
62 template< bool Signed >
63 struct gcc_sparc_cas32 :
64 public gcc_sparc_cas_base
66 typedef typename make_storage_type< 4u, Signed >::type storage_type;
67 typedef typename make_storage_type< 4u, Signed >::aligned aligned_storage_type;
69 static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
73 fence_after_store(order);
76 static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT
78 storage_type v = storage;
83 static BOOST_FORCEINLINE bool compare_exchange_strong(
84 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
86 fence_before(success_order);
87 storage_type previous = expected;
92 : "r" (&storage), "r" (previous)
95 const bool success = (desired == previous);
97 fence_after(success_order);
99 fence_after(failure_order);
104 static BOOST_FORCEINLINE bool compare_exchange_weak(
105 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
107 return compare_exchange_strong(storage, expected, desired, success_order, failure_order);
110 static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
124 static BOOST_FORCEINLINE bool is_lock_free(storage_type const volatile&) BOOST_NOEXCEPT
130 template< bool Signed >
131 struct operations< 4u, Signed > :
132 public cas_based_operations< gcc_sparc_cas32< Signed > >
136 template< bool Signed >
137 struct operations< 1u, Signed > :
138 public extending_cas_based_operations< operations< 4u, Signed >, 1u, Signed >
142 template< bool Signed >
143 struct operations< 2u, Signed > :
144 public extending_cas_based_operations< operations< 4u, Signed >, 2u, Signed >
148 template< bool Signed >
149 struct gcc_sparc_cas64 :
150 public gcc_sparc_cas_base
152 typedef typename make_storage_type< 8u, Signed >::type storage_type;
153 typedef typename make_storage_type< 8u, Signed >::aligned aligned_storage_type;
155 static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
159 fence_after_store(order);
162 static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT
164 storage_type v = storage;
169 static BOOST_FORCEINLINE bool compare_exchange_strong(
170 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
172 fence_before(success_order);
173 storage_type previous = expected;
178 : "r" (&storage), "r" (previous)
181 const bool success = (desired == previous);
183 fence_after(success_order);
185 fence_after(failure_order);
190 static BOOST_FORCEINLINE bool compare_exchange_weak(
191 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
193 return compare_exchange_strong(storage, expected, desired, success_order, failure_order);
196 static BOOST_FORCEINLINE bool is_lock_free(storage_type const volatile&) BOOST_NOEXCEPT
202 template< bool Signed >
203 struct operations< 8u, Signed > :
204 public cas_based_operations< cas_based_exchange< gcc_sparc_cas64< Signed > > >
209 BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT
213 case memory_order_release:
214 __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
216 case memory_order_consume:
217 case memory_order_acquire:
218 __asm__ __volatile__ ("membar #LoadLoad | #LoadStore" ::: "memory");
220 case memory_order_acq_rel:
221 __asm__ __volatile__ ("membar #LoadLoad | #LoadStore | #StoreStore" ::: "memory");
223 case memory_order_seq_cst:
224 __asm__ __volatile__ ("membar #Sync" ::: "memory");
226 case memory_order_relaxed:
232 BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT
234 if (order != memory_order_relaxed)
235 __asm__ __volatile__ ("" ::: "memory");
238 } // namespace detail
239 } // namespace atomics
242 #endif // BOOST_ATOMIC_DETAIL_OPS_GCC_SPARC_HPP_INCLUDED_