OLD | NEW |
| (Empty) |
1 // Copyright 2010 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // This file is an internal atomic implementation, use atomicops.h instead. | |
6 | |
7 #ifndef V8_ATOMICOPS_INTERNALS_MIPS_GCC_H_ | |
8 #define V8_ATOMICOPS_INTERNALS_MIPS_GCC_H_ | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 | |
13 // Atomically execute: | |
14 // result = *ptr; | |
15 // if (*ptr == old_value) | |
16 // *ptr = new_value; | |
17 // return result; | |
18 // | |
19 // I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value". | |
20 // Always return the old value of "*ptr" | |
21 // | |
22 // This routine implies no memory barriers. | |
23 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | |
24 Atomic32 old_value, | |
25 Atomic32 new_value) { | |
26 Atomic32 prev, tmp; | |
27 __asm__ __volatile__(".set push\n" | |
28 ".set noreorder\n" | |
29 "1:\n" | |
30 "ll %0, %5\n" // prev = *ptr | |
31 "bne %0, %3, 2f\n" // if (prev != old_value) goto 2 | |
32 "move %2, %4\n" // tmp = new_value | |
33 "sc %2, %1\n" // *ptr = tmp (with atomic check) | |
34 "beqz %2, 1b\n" // start again on atomic error | |
35 "nop\n" // delay slot nop | |
36 "2:\n" | |
37 ".set pop\n" | |
38 : "=&r" (prev), "=m" (*ptr), "=&r" (tmp) | |
39 : "Ir" (old_value), "r" (new_value), "m" (*ptr) | |
40 : "memory"); | |
41 return prev; | |
42 } | |
43 | |
44 // Atomically store new_value into *ptr, returning the previous value held in | |
45 // *ptr. This routine implies no memory barriers. | |
46 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | |
47 Atomic32 new_value) { | |
48 Atomic32 temp, old; | |
49 __asm__ __volatile__(".set push\n" | |
50 ".set noreorder\n" | |
51 "1:\n" | |
52 "ll %1, %2\n" // old = *ptr | |
53 "move %0, %3\n" // temp = new_value | |
54 "sc %0, %2\n" // *ptr = temp (with atomic check) | |
55 "beqz %0, 1b\n" // start again on atomic error | |
56 "nop\n" // delay slot nop | |
57 ".set pop\n" | |
58 : "=&r" (temp), "=&r" (old), "=m" (*ptr) | |
59 : "r" (new_value), "m" (*ptr) | |
60 : "memory"); | |
61 | |
62 return old; | |
63 } | |
64 | |
65 // Atomically increment *ptr by "increment". Returns the new value of | |
66 // *ptr with the increment applied. This routine implies no memory barriers. | |
67 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | |
68 Atomic32 increment) { | |
69 Atomic32 temp, temp2; | |
70 | |
71 __asm__ __volatile__(".set push\n" | |
72 ".set noreorder\n" | |
73 "1:\n" | |
74 "ll %0, %2\n" // temp = *ptr | |
75 "addu %1, %0, %3\n" // temp2 = temp + increment | |
76 "sc %1, %2\n" // *ptr = temp2 (with atomic check) | |
77 "beqz %1, 1b\n" // start again on atomic error | |
78 "addu %1, %0, %3\n" // temp2 = temp + increment | |
79 ".set pop\n" | |
80 : "=&r" (temp), "=&r" (temp2), "=m" (*ptr) | |
81 : "Ir" (increment), "m" (*ptr) | |
82 : "memory"); | |
83 // temp2 now holds the final value. | |
84 return temp2; | |
85 } | |
86 | |
87 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | |
88 Atomic32 increment) { | |
89 MemoryBarrier(); | |
90 Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment); | |
91 MemoryBarrier(); | |
92 return res; | |
93 } | |
94 | |
95 // "Acquire" operations | |
96 // ensure that no later memory access can be reordered ahead of the operation. | |
97 // "Release" operations ensure that no previous memory access can be reordered | |
98 // after the operation. "Barrier" operations have both "Acquire" and "Release" | |
99 // semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory | |
100 // access. | |
101 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, | |
102 Atomic32 old_value, | |
103 Atomic32 new_value) { | |
104 Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); | |
105 MemoryBarrier(); | |
106 return res; | |
107 } | |
108 | |
109 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, | |
110 Atomic32 old_value, | |
111 Atomic32 new_value) { | |
112 MemoryBarrier(); | |
113 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); | |
114 } | |
115 | |
116 inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { | |
117 *ptr = value; | |
118 } | |
119 | |
120 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { | |
121 *ptr = value; | |
122 } | |
123 | |
124 inline void MemoryBarrier() { | |
125 __asm__ __volatile__("sync" : : : "memory"); | |
126 } | |
127 | |
128 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { | |
129 *ptr = value; | |
130 MemoryBarrier(); | |
131 } | |
132 | |
133 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { | |
134 MemoryBarrier(); | |
135 *ptr = value; | |
136 } | |
137 | |
138 inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { | |
139 return *ptr; | |
140 } | |
141 | |
142 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { | |
143 return *ptr; | |
144 } | |
145 | |
146 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { | |
147 Atomic32 value = *ptr; | |
148 MemoryBarrier(); | |
149 return value; | |
150 } | |
151 | |
152 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { | |
153 MemoryBarrier(); | |
154 return *ptr; | |
155 } | |
156 | |
157 } } // namespace v8::internal | |
158 | |
159 #endif // V8_ATOMICOPS_INTERNALS_MIPS_GCC_H_ | |
OLD | NEW |