author | stefank |
Mon, 25 Nov 2019 12:32:40 +0100 | |
changeset 59251 | 4cbfa5077d68 |
parent 59249 | 29b0d0b61615 |
child 59252 | 623722a6aeb9 |
permissions | -rw-r--r-- |
380 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
380 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
21 |
* questions. |
380 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
25 |
#ifndef OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
26 |
#define OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP |
7397 | 27 |
|
380 | 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::AddAndFetch<Atomic::PlatformAdd<byte_size> > |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
33 |
{ |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
53244
diff
changeset
|
34 |
template<typename D, typename I> |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
53244
diff
changeset
|
35 |
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
|
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<> |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
53244
diff
changeset
|
39 |
template<typename D, typename I> |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
53244
diff
changeset
|
40 |
inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
41 |
atomic_memory_order order) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
42 |
STATIC_ASSERT(4 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
43 |
STATIC_ASSERT(4 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
44 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
45 |
D rv; |
380 | 46 |
__asm__ volatile( |
47 |
"1: \n\t" |
|
48 |
" ld [%2], %%o2\n\t" |
|
49 |
" add %1, %%o2, %%o3\n\t" |
|
50 |
" cas [%2], %%o2, %%o3\n\t" |
|
51 |
" cmp %%o2, %%o3\n\t" |
|
52 |
" bne 1b\n\t" |
|
53 |
" nop\n\t" |
|
54 |
" add %1, %%o2, %0\n\t" |
|
55 |
: "=r" (rv) |
|
56 |
: "r" (add_value), "r" (dest) |
|
57 |
: "memory", "o2", "o3"); |
|
58 |
return rv; |
|
59 |
} |
|
60 |
||
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
61 |
template<> |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
53244
diff
changeset
|
62 |
template<typename D, typename I> |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
53244
diff
changeset
|
63 |
inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I add_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
64 |
atomic_memory_order order) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
65 |
STATIC_ASSERT(8 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
66 |
STATIC_ASSERT(8 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
67 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
68 |
D rv; |
380 | 69 |
__asm__ volatile( |
70 |
"1: \n\t" |
|
71 |
" ldx [%2], %%o2\n\t" |
|
24327 | 72 |
" add %1, %%o2, %%o3\n\t" |
380 | 73 |
" casx [%2], %%o2, %%o3\n\t" |
74 |
" cmp %%o2, %%o3\n\t" |
|
75 |
" bne %%xcc, 1b\n\t" |
|
76 |
" nop\n\t" |
|
24327 | 77 |
" add %1, %%o2, %0\n\t" |
380 | 78 |
: "=r" (rv) |
79 |
: "r" (add_value), "r" (dest) |
|
80 |
: "memory", "o2", "o3"); |
|
81 |
return rv; |
|
82 |
} |
|
83 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
84 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
85 |
template<typename T> |
59251
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
86 |
inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest, |
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
87 |
T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
88 |
atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
89 |
STATIC_ASSERT(4 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
90 |
T rv = exchange_value; |
380 | 91 |
__asm__ volatile( |
92 |
" swap [%2],%1\n\t" |
|
93 |
: "=r" (rv) |
|
94 |
: "0" (exchange_value) /* we use same register as for return value */, "r" (dest) |
|
95 |
: "memory"); |
|
96 |
return rv; |
|
97 |
} |
|
98 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
99 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
100 |
template<typename T> |
59251
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
101 |
inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest, |
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59249
diff
changeset
|
102 |
T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
103 |
atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
104 |
STATIC_ASSERT(8 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
105 |
T rv = exchange_value; |
380 | 106 |
__asm__ volatile( |
107 |
"1:\n\t" |
|
108 |
" mov %1, %%o3\n\t" |
|
109 |
" ldx [%2], %%o2\n\t" |
|
110 |
" casx [%2], %%o2, %%o3\n\t" |
|
111 |
" cmp %%o2, %%o3\n\t" |
|
112 |
" bne %%xcc, 1b\n\t" |
|
113 |
" nop\n\t" |
|
114 |
" mov %%o2, %0\n\t" |
|
115 |
: "=r" (rv) |
|
116 |
: "r" (exchange_value), "r" (dest) |
|
117 |
: "memory", "o2", "o3"); |
|
118 |
return rv; |
|
119 |
} |
|
120 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
121 |
// No direct support for cmpxchg of bytes; emulate using int. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
122 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
123 |
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {}; |
380 | 124 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
125 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
126 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
127 |
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
128 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
129 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
130 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
131 |
STATIC_ASSERT(4 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
132 |
T rv; |
380 | 133 |
__asm__ volatile( |
134 |
" cas [%2], %3, %0" |
|
135 |
: "=r" (rv) |
|
136 |
: "0" (exchange_value), "r" (dest), "r" (compare_value) |
|
137 |
: "memory"); |
|
138 |
return rv; |
|
139 |
} |
|
140 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
141 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
142 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
143 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
144 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
145 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
47593
diff
changeset
|
146 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
147 |
STATIC_ASSERT(8 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
148 |
T rv; |
380 | 149 |
__asm__ volatile( |
150 |
" casx [%2], %3, %0" |
|
151 |
: "=r" (rv) |
|
152 |
: "0" (exchange_value), "r" (dest), "r" (compare_value) |
|
153 |
: "memory"); |
|
154 |
return rv; |
|
155 |
} |
|
156 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
157 |
#endif // OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP |