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_
20 #include <boost/memory_order.hpp>
21 #include <boost/atomic/detail/config.hpp>
22 #include <boost/atomic/detail/storage_type.hpp>
23 #include <boost/atomic/detail/operations_fwd.hpp>
24 #include <boost/atomic/capabilities.hpp>
25 #include <boost/atomic/detail/ops_cas_based.hpp>
26 #include <boost/atomic/detail/ops_extending_cas_based.hpp>
28 #ifdef BOOST_HAS_PRAGMA_ONCE
36 struct gcc_sparc_cas_base
38 static BOOST_CONSTEXPR_OR_CONST bool is_always_lock_free = true;
40 static BOOST_FORCEINLINE void fence_before(memory_order order) BOOST_NOEXCEPT
42 if (order == memory_order_seq_cst)
43 __asm__ __volatile__ ("membar #Sync" ::: "memory");
44 else if ((order & memory_order_release) != 0)
45 __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
48 static BOOST_FORCEINLINE void fence_after(memory_order order) BOOST_NOEXCEPT
50 if (order == memory_order_seq_cst)
51 __asm__ __volatile__ ("membar #Sync" ::: "memory");
52 else if ((order & (memory_order_consume | memory_order_acquire)) != 0)
53 __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
56 static BOOST_FORCEINLINE void fence_after_store(memory_order order) BOOST_NOEXCEPT
58 if (order == memory_order_seq_cst)
59 __asm__ __volatile__ ("membar #Sync" ::: "memory");
63 template< bool Signed >
64 struct gcc_sparc_cas32 :
65 public gcc_sparc_cas_base
67 typedef typename make_storage_type< 4u, Signed >::type storage_type;
68 typedef typename make_storage_type< 4u, Signed >::aligned aligned_storage_type;
70 static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 4u;
71 static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
73 static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
77 fence_after_store(order);
80 static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT
82 storage_type v = storage;
87 static BOOST_FORCEINLINE bool compare_exchange_strong(
88 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
90 fence_before(success_order);
91 storage_type previous = expected;
96 : "r" (&storage), "r" (previous)
99 const bool success = (desired == previous);
101 fence_after(success_order);
103 fence_after(failure_order);
108 static BOOST_FORCEINLINE bool compare_exchange_weak(
109 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
111 return compare_exchange_strong(storage, expected, desired, success_order, failure_order);
114 static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
129 template< bool Signed >
130 struct operations< 4u, Signed > :
131 public cas_based_operations< gcc_sparc_cas32< Signed > >
135 template< bool Signed >
136 struct operations< 1u, Signed > :
137 public extending_cas_based_operations< operations< 4u, Signed >, 1u, Signed >
141 template< bool Signed >
142 struct operations< 2u, Signed > :
143 public extending_cas_based_operations< operations< 4u, Signed >, 2u, Signed >
147 template< bool Signed >
148 struct gcc_sparc_cas64 :
149 public gcc_sparc_cas_base
151 typedef typename make_storage_type< 8u, Signed >::type storage_type;
152 typedef typename make_storage_type< 8u, Signed >::aligned aligned_storage_type;
154 static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 8u;
155 static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
157 static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
161 fence_after_store(order);
164 static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT
166 storage_type v = storage;
171 static BOOST_FORCEINLINE bool compare_exchange_strong(
172 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
174 fence_before(success_order);
175 storage_type previous = expected;
180 : "r" (&storage), "r" (previous)
183 const bool success = (desired == previous);
185 fence_after(success_order);
187 fence_after(failure_order);
192 static BOOST_FORCEINLINE bool compare_exchange_weak(
193 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
195 return compare_exchange_strong(storage, expected, desired, success_order, failure_order);
199 template< bool Signed >
200 struct operations< 8u, Signed > :
201 public cas_based_operations< cas_based_exchange< gcc_sparc_cas64< Signed > > >
206 BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT
210 case memory_order_release:
211 __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
213 case memory_order_consume:
214 case memory_order_acquire:
215 __asm__ __volatile__ ("membar #LoadLoad | #LoadStore" ::: "memory");
217 case memory_order_acq_rel:
218 __asm__ __volatile__ ("membar #LoadLoad | #LoadStore | #StoreStore" ::: "memory");
220 case memory_order_seq_cst:
221 __asm__ __volatile__ ("membar #Sync" ::: "memory");
223 case memory_order_relaxed:
229 BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT
231 if (order != memory_order_relaxed)
232 __asm__ __volatile__ ("" ::: "memory");
235 } // namespace detail
236 } // namespace atomics
239 #endif // BOOST_ATOMIC_DETAIL_OPS_GCC_SPARC_HPP_INCLUDED_