Tue, 08 Aug 2017 15:57:29 +0800
merge
1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
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 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_ASM_REGISTER_HPP
32 #define SHARE_VM_ASM_REGISTER_HPP
34 #include "utilities/top.hpp"
36 // Use AbstractRegister as shortcut
37 class AbstractRegisterImpl;
38 typedef AbstractRegisterImpl* AbstractRegister;
41 // The super class for platform specific registers. Instead of using value objects,
42 // registers are implemented as pointers. Subclassing is used so all registers can
43 // use the debugging suport below. No virtual functions are used for efficiency.
44 // They are canonicalized; i.e., registers are equal if their pointers are equal,
45 // and vice versa. A concrete implementation may just map the register onto 'this'.
47 class AbstractRegisterImpl {
48 protected:
49 int value() const { return (int)(intx)this; }
50 };
53 //
54 // Macros for use in defining Register instances. We'd like to be
55 // able to simply define const instances of the RegisterImpl* for each
56 // of the registers needed on a system in a header file. However many
57 // compilers don't handle this very well and end up producing a
58 // private definition in every file which includes the header file.
59 // Along with the static constructors necessary for initialization it
60 // can consume a significant amount of space in the result library.
61 //
62 // The following macros allow us to declare the instance in a .hpp and
63 // produce an enumeration value which has the same number. Then in a
64 // .cpp the the register instance can be defined using the enumeration
65 // value. This avoids the use of static constructors and multiple
66 // definitions per .cpp. In addition #defines for the register can be
67 // produced so that the constant registers can be inlined. These
68 // macros should not be used inside other macros, because you may get
69 // multiple evaluations of the macros which can give bad results.
70 //
71 // Here are some example uses and expansions. Note that the macro
72 // invocation is terminated with a ;.
73 //
74 // CONSTANT_REGISTER_DECLARATION(Register, G0, 0);
75 //
76 // extern const Register G0 ;
77 // enum { G0_RegisterEnumValue = 0 } ;
78 //
79 // REGISTER_DECLARATION(Register, Gmethod, G5);
80 //
81 // extern const Register Gmethod ;
82 // enum { Gmethod_RegisterEnumValue = G5_RegisterEnumValue } ;
83 //
84 // REGISTER_DEFINITION(Register, G0);
85 //
86 // const Register G0 = ( ( Register ) G0_RegisterEnumValue ) ;
87 //
89 #define AS_REGISTER(type,name) ((type)name##_##type##EnumValue)
91 #define CONSTANT_REGISTER_DECLARATION(type, name, value) \
92 extern const type name; \
93 enum { name##_##type##EnumValue = (value) }
95 #define REGISTER_DECLARATION(type, name, value) \
96 extern const type name; \
97 enum { name##_##type##EnumValue = value##_##type##EnumValue }
99 #define REGISTER_DEFINITION(type, name) \
100 const type name = ((type)name##_##type##EnumValue)
102 #ifdef TARGET_ARCH_x86
103 # include "register_x86.hpp"
104 #endif
105 #ifdef TARGET_ARCH_sparc
106 # include "register_sparc.hpp"
107 #endif
108 #ifdef TARGET_ARCH_zero
109 # include "register_zero.hpp"
110 #endif
111 #ifdef TARGET_ARCH_arm
112 # include "register_arm.hpp"
113 #endif
114 #ifdef TARGET_ARCH_ppc
115 # include "register_ppc.hpp"
116 #endif
117 #ifdef TARGET_ARCH_mips
118 # include "register_mips.hpp"
119 #endif
122 // Debugging support
124 inline void assert_different_registers(
125 AbstractRegister a,
126 AbstractRegister b
127 ) {
128 assert(
129 a != b,
130 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT "",
131 p2i(a), p2i(b))
132 );
133 }
136 inline void assert_different_registers(
137 AbstractRegister a,
138 AbstractRegister b,
139 AbstractRegister c
140 ) {
141 assert(
142 a != b && a != c
143 && b != c,
144 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
145 ", c=" INTPTR_FORMAT "",
146 p2i(a), p2i(b), p2i(c))
147 );
148 }
151 inline void assert_different_registers(
152 AbstractRegister a,
153 AbstractRegister b,
154 AbstractRegister c,
155 AbstractRegister d
156 ) {
157 assert(
158 a != b && a != c && a != d
159 && b != c && b != d
160 && c != d,
161 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
162 ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT "",
163 p2i(a), p2i(b), p2i(c), p2i(d))
164 );
165 }
168 inline void assert_different_registers(
169 AbstractRegister a,
170 AbstractRegister b,
171 AbstractRegister c,
172 AbstractRegister d,
173 AbstractRegister e
174 ) {
175 assert(
176 a != b && a != c && a != d && a != e
177 && b != c && b != d && b != e
178 && c != d && c != e
179 && d != e,
180 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
181 ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT "",
182 p2i(a), p2i(b), p2i(c), p2i(d), p2i(e))
183 );
184 }
187 inline void assert_different_registers(
188 AbstractRegister a,
189 AbstractRegister b,
190 AbstractRegister c,
191 AbstractRegister d,
192 AbstractRegister e,
193 AbstractRegister f
194 ) {
195 assert(
196 a != b && a != c && a != d && a != e && a != f
197 && b != c && b != d && b != e && b != f
198 && c != d && c != e && c != f
199 && d != e && d != f
200 && e != f,
201 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
202 ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT
203 ", f=" INTPTR_FORMAT "",
204 p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f))
205 );
206 }
209 inline void assert_different_registers(
210 AbstractRegister a,
211 AbstractRegister b,
212 AbstractRegister c,
213 AbstractRegister d,
214 AbstractRegister e,
215 AbstractRegister f,
216 AbstractRegister g
217 ) {
218 assert(
219 a != b && a != c && a != d && a != e && a != f && a != g
220 && b != c && b != d && b != e && b != f && b != g
221 && c != d && c != e && c != f && c != g
222 && d != e && d != f && d != g
223 && e != f && e != g
224 && f != g,
225 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
226 ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT
227 ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT "",
228 p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g))
229 );
230 }
233 inline void assert_different_registers(
234 AbstractRegister a,
235 AbstractRegister b,
236 AbstractRegister c,
237 AbstractRegister d,
238 AbstractRegister e,
239 AbstractRegister f,
240 AbstractRegister g,
241 AbstractRegister h
242 ) {
243 assert(
244 a != b && a != c && a != d && a != e && a != f && a != g && a != h
245 && b != c && b != d && b != e && b != f && b != g && b != h
246 && c != d && c != e && c != f && c != g && c != h
247 && d != e && d != f && d != g && d != h
248 && e != f && e != g && e != h
249 && f != g && f != h
250 && g != h,
251 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
252 ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT
253 ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT ", h=" INTPTR_FORMAT "",
254 p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g), p2i(h))
255 );
256 }
259 inline void assert_different_registers(
260 AbstractRegister a,
261 AbstractRegister b,
262 AbstractRegister c,
263 AbstractRegister d,
264 AbstractRegister e,
265 AbstractRegister f,
266 AbstractRegister g,
267 AbstractRegister h,
268 AbstractRegister i
269 ) {
270 assert(
271 a != b && a != c && a != d && a != e && a != f && a != g && a != h && a != i
272 && b != c && b != d && b != e && b != f && b != g && b != h && b != i
273 && c != d && c != e && c != f && c != g && c != h && c != i
274 && d != e && d != f && d != g && d != h && d != i
275 && e != f && e != g && e != h && e != i
276 && f != g && f != h && f != i
277 && g != h && g != i
278 && h != i,
279 err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT
280 ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT
281 ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT ", h=" INTPTR_FORMAT
282 ", i=" INTPTR_FORMAT "",
283 p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g), p2i(h), p2i(i))
284 );
285 }
287 #endif // SHARE_VM_ASM_REGISTER_HPP