author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 59252 | 623722a6aeb9 |
permissions | -rw-r--r-- |
42065 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
59122 | 3 |
* Copyright (c) 2016, 2019 SAP SE. All rights reserved. |
42065 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
* |
|
24 |
*/ |
|
25 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
26 |
#ifndef OS_CPU_LINUX_S390_ATOMIC_LINUX_S390_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
27 |
#define OS_CPU_LINUX_S390_ATOMIC_LINUX_S390_HPP |
42065 | 28 |
|
29 |
#include "runtime/atomic.hpp" |
|
30 |
#include "runtime/os.hpp" |
|
59122 | 31 |
#include "runtime/vm_version.hpp" |
42065 | 32 |
|
33 |
// Note that the compare-and-swap instructions on System z perform |
|
34 |
// a serialization function before the storage operand is fetched |
|
35 |
// and again after the operation is completed. |
|
36 |
// |
|
37 |
// Used constraint modifiers: |
|
38 |
// = write-only access: Value on entry to inline-assembler code irrelevant. |
|
39 |
// + read/write access: Value on entry is used; on exit value is changed. |
|
40 |
// read-only access: Value on entry is used and never changed. |
|
41 |
// & early-clobber access: Might be modified before all read-only operands |
|
42 |
// have been used. |
|
43 |
// a address register operand (not GR0). |
|
44 |
// d general register operand (including GR0) |
|
45 |
// Q memory operand w/o index register. |
|
46 |
// 0..9 operand reference (by operand position). |
|
47 |
// Used for operands that fill multiple roles. One example would be a |
|
48 |
// write-only operand receiving its initial value from a read-only operand. |
|
49 |
// Refer to cmpxchg(..) operand #0 and variable cmp_val for a real-life example. |
|
50 |
// |
|
51 |
||
52 |
// On System z, all store operations are atomic if the address where the data is stored into |
|
53 |
// is an integer multiple of the data length. Furthermore, all stores are ordered: |
|
54 |
// a store which occurs conceptually before another store becomes visible to other CPUs |
|
55 |
// before the other store becomes visible. |
|
56 |
||
57 |
//------------ |
|
58 |
// Atomic::add |
|
59 |
//------------ |
|
60 |
// These methods force the value in memory to be augmented by the passed increment. |
|
61 |
// Both, memory value and increment, are treated as 32bit signed binary integers. |
|
62 |
// No overflow exceptions are recognized, and the condition code does not hold |
|
63 |
// information about the value in memory. |
|
64 |
// |
|
65 |
// The value in memory is updated by using a compare-and-swap instruction. The |
|
66 |
// instruction is retried as often as required. |
|
67 |
// |
|
68 |
// The return value of the method is the value that was successfully stored. At the |
|
69 |
// time the caller receives back control, the value in memory may have changed already. |
|
70 |
||
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
71 |
// New atomic operations only include specific-operand-serialization, not full |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
72 |
// memory barriers. We can use the Fast-BCR-Serialization Facility for them. |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
73 |
inline void z196_fast_sync() { |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
74 |
__asm__ __volatile__ ("bcr 14, 0" : : : "memory"); |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
75 |
} |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
76 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
77 |
template<size_t byte_size> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
78 |
struct Atomic::PlatformAdd |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
79 |
: Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> > |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
80 |
{ |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
59247
diff
changeset
|
81 |
template<typename D, typename I> |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
59247
diff
changeset
|
82 |
D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const; |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
83 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
84 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
85 |
template<> |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
59247
diff
changeset
|
86 |
template<typename D, typename I> |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
59247
diff
changeset
|
87 |
inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I inc, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
88 |
atomic_memory_order order) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
89 |
STATIC_ASSERT(4 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
90 |
STATIC_ASSERT(4 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
91 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
92 |
D old, upd; |
42065 | 93 |
|
94 |
if (VM_Version::has_LoadAndALUAtomicV1()) { |
|
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
95 |
if (order == memory_order_conservative) { z196_fast_sync(); } |
42065 | 96 |
__asm__ __volatile__ ( |
97 |
" LGFR 0,%[inc] \n\t" // save increment |
|
98 |
" LA 3,%[mem] \n\t" // force data address into ARG2 |
|
99 |
// " LAA %[upd],%[inc],%[mem] \n\t" // increment and get old value |
|
100 |
// " LAA 2,0,0(3) \n\t" // actually coded instruction |
|
101 |
" .byte 0xeb \n\t" // LAA main opcode |
|
102 |
" .byte 0x20 \n\t" // R1,R3 |
|
103 |
" .byte 0x30 \n\t" // R2,disp1 |
|
104 |
" .byte 0x00 \n\t" // disp2,disp3 |
|
105 |
" .byte 0x00 \n\t" // disp4,disp5 |
|
106 |
" .byte 0xf8 \n\t" // LAA minor opcode |
|
107 |
" AR 2,0 \n\t" // calc new value in register |
|
108 |
" LR %[upd],2 \n\t" // move to result register |
|
109 |
//---< outputs >--- |
|
110 |
: [upd] "=&d" (upd) // write-only, updated counter value |
|
111 |
, [mem] "+Q" (*dest) // read/write, memory to be updated atomically |
|
112 |
//---< inputs >--- |
|
113 |
: [inc] "a" (inc) // read-only. |
|
114 |
//---< clobbered >--- |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
115 |
: "cc", "r0", "r2", "r3", "memory" |
42065 | 116 |
); |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
117 |
if (order == memory_order_conservative) { z196_fast_sync(); } |
42065 | 118 |
} else { |
119 |
__asm__ __volatile__ ( |
|
120 |
" LLGF %[old],%[mem] \n\t" // get old value |
|
121 |
"0: LA %[upd],0(%[inc],%[old]) \n\t" // calc result |
|
122 |
" CS %[old],%[upd],%[mem] \n\t" // try to xchg res with mem |
|
123 |
" JNE 0b \n\t" // no success? -> retry |
|
124 |
//---< outputs >--- |
|
125 |
: [old] "=&a" (old) // write-only, old counter value |
|
126 |
, [upd] "=&d" (upd) // write-only, updated counter value |
|
127 |
, [mem] "+Q" (*dest) // read/write, memory to be updated atomically |
|
128 |
//---< inputs >--- |
|
129 |
: [inc] "a" (inc) // read-only. |
|
130 |
//---< clobbered >--- |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
131 |
: "cc", "memory" |
42065 | 132 |
); |
133 |
} |
|
134 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
135 |
return upd; |
42065 | 136 |
} |
137 |
||
138 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
139 |
template<> |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
59247
diff
changeset
|
140 |
template<typename D, typename I> |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
59247
diff
changeset
|
141 |
inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I inc, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
142 |
atomic_memory_order order) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
143 |
STATIC_ASSERT(8 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
144 |
STATIC_ASSERT(8 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
145 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
146 |
D old, upd; |
42065 | 147 |
|
148 |
if (VM_Version::has_LoadAndALUAtomicV1()) { |
|
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
149 |
if (order == memory_order_conservative) { z196_fast_sync(); } |
42065 | 150 |
__asm__ __volatile__ ( |
151 |
" LGR 0,%[inc] \n\t" // save increment |
|
152 |
" LA 3,%[mem] \n\t" // force data address into ARG2 |
|
153 |
// " LAAG %[upd],%[inc],%[mem] \n\t" // increment and get old value |
|
154 |
// " LAAG 2,0,0(3) \n\t" // actually coded instruction |
|
155 |
" .byte 0xeb \n\t" // LAA main opcode |
|
156 |
" .byte 0x20 \n\t" // R1,R3 |
|
157 |
" .byte 0x30 \n\t" // R2,disp1 |
|
158 |
" .byte 0x00 \n\t" // disp2,disp3 |
|
159 |
" .byte 0x00 \n\t" // disp4,disp5 |
|
160 |
" .byte 0xe8 \n\t" // LAA minor opcode |
|
161 |
" AGR 2,0 \n\t" // calc new value in register |
|
162 |
" LGR %[upd],2 \n\t" // move to result register |
|
163 |
//---< outputs >--- |
|
164 |
: [upd] "=&d" (upd) // write-only, updated counter value |
|
165 |
, [mem] "+Q" (*dest) // read/write, memory to be updated atomically |
|
166 |
//---< inputs >--- |
|
167 |
: [inc] "a" (inc) // read-only. |
|
168 |
//---< clobbered >--- |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
169 |
: "cc", "r0", "r2", "r3", "memory" |
42065 | 170 |
); |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
171 |
if (order == memory_order_conservative) { z196_fast_sync(); } |
42065 | 172 |
} else { |
173 |
__asm__ __volatile__ ( |
|
174 |
" LG %[old],%[mem] \n\t" // get old value |
|
175 |
"0: LA %[upd],0(%[inc],%[old]) \n\t" // calc result |
|
176 |
" CSG %[old],%[upd],%[mem] \n\t" // try to xchg res with mem |
|
177 |
" JNE 0b \n\t" // no success? -> retry |
|
178 |
//---< outputs >--- |
|
179 |
: [old] "=&a" (old) // write-only, old counter value |
|
180 |
, [upd] "=&d" (upd) // write-only, updated counter value |
|
181 |
, [mem] "+Q" (*dest) // read/write, memory to be updated atomically |
|
182 |
//---< inputs >--- |
|
183 |
: [inc] "a" (inc) // read-only. |
|
184 |
//---< clobbered >--- |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
185 |
: "cc", "memory" |
42065 | 186 |
); |
187 |
} |
|
188 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
189 |
return upd; |
42065 | 190 |
} |
191 |
||
192 |
||
193 |
//------------- |
|
194 |
// Atomic::xchg |
|
195 |
//------------- |
|
196 |
// These methods force the value in memory to be replaced by the new value passed |
|
197 |
// in as argument. |
|
198 |
// |
|
199 |
// The value in memory is replaced by using a compare-and-swap instruction. The |
|
200 |
// instruction is retried as often as required. This makes sure that the new |
|
201 |
// value can be seen, at least for a very short period of time, by other CPUs. |
|
202 |
// |
|
203 |
// If we would use a normal "load(old value) store(new value)" sequence, |
|
204 |
// the new value could be lost unnoticed, due to a store(new value) from |
|
205 |
// another thread. |
|
206 |
// |
|
207 |
// The return value is the (unchanged) value from memory as it was when the |
|
208 |
// replacement succeeded. |
|
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
209 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
210 |
template<typename T> |
59251
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
211 |
inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest, |
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
212 |
T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
213 |
atomic_memory_order unused) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
214 |
STATIC_ASSERT(4 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
215 |
T old; |
42065 | 216 |
|
217 |
__asm__ __volatile__ ( |
|
218 |
" LLGF %[old],%[mem] \n\t" // get old value |
|
219 |
"0: CS %[old],%[upd],%[mem] \n\t" // try to xchg upd with mem |
|
220 |
" JNE 0b \n\t" // no success? -> retry |
|
221 |
//---< outputs >--- |
|
222 |
: [old] "=&d" (old) // write-only, prev value irrelevant |
|
223 |
, [mem] "+Q" (*dest) // read/write, memory to be updated atomically |
|
224 |
//---< inputs >--- |
|
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
225 |
: [upd] "d" (exchange_value) // read-only, value to be written to memory |
42065 | 226 |
//---< clobbered >--- |
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
227 |
: "cc", "memory" |
42065 | 228 |
); |
229 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
230 |
return old; |
42065 | 231 |
} |
232 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
233 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
234 |
template<typename T> |
59251
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
235 |
inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest, |
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
236 |
T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
237 |
atomic_memory_order unused) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
238 |
STATIC_ASSERT(8 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
239 |
T old; |
42065 | 240 |
|
241 |
__asm__ __volatile__ ( |
|
242 |
" LG %[old],%[mem] \n\t" // get old value |
|
243 |
"0: CSG %[old],%[upd],%[mem] \n\t" // try to xchg upd with mem |
|
244 |
" JNE 0b \n\t" // no success? -> retry |
|
245 |
//---< outputs >--- |
|
246 |
: [old] "=&d" (old) // write-only, init from memory |
|
247 |
, [mem] "+Q" (*dest) // read/write, memory to be updated atomically |
|
248 |
//---< inputs >--- |
|
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
249 |
: [upd] "d" (exchange_value) // read-only, value to be written to memory |
42065 | 250 |
//---< clobbered >--- |
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
251 |
: "cc", "memory" |
42065 | 252 |
); |
253 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
254 |
return old; |
42065 | 255 |
} |
256 |
||
257 |
//---------------- |
|
258 |
// Atomic::cmpxchg |
|
259 |
//---------------- |
|
260 |
// These methods compare the value in memory with a given compare value. |
|
261 |
// If both values compare equal, the value in memory is replaced with |
|
262 |
// the exchange value. |
|
263 |
// |
|
264 |
// The value in memory is compared and replaced by using a compare-and-swap |
|
265 |
// instruction. The instruction is NOT retried (one shot only). |
|
266 |
// |
|
267 |
// The return value is the (unchanged) value from memory as it was when the |
|
268 |
// compare-and-swap instruction completed. A successful exchange operation |
|
269 |
// is indicated by (return value == compare_value). If unsuccessful, a new |
|
270 |
// exchange value can be calculated based on the return value which is the |
|
271 |
// latest contents of the memory location. |
|
272 |
// |
|
273 |
// Inspecting the return value is the only way for the caller to determine |
|
274 |
// if the compare-and-swap instruction was successful: |
|
275 |
// - If return value and compare value compare equal, the compare-and-swap |
|
276 |
// instruction was successful and the value in memory was replaced by the |
|
277 |
// exchange value. |
|
278 |
// - If return value and compare value compare unequal, the compare-and-swap |
|
279 |
// instruction was not successful. The value in memory was left unchanged. |
|
280 |
// |
|
281 |
// The s390 processors always fence before and after the csg instructions. |
|
282 |
// Thus we ignore the memory ordering argument. The docu says: "A serialization |
|
283 |
// function is performed before the operand is fetched and again after the |
|
284 |
// operation is completed." |
|
285 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
286 |
// No direct support for cmpxchg of bytes; emulate using int. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
287 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
288 |
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
289 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
290 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
291 |
template<typename T> |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59251
diff
changeset
|
292 |
inline T Atomic::PlatformCmpxchg<4>::operator()(T volatile* dest, |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
293 |
T cmp_val, |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59251
diff
changeset
|
294 |
T xchg_val, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
295 |
atomic_memory_order unused) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
296 |
STATIC_ASSERT(4 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
297 |
T old; |
42065 | 298 |
|
299 |
__asm__ __volatile__ ( |
|
300 |
" CS %[old],%[upd],%[mem] \n\t" // Try to xchg upd with mem. |
|
301 |
// outputs |
|
302 |
: [old] "=&d" (old) // Write-only, prev value irrelevant. |
|
303 |
, [mem] "+Q" (*dest) // Read/write, memory to be updated atomically. |
|
304 |
// inputs |
|
305 |
: [upd] "d" (xchg_val) |
|
306 |
, "0" (cmp_val) // Read-only, initial value for [old] (operand #0). |
|
307 |
// clobbered |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
308 |
: "cc", "memory" |
42065 | 309 |
); |
310 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
311 |
return old; |
42065 | 312 |
} |
313 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
314 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
315 |
template<typename T> |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59251
diff
changeset
|
316 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T volatile* dest, |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
317 |
T cmp_val, |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59251
diff
changeset
|
318 |
T xchg_val, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
319 |
atomic_memory_order unused) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
320 |
STATIC_ASSERT(8 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
321 |
T old; |
42065 | 322 |
|
323 |
__asm__ __volatile__ ( |
|
324 |
" CSG %[old],%[upd],%[mem] \n\t" // Try to xchg upd with mem. |
|
325 |
// outputs |
|
326 |
: [old] "=&d" (old) // Write-only, prev value irrelevant. |
|
327 |
, [mem] "+Q" (*dest) // Read/write, memory to be updated atomically. |
|
328 |
// inputs |
|
329 |
: [upd] "d" (xchg_val) |
|
330 |
, "0" (cmp_val) // Read-only, initial value for [old] (operand #0). |
|
331 |
// clobbered |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
46523
diff
changeset
|
332 |
: "cc", "memory" |
42065 | 333 |
); |
334 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46953
diff
changeset
|
335 |
return old; |
42065 | 336 |
} |
337 |
||
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
338 |
template<size_t byte_size> |
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
339 |
struct Atomic::PlatformOrderedLoad<byte_size, X_ACQUIRE> |
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
340 |
{ |
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
341 |
template <typename T> |
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
342 |
T operator()(const volatile T* p) const { T t = *p; OrderAccess::acquire(); return t; } |
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
343 |
}; |
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
59122
diff
changeset
|
344 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
345 |
#endif // OS_CPU_LINUX_S390_ATOMIC_LINUX_S390_HPP |