author | ihse |
Fri, 02 Mar 2018 19:10:12 +0100 | |
branch | ihse-warnings-cflags-branch |
changeset 56229 | 0015bf3a82e0 |
parent 47593 | 2d56326b98f0 |
child 50029 | ea0a16ba6ac0 |
permissions | -rw-r--r-- |
380 | 1 |
/* |
46523
cbcc0ebaa044
8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents:
46381
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, 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 |
||
7397 | 25 |
#ifndef OS_CPU_LINUX_SPARC_VM_ATOMIC_LINUX_SPARC_INLINE_HPP |
26 |
#define OS_CPU_LINUX_SPARC_VM_ATOMIC_LINUX_SPARC_INLINE_HPP |
|
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 |
{ |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
34 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
35 |
D add_and_fetch(I add_value, D volatile* dest) const; |
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> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
40 |
inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
41 |
STATIC_ASSERT(4 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
42 |
STATIC_ASSERT(4 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
43 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
44 |
D rv; |
380 | 45 |
__asm__ volatile( |
46 |
"1: \n\t" |
|
47 |
" ld [%2], %%o2\n\t" |
|
48 |
" add %1, %%o2, %%o3\n\t" |
|
49 |
" cas [%2], %%o2, %%o3\n\t" |
|
50 |
" cmp %%o2, %%o3\n\t" |
|
51 |
" bne 1b\n\t" |
|
52 |
" nop\n\t" |
|
53 |
" add %1, %%o2, %0\n\t" |
|
54 |
: "=r" (rv) |
|
55 |
: "r" (add_value), "r" (dest) |
|
56 |
: "memory", "o2", "o3"); |
|
57 |
return rv; |
|
58 |
} |
|
59 |
||
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
60 |
template<> |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
61 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
62 |
inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
63 |
STATIC_ASSERT(8 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
64 |
STATIC_ASSERT(8 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
65 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
66 |
D rv; |
380 | 67 |
__asm__ volatile( |
68 |
"1: \n\t" |
|
69 |
" ldx [%2], %%o2\n\t" |
|
24327 | 70 |
" add %1, %%o2, %%o3\n\t" |
380 | 71 |
" casx [%2], %%o2, %%o3\n\t" |
72 |
" cmp %%o2, %%o3\n\t" |
|
73 |
" bne %%xcc, 1b\n\t" |
|
74 |
" nop\n\t" |
|
24327 | 75 |
" add %1, %%o2, %0\n\t" |
380 | 76 |
: "=r" (rv) |
77 |
: "r" (add_value), "r" (dest) |
|
78 |
: "memory", "o2", "o3"); |
|
79 |
return rv; |
|
80 |
} |
|
81 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
82 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
83 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
84 |
inline T Atomic::PlatformXchg<4>::operator()(T exchange_value, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
85 |
T volatile* dest) const { |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
86 |
STATIC_ASSERT(4 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
87 |
T rv = exchange_value; |
380 | 88 |
__asm__ volatile( |
89 |
" swap [%2],%1\n\t" |
|
90 |
: "=r" (rv) |
|
91 |
: "0" (exchange_value) /* we use same register as for return value */, "r" (dest) |
|
92 |
: "memory"); |
|
93 |
return rv; |
|
94 |
} |
|
95 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
96 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
97 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
98 |
inline T Atomic::PlatformXchg<8>::operator()(T exchange_value, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
99 |
T volatile* dest) const { |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
100 |
STATIC_ASSERT(8 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
101 |
T rv = exchange_value; |
380 | 102 |
__asm__ volatile( |
103 |
"1:\n\t" |
|
104 |
" mov %1, %%o3\n\t" |
|
105 |
" ldx [%2], %%o2\n\t" |
|
106 |
" casx [%2], %%o2, %%o3\n\t" |
|
107 |
" cmp %%o2, %%o3\n\t" |
|
108 |
" bne %%xcc, 1b\n\t" |
|
109 |
" nop\n\t" |
|
110 |
" mov %%o2, %0\n\t" |
|
111 |
: "=r" (rv) |
|
112 |
: "r" (exchange_value), "r" (dest) |
|
113 |
: "memory", "o2", "o3"); |
|
114 |
return rv; |
|
115 |
} |
|
116 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
117 |
// No direct support for cmpxchg of bytes; emulate using int. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
118 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
119 |
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {}; |
380 | 120 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
121 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
122 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
123 |
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
124 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
125 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
126 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
127 |
STATIC_ASSERT(4 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
128 |
T rv; |
380 | 129 |
__asm__ volatile( |
130 |
" cas [%2], %3, %0" |
|
131 |
: "=r" (rv) |
|
132 |
: "0" (exchange_value), "r" (dest), "r" (compare_value) |
|
133 |
: "memory"); |
|
134 |
return rv; |
|
135 |
} |
|
136 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
137 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
138 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
139 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
140 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
141 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
142 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
143 |
STATIC_ASSERT(8 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46668
diff
changeset
|
144 |
T rv; |
380 | 145 |
__asm__ volatile( |
146 |
" casx [%2], %3, %0" |
|
147 |
: "=r" (rv) |
|
148 |
: "0" (exchange_value), "r" (dest), "r" (compare_value) |
|
149 |
: "memory"); |
|
150 |
return rv; |
|
151 |
} |
|
152 |
||
7397 | 153 |
#endif // OS_CPU_LINUX_SPARC_VM_ATOMIC_LINUX_SPARC_INLINE_HPP |