v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
atomicops_internals_arm64_gcc.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 // This file is an internal atomic implementation, use atomicops.h instead.
29 
30 #ifndef V8_ATOMICOPS_INTERNALS_ARM_GCC_H_
31 #define V8_ATOMICOPS_INTERNALS_ARM_GCC_H_
32 
33 namespace v8 {
34 namespace internal {
35 
36 inline void MemoryBarrier() {
37  __asm__ __volatile__ ( // NOLINT
38  "dmb ish \n\t" // Data memory barrier.
39  ::: "memory"
40  ); // NOLINT
41 }
42 
43 
45  Atomic32 old_value,
46  Atomic32 new_value) {
47  Atomic32 prev;
48  int32_t temp;
49 
50  __asm__ __volatile__ ( // NOLINT
51  "0: \n\t"
52  "ldxr %w[prev], %[ptr] \n\t" // Load the previous value.
53  "cmp %w[prev], %w[old_value] \n\t"
54  "bne 1f \n\t"
55  "stxr %w[temp], %w[new_value], %[ptr] \n\t" // Try to store the new value.
56  "cbnz %w[temp], 0b \n\t" // Retry if it did not work.
57  "1: \n\t"
58  "clrex \n\t" // In case we didn't swap.
59  : [prev]"=&r" (prev),
60  [temp]"=&r" (temp),
61  [ptr]"+Q" (*ptr)
62  : [old_value]"r" (old_value),
63  [new_value]"r" (new_value)
64  : "memory", "cc"
65  ); // NOLINT
66 
67  return prev;
68 }
69 
71  Atomic32 new_value) {
72  Atomic32 result;
73  int32_t temp;
74 
75  __asm__ __volatile__ ( // NOLINT
76  "0: \n\t"
77  "ldxr %w[result], %[ptr] \n\t" // Load the previous value.
78  "stxr %w[temp], %w[new_value], %[ptr] \n\t" // Try to store the new value.
79  "cbnz %w[temp], 0b \n\t" // Retry if it did not work.
80  : [result]"=&r" (result),
81  [temp]"=&r" (temp),
82  [ptr]"+Q" (*ptr)
83  : [new_value]"r" (new_value)
84  : "memory"
85  ); // NOLINT
86 
87  return result;
88 }
89 
91  Atomic32 increment) {
92  Atomic32 result;
93  int32_t temp;
94 
95  __asm__ __volatile__ ( // NOLINT
96  "0: \n\t"
97  "ldxr %w[result], %[ptr] \n\t" // Load the previous value.
98  "add %w[result], %w[result], %w[increment]\n\t"
99  "stxr %w[temp], %w[result], %[ptr] \n\t" // Try to store the result.
100  "cbnz %w[temp], 0b \n\t" // Retry on failure.
101  : [result]"=&r" (result),
102  [temp]"=&r" (temp),
103  [ptr]"+Q" (*ptr)
104  : [increment]"r" (increment)
105  : "memory"
106  ); // NOLINT
107 
108  return result;
109 }
110 
112  Atomic32 increment) {
113  MemoryBarrier();
114  Atomic32 result = NoBarrier_AtomicIncrement(ptr, increment);
115  MemoryBarrier();
116 
117  return result;
118 }
119 
121  Atomic32 old_value,
122  Atomic32 new_value) {
123  Atomic32 prev;
124  int32_t temp;
125 
126  __asm__ __volatile__ ( // NOLINT
127  "0: \n\t"
128  "ldxr %w[prev], %[ptr] \n\t" // Load the previous value.
129  "cmp %w[prev], %w[old_value] \n\t"
130  "bne 1f \n\t"
131  "stxr %w[temp], %w[new_value], %[ptr] \n\t" // Try to store the new value.
132  "cbnz %w[temp], 0b \n\t" // Retry if it did not work.
133  "dmb ish \n\t" // Data memory barrier.
134  "1: \n\t"
135  // If the compare failed the 'dmb' is unnecessary, but we still need a
136  // 'clrex'.
137  "clrex \n\t"
138  : [prev]"=&r" (prev),
139  [temp]"=&r" (temp),
140  [ptr]"+Q" (*ptr)
141  : [old_value]"r" (old_value),
142  [new_value]"r" (new_value)
143  : "memory", "cc"
144  ); // NOLINT
145 
146  return prev;
147 }
148 
150  Atomic32 old_value,
151  Atomic32 new_value) {
152  Atomic32 prev;
153  int32_t temp;
154 
155  MemoryBarrier();
156 
157  __asm__ __volatile__ ( // NOLINT
158  "0: \n\t"
159  "ldxr %w[prev], %[ptr] \n\t" // Load the previous value.
160  "cmp %w[prev], %w[old_value] \n\t"
161  "bne 1f \n\t"
162  "stxr %w[temp], %w[new_value], %[ptr] \n\t" // Try to store the new value.
163  "cbnz %w[temp], 0b \n\t" // Retry if it did not work.
164  "1: \n\t"
165  // If the compare failed the we still need a 'clrex'.
166  "clrex \n\t"
167  : [prev]"=&r" (prev),
168  [temp]"=&r" (temp),
169  [ptr]"+Q" (*ptr)
170  : [old_value]"r" (old_value),
171  [new_value]"r" (new_value)
172  : "memory", "cc"
173  ); // NOLINT
174 
175  return prev;
176 }
177 
178 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
179  *ptr = value;
180 }
181 
182 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
183  *ptr = value;
184  MemoryBarrier();
185 }
186 
187 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
188  MemoryBarrier();
189  *ptr = value;
190 }
191 
192 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
193  return *ptr;
194 }
195 
196 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
197  Atomic32 value = *ptr;
198  MemoryBarrier();
199  return value;
200 }
201 
202 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
203  MemoryBarrier();
204  return *ptr;
205 }
206 
207 // 64-bit versions of the operations.
208 // See the 32-bit versions for comments.
209 
210 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
211  Atomic64 old_value,
212  Atomic64 new_value) {
213  Atomic64 prev;
214  int32_t temp;
215 
216  __asm__ __volatile__ ( // NOLINT
217  "0: \n\t"
218  "ldxr %[prev], %[ptr] \n\t"
219  "cmp %[prev], %[old_value] \n\t"
220  "bne 1f \n\t"
221  "stxr %w[temp], %[new_value], %[ptr] \n\t"
222  "cbnz %w[temp], 0b \n\t"
223  "1: \n\t"
224  "clrex \n\t"
225  : [prev]"=&r" (prev),
226  [temp]"=&r" (temp),
227  [ptr]"+Q" (*ptr)
228  : [old_value]"r" (old_value),
229  [new_value]"r" (new_value)
230  : "memory", "cc"
231  ); // NOLINT
232 
233  return prev;
234 }
235 
236 inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
237  Atomic64 new_value) {
238  Atomic64 result;
239  int32_t temp;
240 
241  __asm__ __volatile__ ( // NOLINT
242  "0: \n\t"
243  "ldxr %[result], %[ptr] \n\t"
244  "stxr %w[temp], %[new_value], %[ptr] \n\t"
245  "cbnz %w[temp], 0b \n\t"
246  : [result]"=&r" (result),
247  [temp]"=&r" (temp),
248  [ptr]"+Q" (*ptr)
249  : [new_value]"r" (new_value)
250  : "memory"
251  ); // NOLINT
252 
253  return result;
254 }
255 
256 inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
257  Atomic64 increment) {
258  Atomic64 result;
259  int32_t temp;
260 
261  __asm__ __volatile__ ( // NOLINT
262  "0: \n\t"
263  "ldxr %[result], %[ptr] \n\t"
264  "add %[result], %[result], %[increment] \n\t"
265  "stxr %w[temp], %[result], %[ptr] \n\t"
266  "cbnz %w[temp], 0b \n\t"
267  : [result]"=&r" (result),
268  [temp]"=&r" (temp),
269  [ptr]"+Q" (*ptr)
270  : [increment]"r" (increment)
271  : "memory"
272  ); // NOLINT
273 
274  return result;
275 }
276 
277 inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
278  Atomic64 increment) {
279  MemoryBarrier();
280  Atomic64 result = NoBarrier_AtomicIncrement(ptr, increment);
281  MemoryBarrier();
282 
283  return result;
284 }
285 
286 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
287  Atomic64 old_value,
288  Atomic64 new_value) {
289  Atomic64 prev;
290  int32_t temp;
291 
292  __asm__ __volatile__ ( // NOLINT
293  "0: \n\t"
294  "ldxr %[prev], %[ptr] \n\t"
295  "cmp %[prev], %[old_value] \n\t"
296  "bne 1f \n\t"
297  "stxr %w[temp], %[new_value], %[ptr] \n\t"
298  "cbnz %w[temp], 0b \n\t"
299  "dmb ish \n\t"
300  "1: \n\t"
301  "clrex \n\t"
302  : [prev]"=&r" (prev),
303  [temp]"=&r" (temp),
304  [ptr]"+Q" (*ptr)
305  : [old_value]"r" (old_value),
306  [new_value]"r" (new_value)
307  : "memory", "cc"
308  ); // NOLINT
309 
310  return prev;
311 }
312 
313 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
314  Atomic64 old_value,
315  Atomic64 new_value) {
316  Atomic64 prev;
317  int32_t temp;
318 
319  MemoryBarrier();
320 
321  __asm__ __volatile__ ( // NOLINT
322  "0: \n\t"
323  "ldxr %[prev], %[ptr] \n\t"
324  "cmp %[prev], %[old_value] \n\t"
325  "bne 1f \n\t"
326  "stxr %w[temp], %[new_value], %[ptr] \n\t"
327  "cbnz %w[temp], 0b \n\t"
328  "1: \n\t"
329  "clrex \n\t"
330  : [prev]"=&r" (prev),
331  [temp]"=&r" (temp),
332  [ptr]"+Q" (*ptr)
333  : [old_value]"r" (old_value),
334  [new_value]"r" (new_value)
335  : "memory", "cc"
336  ); // NOLINT
337 
338  return prev;
339 }
340 
341 inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
342  *ptr = value;
343 }
344 
345 inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
346  *ptr = value;
347  MemoryBarrier();
348 }
349 
350 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
351  MemoryBarrier();
352  *ptr = value;
353 }
354 
355 inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
356  return *ptr;
357 }
358 
359 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
360  Atomic64 value = *ptr;
361  MemoryBarrier();
362  return value;
363 }
364 
365 inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
366  MemoryBarrier();
367  return *ptr;
368 }
369 
370 } } // namespace v8::internal
371 
372 #endif // V8_ATOMICOPS_INTERNALS_ARM_GCC_H_
void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value)
int int32_t
Definition: unicode.cc:47
Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr, Atomic32 old_value, Atomic32 new_value)
Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr, Atomic32 old_value, Atomic32 new_value)
void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value)
Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr, Atomic32 new_value)
Atomic32 Release_Load(volatile const Atomic32 *ptr)
Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment)
void Release_Store(volatile Atomic32 *ptr, Atomic32 value)
Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment)
Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr)
Atomic32 Acquire_Load(volatile const Atomic32 *ptr)
int32_t Atomic32
Definition: atomicops.h:66
Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr, Atomic32 old_value, Atomic32 new_value)