Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 576922 | Differences between
and this patch

Collapse All | Expand All

(-)a/js/src/jit/AtomicOperations.h (-1 / +236 lines)
Lines 311-316 Link Here
311
  // top of the file for more guidance.
311
  // top of the file for more guidance.
312
# if defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)
312
# if defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)
313
#  include "jit/none/AtomicOperations-ppc.h"
313
#  include "jit/none/AtomicOperations-ppc.h"
314
# elif defined(__ia64__)
315
#  include "jit/none/AtomicOperations-ia64.h"
314
# elif defined(__i386__) || defined(__x86_64__)
316
# elif defined(__i386__) || defined(__x86_64__)
315
#  include "jit/x86-shared/AtomicOperations-x86-shared.h"
317
#  include "jit/x86-shared/AtomicOperations-x86-shared.h"
316
# else
318
# else
317
-- /dev/null
Line 0 Link Here
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 * vim: set ts=8 sts=4 et sw=4 tw=99:
3
 * This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
/* For documentation, see jit/AtomicOperations.h */
8
9
#ifndef jit_ia64_AtomicOperations_ia64_h
10
#define jit_ia64_AtomicOperations_ia64_h
11
12
#include "mozilla/Assertions.h"
13
#include "mozilla/Types.h"
14
15
#if defined(__GNUC__)
16
17
// The default implementation tactic for gcc is to use the newer
18
// __atomic intrinsics added for use in C++11 <atomic>.  Where that
19
// isn't available, we use GCC's older __sync functions instead.
20
//
21
// ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS is kept as a backward
22
// compatible option for older compilers: enable this to use GCC's old
23
// __sync functions instead of the newer __atomic functions.  This
24
// will be required for GCC 4.6.x and earlier, should we need to use
25
// those versions.
26
27
//#define ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
28
29
inline bool
30
js::jit::AtomicOperations::isLockfree8()
31
{
32
# ifndef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
33
    MOZ_ASSERT(__atomic_always_lock_free(sizeof(int8_t), 0));
34
    MOZ_ASSERT(__atomic_always_lock_free(sizeof(int16_t), 0));
35
    MOZ_ASSERT(__atomic_always_lock_free(sizeof(int32_t), 0));
36
    MOZ_ASSERT(__atomic_always_lock_free(sizeof(int64_t), 0));
37
    return true;
38
# else
39
    return false;
40
# endif
41
}
42
43
inline void
44
js::jit::AtomicOperations::fenceSeqCst()
45
{
46
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
47
    __sync_synchronize();
48
# else
49
    __atomic_thread_fence(__ATOMIC_SEQ_CST);
50
# endif
51
}
52
53
template<typename T>
54
inline T
55
js::jit::AtomicOperations::loadSeqCst(T* addr)
56
{
57
    MOZ_ASSERT(sizeof(T) < 8 || isLockfree8());
58
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
59
    __sync_synchronize();
60
    T v = *addr;
61
    __sync_synchronize();
62
# else
63
    T v;
64
    __atomic_load(addr, &v, __ATOMIC_SEQ_CST);
65
# endif
66
    return v;
67
}
68
69
template<typename T>
70
inline void
71
js::jit::AtomicOperations::storeSeqCst(T* addr, T val)
72
{
73
    MOZ_ASSERT(sizeof(T) < 8 || isLockfree8());
74
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
75
    __sync_synchronize();
76
    *addr = val;
77
    __sync_synchronize();
78
# else
79
    __atomic_store(addr, &val, __ATOMIC_SEQ_CST);
80
# endif
81
}
82
83
template<typename T>
84
inline T
85
js::jit::AtomicOperations::compareExchangeSeqCst(T* addr, T oldval, T newval)
86
{
87
    MOZ_ASSERT(sizeof(T) < 8 || isLockfree8());
88
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
89
    return __sync_val_compare_and_swap(addr, oldval, newval);
90
# else
91
    __atomic_compare_exchange(addr, &oldval, &newval, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
92
    return oldval;
93
# endif
94
}
95
96
template<typename T>
97
inline T
98
js::jit::AtomicOperations::fetchAddSeqCst(T* addr, T val)
99
{
100
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
101
    return __sync_fetch_and_add(addr, val);
102
# else
103
    return __atomic_fetch_add(addr, val, __ATOMIC_SEQ_CST);
104
# endif
105
}
106
107
template<typename T>
108
inline T
109
js::jit::AtomicOperations::fetchSubSeqCst(T* addr, T val)
110
{
111
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
112
    return __sync_fetch_and_sub(addr, val);
113
# else
114
    return __atomic_fetch_sub(addr, val, __ATOMIC_SEQ_CST);
115
# endif
116
}
117
118
template<typename T>
119
inline T
120
js::jit::AtomicOperations::fetchAndSeqCst(T* addr, T val)
121
{
122
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
123
    return __sync_fetch_and_and(addr, val);
124
# else
125
    return __atomic_fetch_and(addr, val, __ATOMIC_SEQ_CST);
126
# endif
127
}
128
129
template<typename T>
130
inline T
131
js::jit::AtomicOperations::fetchOrSeqCst(T* addr, T val)
132
{
133
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
134
    return __sync_fetch_and_or(addr, val);
135
# else
136
    return __atomic_fetch_or(addr, val, __ATOMIC_SEQ_CST);
137
# endif
138
}
139
140
template<typename T>
141
inline T
142
js::jit::AtomicOperations::fetchXorSeqCst(T* addr, T val)
143
{
144
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
145
    return __sync_fetch_and_xor(addr, val);
146
# else
147
    return __atomic_fetch_xor(addr, val, __ATOMIC_SEQ_CST);
148
# endif
149
}
150
151
template<typename T>
152
inline T
153
js::jit::AtomicOperations::exchangeSeqCst(T* addr, T val)
154
{
155
    MOZ_ASSERT(sizeof(T) < 8 || isLockfree8());
156
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
157
    T v;
158
    __sync_synchronize();
159
    do {
160
	v = *addr;
161
    } while (__sync_val_compare_and_swap(addr, v, val) != v);
162
    return v;
163
# else
164
    T v;
165
    __atomic_exchange(addr, &val, &v, __ATOMIC_SEQ_CST);
166
    return v;
167
# endif
168
}
169
170
template<typename T>
171
inline T
172
js::jit::AtomicOperations::loadSafeWhenRacy(T* addr)
173
{
174
    return *addr;               // FIXME (1208663): not yet safe
175
}
176
177
template<typename T>
178
inline void
179
js::jit::AtomicOperations::storeSafeWhenRacy(T* addr, T val)
180
{
181
    *addr = val;                // FIXME (1208663): not yet safe
182
}
183
184
inline void
185
js::jit::AtomicOperations::memcpySafeWhenRacy(void* dest, const void* src, size_t nbytes)
186
{
187
    ::memcpy(dest, src, nbytes); // FIXME (1208663): not yet safe
188
}
189
190
inline void
191
js::jit::AtomicOperations::memmoveSafeWhenRacy(void* dest, const void* src, size_t nbytes)
192
{
193
    ::memmove(dest, src, nbytes); // FIXME (1208663): not yet safe
194
}
195
196
template<size_t nbytes>
197
inline void
198
js::jit::RegionLock::acquire(void* addr)
199
{
200
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
201
    while (!__sync_bool_compare_and_swap(&spinlock, 0, 1))
202
        ;
203
# else
204
    uint32_t zero = 0;
205
    uint32_t one = 1;
206
    while (!__atomic_compare_exchange(&spinlock, &zero, &one, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE)) {
207
        zero = 0;
208
        continue;
209
    }
210
# endif
211
}
212
213
template<size_t nbytes>
214
inline void
215
js::jit::RegionLock::release(void* addr)
216
{
217
    MOZ_ASSERT(AtomicOperations::loadSeqCst(&spinlock) == 1, "releasing unlocked region lock");
218
# ifdef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
219
    __sync_sub_and_fetch(&spinlock, 1);
220
# else
221
    uint32_t zero = 0;
222
    __atomic_store(&spinlock, &zero, __ATOMIC_SEQ_CST);
223
# endif
224
}
225
226
# undef ATOMICS_IMPLEMENTED_WITH_SYNC_INTRINSICS
227
228
#elif defined(ENABLE_SHARED_ARRAY_BUFFER)
229
230
# error "Either disable JS shared memory, use GCC, or add code here"
231
232
#endif
233
234
#endif // jit_ia64_AtomicOperations_ia64_h

Return to bug 576922