]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/atomic/detail/extra_ops_gcc_ppc.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / atomic / detail / extra_ops_gcc_ppc.hpp
1 /*
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)
5 *
6 * Copyright (c) 2017 Andrey Semashev
7 */
8 /*!
9 * \file atomic/detail/extra_ops_gcc_ppc.hpp
10 *
11 * This header contains implementation of the extra atomic operations for PowerPC.
12 */
13
14 #ifndef BOOST_ATOMIC_DETAIL_EXTRA_OPS_GCC_PPC_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_EXTRA_OPS_GCC_PPC_HPP_INCLUDED_
16
17 #include <cstddef>
18 #include <boost/memory_order.hpp>
19 #include <boost/atomic/detail/config.hpp>
20 #include <boost/atomic/detail/storage_type.hpp>
21 #include <boost/atomic/detail/extra_operations_fwd.hpp>
22 #include <boost/atomic/detail/extra_ops_generic.hpp>
23 #include <boost/atomic/detail/ops_gcc_ppc_common.hpp>
24 #include <boost/atomic/capabilities.hpp>
25
26 #ifdef BOOST_HAS_PRAGMA_ONCE
27 #pragma once
28 #endif
29
30 namespace boost {
31 namespace atomics {
32 namespace detail {
33
34 #if defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LBARX_STBCX)
35
36 template< typename Base, bool Signed >
37 struct extra_operations< Base, 1u, Signed > :
38 public generic_extra_operations< Base, 1u, Signed >
39 {
40 typedef generic_extra_operations< Base, 1u, Signed > base_type;
41 typedef typename base_type::storage_type storage_type;
42
43 static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
44 {
45 gcc_ppc_operations_base::fence_before(order);
46 storage_type original, tmp;
47 __asm__ __volatile__
48 (
49 "1:\n\t"
50 "lbarx %0,%y2\n\t"
51 "neg %1,%0\n\t"
52 "stbcx. %1,%y2\n\t"
53 "bne- 1b\n\t"
54 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
55 :
56 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
57 );
58 gcc_ppc_operations_base::fence_after(order);
59 return original;
60 }
61
62 static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
63 {
64 gcc_ppc_operations_base::fence_before(order);
65 storage_type original, tmp;
66 __asm__ __volatile__
67 (
68 "1:\n\t"
69 "lbarx %0,%y2\n\t"
70 "nor %1,%0,%0\n\t"
71 "stbcx. %1,%y2\n\t"
72 "bne- 1b\n\t"
73 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
74 :
75 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
76 );
77 gcc_ppc_operations_base::fence_after(order);
78 return original;
79 }
80
81 static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
82 {
83 fetch_negate(storage, order);
84 }
85
86 static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
87 {
88 fetch_complement(storage, order);
89 }
90 };
91
92 #endif // defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LBARX_STBCX)
93
94 #if defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LHARX_STHCX)
95
96 template< typename Base, bool Signed >
97 struct extra_operations< Base, 2u, Signed > :
98 public generic_extra_operations< Base, 2u, Signed >
99 {
100 typedef generic_extra_operations< Base, 2u, Signed > base_type;
101 typedef typename base_type::storage_type storage_type;
102
103 static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
104 {
105 gcc_ppc_operations_base::fence_before(order);
106 storage_type original, tmp;
107 __asm__ __volatile__
108 (
109 "1:\n\t"
110 "lharx %0,%y2\n\t"
111 "neg %1,%0\n\t"
112 "sthcx. %1,%y2\n\t"
113 "bne- 1b\n\t"
114 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
115 :
116 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
117 );
118 gcc_ppc_operations_base::fence_after(order);
119 return original;
120 }
121
122 static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
123 {
124 gcc_ppc_operations_base::fence_before(order);
125 storage_type original, tmp;
126 __asm__ __volatile__
127 (
128 "1:\n\t"
129 "lharx %0,%y2\n\t"
130 "nor %1,%0,%0\n\t"
131 "sthcx. %1,%y2\n\t"
132 "bne- 1b\n\t"
133 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
134 :
135 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
136 );
137 gcc_ppc_operations_base::fence_after(order);
138 return original;
139 }
140
141 static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
142 {
143 fetch_negate(storage, order);
144 }
145
146 static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
147 {
148 fetch_complement(storage, order);
149 }
150 };
151
152 #endif // defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LHARX_STHCX)
153
154 template< typename Base, bool Signed >
155 struct extra_operations< Base, 4u, Signed > :
156 public generic_extra_operations< Base, 4u, Signed >
157 {
158 typedef generic_extra_operations< Base, 4u, Signed > base_type;
159 typedef typename base_type::storage_type storage_type;
160
161 static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
162 {
163 gcc_ppc_operations_base::fence_before(order);
164 storage_type original, tmp;
165 __asm__ __volatile__
166 (
167 "1:\n\t"
168 "lwarx %0,%y2\n\t"
169 "neg %1,%0\n\t"
170 "stwcx. %1,%y2\n\t"
171 "bne- 1b\n\t"
172 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
173 :
174 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
175 );
176 gcc_ppc_operations_base::fence_after(order);
177 return original;
178 }
179
180 static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
181 {
182 gcc_ppc_operations_base::fence_before(order);
183 storage_type original, tmp;
184 __asm__ __volatile__
185 (
186 "1:\n\t"
187 "lwarx %0,%y2\n\t"
188 "nor %1,%0,%0\n\t"
189 "stwcx. %1,%y2\n\t"
190 "bne- 1b\n\t"
191 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
192 :
193 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
194 );
195 gcc_ppc_operations_base::fence_after(order);
196 return original;
197 }
198
199 static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
200 {
201 fetch_negate(storage, order);
202 }
203
204 static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
205 {
206 fetch_complement(storage, order);
207 }
208 };
209
210 #if defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LDARX_STDCX)
211
212 template< typename Base, bool Signed >
213 struct extra_operations< Base, 8u, Signed > :
214 public generic_extra_operations< Base, 8u, Signed >
215 {
216 typedef generic_extra_operations< Base, 8u, Signed > base_type;
217 typedef typename base_type::storage_type storage_type;
218
219 static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
220 {
221 gcc_ppc_operations_base::fence_before(order);
222 storage_type original, tmp;
223 __asm__ __volatile__
224 (
225 "1:\n\t"
226 "ldarx %0,%y2\n\t"
227 "neg %1,%0\n\t"
228 "stdcx. %1,%y2\n\t"
229 "bne- 1b\n\t"
230 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
231 :
232 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
233 );
234 gcc_ppc_operations_base::fence_after(order);
235 return original;
236 }
237
238 static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
239 {
240 gcc_ppc_operations_base::fence_before(order);
241 storage_type original, tmp;
242 __asm__ __volatile__
243 (
244 "1:\n\t"
245 "ldarx %0,%y2\n\t"
246 "nor %1,%0,%0\n\t"
247 "stdcx. %1,%y2\n\t"
248 "bne- 1b\n\t"
249 : "=&b" (original), "=&b" (tmp), "+Z" (storage)
250 :
251 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
252 );
253 gcc_ppc_operations_base::fence_after(order);
254 return original;
255 }
256
257 static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
258 {
259 fetch_negate(storage, order);
260 }
261
262 static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
263 {
264 fetch_complement(storage, order);
265 }
266 };
267
268 #endif // defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LDARX_STDCX)
269
270 } // namespace detail
271 } // namespace atomics
272 } // namespace boost
273
274 #endif // BOOST_ATOMIC_DETAIL_EXTRA_OPS_GCC_ARM_PPC_INCLUDED_