author | darcy |
Tue, 12 Nov 2019 10:45:23 -0800 | |
changeset 59037 | 3d2575331a41 |
parent 53244 | 9807daeb47c4 |
child 59247 | 56bf71d64d51 |
permissions | -rw-r--r-- |
10565 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51996
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
10565 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51996
diff
changeset
|
25 |
#ifndef OS_CPU_BSD_X86_ATOMIC_BSD_X86_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51996
diff
changeset
|
26 |
#define OS_CPU_BSD_X86_ATOMIC_BSD_X86_HPP |
10565 | 27 |
|
28 |
// Implementation of class atomic |
|
29 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
30 |
template<size_t byte_size> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
31 |
struct Atomic::PlatformAdd |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
32 |
: Atomic::FetchAndAdd<Atomic::PlatformAdd<byte_size> > |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
33 |
{ |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
34 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
35 |
D fetch_and_add(I add_value, D volatile* dest, atomic_memory_order /* order */) const; |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
36 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
37 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
38 |
template<> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
39 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
40 |
inline D Atomic::PlatformAdd<4>::fetch_and_add(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
41 |
atomic_memory_order /* order */) const { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
42 |
STATIC_ASSERT(4 == sizeof(I)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
43 |
STATIC_ASSERT(4 == sizeof(D)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
44 |
D old_value; |
46414 | 45 |
__asm__ volatile ( "lock xaddl %0,(%2)" |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
46 |
: "=r" (old_value) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
47 |
: "0" (add_value), "r" (dest) |
10565 | 48 |
: "cc", "memory"); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
49 |
return old_value; |
10565 | 50 |
} |
51 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
52 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
53 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
54 |
inline T Atomic::PlatformXchg<4>::operator()(T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
55 |
T volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
56 |
atomic_memory_order /* order */) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
57 |
STATIC_ASSERT(4 == sizeof(T)); |
10565 | 58 |
__asm__ volatile ( "xchgl (%2),%0" |
59 |
: "=r" (exchange_value) |
|
60 |
: "0" (exchange_value), "r" (dest) |
|
61 |
: "memory"); |
|
62 |
return exchange_value; |
|
63 |
} |
|
64 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
65 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
66 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
67 |
inline T Atomic::PlatformCmpxchg<1>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
68 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
69 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
70 |
atomic_memory_order /* order */) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
71 |
STATIC_ASSERT(1 == sizeof(T)); |
46414 | 72 |
__asm__ volatile ( "lock cmpxchgb %1,(%3)" |
27691
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
73 |
: "=a" (exchange_value) |
46414 | 74 |
: "q" (exchange_value), "a" (compare_value), "r" (dest) |
27691
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
75 |
: "cc", "memory"); |
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
76 |
return exchange_value; |
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
77 |
} |
10565 | 78 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
79 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
80 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
81 |
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
82 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
83 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
84 |
atomic_memory_order /* order */) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
85 |
STATIC_ASSERT(4 == sizeof(T)); |
46414 | 86 |
__asm__ volatile ( "lock cmpxchgl %1,(%3)" |
10565 | 87 |
: "=a" (exchange_value) |
46414 | 88 |
: "r" (exchange_value), "a" (compare_value), "r" (dest) |
10565 | 89 |
: "cc", "memory"); |
90 |
return exchange_value; |
|
91 |
} |
|
92 |
||
93 |
#ifdef AMD64 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
94 |
template<> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
95 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
96 |
inline D Atomic::PlatformAdd<8>::fetch_and_add(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
97 |
atomic_memory_order /* order */) const { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
98 |
STATIC_ASSERT(8 == sizeof(I)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
99 |
STATIC_ASSERT(8 == sizeof(D)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
100 |
D old_value; |
46414 | 101 |
__asm__ __volatile__ ( "lock xaddq %0,(%2)" |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
102 |
: "=r" (old_value) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
103 |
: "0" (add_value), "r" (dest) |
10565 | 104 |
: "cc", "memory"); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
105 |
return old_value; |
10565 | 106 |
} |
107 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
108 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
109 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
110 |
inline T Atomic::PlatformXchg<8>::operator()(T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
111 |
T volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
112 |
atomic_memory_order /* order */) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
113 |
STATIC_ASSERT(8 == sizeof(T)); |
10565 | 114 |
__asm__ __volatile__ ("xchgq (%2),%0" |
115 |
: "=r" (exchange_value) |
|
116 |
: "0" (exchange_value), "r" (dest) |
|
117 |
: "memory"); |
|
118 |
return exchange_value; |
|
119 |
} |
|
120 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
121 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
122 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
123 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
124 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
125 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
126 |
atomic_memory_order /* order */) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
127 |
STATIC_ASSERT(8 == sizeof(T)); |
46414 | 128 |
__asm__ __volatile__ ( "lock cmpxchgq %1,(%3)" |
10565 | 129 |
: "=a" (exchange_value) |
46414 | 130 |
: "r" (exchange_value), "a" (compare_value), "r" (dest) |
10565 | 131 |
: "cc", "memory"); |
132 |
return exchange_value; |
|
133 |
} |
|
134 |
||
135 |
#else // !AMD64 |
|
136 |
||
137 |
extern "C" { |
|
138 |
// defined in bsd_x86.s |
|
51996
84743156e780
8188764: Obsolete AssumeMP and then remove all support for non-MP builds
dholmes
parents:
50029
diff
changeset
|
139 |
int64_t _Atomic_cmpxchg_long(int64_t, volatile int64_t*, int64_t); |
48468 | 140 |
void _Atomic_move_long(const volatile int64_t* src, volatile int64_t* dst); |
10565 | 141 |
} |
142 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
143 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
144 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
145 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
146 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
147 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48468
diff
changeset
|
148 |
atomic_memory_order /* order */) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
149 |
STATIC_ASSERT(8 == sizeof(T)); |
48468 | 150 |
return cmpxchg_using_helper<int64_t>(_Atomic_cmpxchg_long, exchange_value, dest, compare_value); |
10565 | 151 |
} |
152 |
||
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
153 |
template<> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
154 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
155 |
inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
156 |
STATIC_ASSERT(8 == sizeof(T)); |
48468 | 157 |
volatile int64_t dest; |
158 |
_Atomic_move_long(reinterpret_cast<const volatile int64_t*>(src), reinterpret_cast<volatile int64_t*>(&dest)); |
|
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
159 |
return PrimitiveConversions::cast<T>(dest); |
10565 | 160 |
} |
161 |
||
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
162 |
template<> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
163 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
164 |
inline void Atomic::PlatformStore<8>::operator()(T store_value, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
165 |
T volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
166 |
STATIC_ASSERT(8 == sizeof(T)); |
48468 | 167 |
_Atomic_move_long(reinterpret_cast<const volatile int64_t*>(&store_value), reinterpret_cast<volatile int64_t*>(dest)); |
10565 | 168 |
} |
169 |
||
170 |
#endif // AMD64 |
|
171 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51996
diff
changeset
|
172 |
#endif // OS_CPU_BSD_X86_ATOMIC_BSD_X86_HPP |