Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.sparc/src/jdk/vm/ci/sparc/SPARC.java @ 22672:1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Thu, 08 Oct 2015 17:28:41 -0700 |
parents | jvmci/jdk.internal.jvmci.sparc/src/jdk/internal/jvmci/sparc/SPARC.java@111882d99400 |
children | c278790fa252 |
comparison
equal
deleted
inserted
replaced
22671:97f30e4d0e95 | 22672:1bbd4a7c274b |
---|---|
1 /* | |
2 * Copyright (c) 2013, 2015, 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 package jdk.vm.ci.sparc; | |
24 | |
25 import static java.nio.ByteOrder.BIG_ENDIAN; | |
26 import static jdk.vm.ci.code.MemoryBarriers.LOAD_LOAD; | |
27 import static jdk.vm.ci.code.MemoryBarriers.LOAD_STORE; | |
28 import static jdk.vm.ci.code.MemoryBarriers.STORE_STORE; | |
29 | |
30 import java.util.Set; | |
31 | |
32 import jdk.vm.ci.code.Architecture; | |
33 import jdk.vm.ci.code.Register; | |
34 import jdk.vm.ci.code.Register.RegisterCategory; | |
35 import jdk.vm.ci.meta.JavaKind; | |
36 import jdk.vm.ci.meta.PlatformKind; | |
37 | |
38 /** | |
39 * Represents the SPARC architecture. | |
40 */ | |
41 public class SPARC extends Architecture { | |
42 | |
43 public static final RegisterCategory CPU = new RegisterCategory("CPU"); | |
44 | |
45 // General purpose registers | |
46 public static final Register r0 = new Register(0, 0, "g0", CPU); | |
47 public static final Register r1 = new Register(1, 1, "g1", CPU); | |
48 public static final Register r2 = new Register(2, 2, "g2", CPU); | |
49 public static final Register r3 = new Register(3, 3, "g3", CPU); | |
50 public static final Register r4 = new Register(4, 4, "g4", CPU); | |
51 public static final Register r5 = new Register(5, 5, "g5", CPU); | |
52 public static final Register r6 = new Register(6, 6, "g6", CPU); | |
53 public static final Register r7 = new Register(7, 7, "g7", CPU); | |
54 | |
55 public static final Register r8 = new Register(8, 8, "o0", CPU); | |
56 public static final Register r9 = new Register(9, 9, "o1", CPU); | |
57 public static final Register r10 = new Register(10, 10, "o2", CPU); | |
58 public static final Register r11 = new Register(11, 11, "o3", CPU); | |
59 public static final Register r12 = new Register(12, 12, "o4", CPU); | |
60 public static final Register r13 = new Register(13, 13, "o5", CPU); | |
61 public static final Register r14 = new Register(14, 14, "o6", CPU); | |
62 public static final Register r15 = new Register(15, 15, "o7", CPU); | |
63 | |
64 public static final Register r16 = new Register(16, 16, "l0", CPU); | |
65 public static final Register r17 = new Register(17, 17, "l1", CPU); | |
66 public static final Register r18 = new Register(18, 18, "l2", CPU); | |
67 public static final Register r19 = new Register(19, 19, "l3", CPU); | |
68 public static final Register r20 = new Register(20, 20, "l4", CPU); | |
69 public static final Register r21 = new Register(21, 21, "l5", CPU); | |
70 public static final Register r22 = new Register(22, 22, "l6", CPU); | |
71 public static final Register r23 = new Register(23, 23, "l7", CPU); | |
72 | |
73 public static final Register r24 = new Register(24, 24, "i0", CPU); | |
74 public static final Register r25 = new Register(25, 25, "i1", CPU); | |
75 public static final Register r26 = new Register(26, 26, "i2", CPU); | |
76 public static final Register r27 = new Register(27, 27, "i3", CPU); | |
77 public static final Register r28 = new Register(28, 28, "i4", CPU); | |
78 public static final Register r29 = new Register(29, 29, "i5", CPU); | |
79 public static final Register r30 = new Register(30, 30, "i6", CPU); | |
80 public static final Register r31 = new Register(31, 31, "i7", CPU); | |
81 | |
82 public static final Register g0 = r0; | |
83 public static final Register g1 = r1; | |
84 public static final Register g2 = r2; | |
85 public static final Register g3 = r3; | |
86 public static final Register g4 = r4; | |
87 public static final Register g5 = r5; | |
88 public static final Register g6 = r6; | |
89 public static final Register g7 = r7; | |
90 | |
91 public static final Register o0 = r8; | |
92 public static final Register o1 = r9; | |
93 public static final Register o2 = r10; | |
94 public static final Register o3 = r11; | |
95 public static final Register o4 = r12; | |
96 public static final Register o5 = r13; | |
97 public static final Register o6 = r14; | |
98 public static final Register o7 = r15; | |
99 | |
100 public static final Register l0 = r16; | |
101 public static final Register l1 = r17; | |
102 public static final Register l2 = r18; | |
103 public static final Register l3 = r19; | |
104 public static final Register l4 = r20; | |
105 public static final Register l5 = r21; | |
106 public static final Register l6 = r22; | |
107 public static final Register l7 = r23; | |
108 | |
109 public static final Register i0 = r24; | |
110 public static final Register i1 = r25; | |
111 public static final Register i2 = r26; | |
112 public static final Register i3 = r27; | |
113 public static final Register i4 = r28; | |
114 public static final Register i5 = r29; | |
115 public static final Register i6 = r30; | |
116 public static final Register i7 = r31; | |
117 | |
118 public static final Register sp = o6; | |
119 public static final Register fp = i6; | |
120 | |
121 // @formatter:off | |
122 public static final Register[] cpuRegisters = { | |
123 r0, r1, r2, r3, r4, r5, r6, r7, | |
124 r8, r9, r10, r11, r12, r13, r14, r15, | |
125 r16, r17, r18, r19, r20, r21, r22, r23, | |
126 r24, r25, r26, r27, r28, r29, r30, r31 | |
127 }; | |
128 // @formatter:on | |
129 | |
130 public static final RegisterCategory FPUs = new RegisterCategory("FPUs", cpuRegisters.length); | |
131 public static final RegisterCategory FPUd = new RegisterCategory("FPUd", cpuRegisters.length + 32); | |
132 | |
133 // Floating point registers | |
134 public static final Register f0 = new Register(32, 0, "f0", FPUs); | |
135 public static final Register f1 = new Register(33, 1, "f1", FPUs); | |
136 public static final Register f2 = new Register(34, 2, "f2", FPUs); | |
137 public static final Register f3 = new Register(35, 3, "f3", FPUs); | |
138 public static final Register f4 = new Register(36, 4, "f4", FPUs); | |
139 public static final Register f5 = new Register(37, 5, "f5", FPUs); | |
140 public static final Register f6 = new Register(38, 6, "f6", FPUs); | |
141 public static final Register f7 = new Register(39, 7, "f7", FPUs); | |
142 | |
143 public static final Register f8 = new Register(40, 8, "f8", FPUs); | |
144 public static final Register f9 = new Register(41, 9, "f9", FPUs); | |
145 public static final Register f10 = new Register(42, 10, "f10", FPUs); | |
146 public static final Register f11 = new Register(43, 11, "f11", FPUs); | |
147 public static final Register f12 = new Register(44, 12, "f12", FPUs); | |
148 public static final Register f13 = new Register(45, 13, "f13", FPUs); | |
149 public static final Register f14 = new Register(46, 14, "f14", FPUs); | |
150 public static final Register f15 = new Register(47, 15, "f15", FPUs); | |
151 | |
152 public static final Register f16 = new Register(48, 16, "f16", FPUs); | |
153 public static final Register f17 = new Register(49, 17, "f17", FPUs); | |
154 public static final Register f18 = new Register(50, 18, "f18", FPUs); | |
155 public static final Register f19 = new Register(51, 19, "f19", FPUs); | |
156 public static final Register f20 = new Register(52, 20, "f20", FPUs); | |
157 public static final Register f21 = new Register(53, 21, "f21", FPUs); | |
158 public static final Register f22 = new Register(54, 22, "f22", FPUs); | |
159 public static final Register f23 = new Register(55, 23, "f23", FPUs); | |
160 | |
161 public static final Register f24 = new Register(56, 24, "f24", FPUs); | |
162 public static final Register f25 = new Register(57, 25, "f25", FPUs); | |
163 public static final Register f26 = new Register(58, 26, "f26", FPUs); | |
164 public static final Register f27 = new Register(59, 27, "f27", FPUs); | |
165 public static final Register f28 = new Register(60, 28, "f28", FPUs); | |
166 public static final Register f29 = new Register(61, 29, "f29", FPUs); | |
167 public static final Register f30 = new Register(62, 30, "f30", FPUs); | |
168 public static final Register f31 = new Register(63, 31, "f31", FPUs); | |
169 | |
170 public static final Register d0 = new Register(32, getDoubleEncoding(0), "d0", FPUd); | |
171 public static final Register d2 = new Register(34, getDoubleEncoding(2), "d2", FPUd); | |
172 public static final Register d4 = new Register(36, getDoubleEncoding(4), "d4", FPUd); | |
173 public static final Register d6 = new Register(38, getDoubleEncoding(6), "d6", FPUd); | |
174 public static final Register d8 = new Register(40, getDoubleEncoding(8), "d8", FPUd); | |
175 public static final Register d10 = new Register(42, getDoubleEncoding(10), "d10", FPUd); | |
176 public static final Register d12 = new Register(44, getDoubleEncoding(12), "d12", FPUd); | |
177 public static final Register d14 = new Register(46, getDoubleEncoding(14), "d14", FPUd); | |
178 | |
179 public static final Register d16 = new Register(48, getDoubleEncoding(16), "d16", FPUd); | |
180 public static final Register d18 = new Register(50, getDoubleEncoding(18), "d18", FPUd); | |
181 public static final Register d20 = new Register(52, getDoubleEncoding(20), "d20", FPUd); | |
182 public static final Register d22 = new Register(54, getDoubleEncoding(22), "d22", FPUd); | |
183 public static final Register d24 = new Register(56, getDoubleEncoding(24), "d24", FPUd); | |
184 public static final Register d26 = new Register(58, getDoubleEncoding(26), "d26", FPUd); | |
185 public static final Register d28 = new Register(60, getDoubleEncoding(28), "d28", FPUd); | |
186 public static final Register d30 = new Register(62, getDoubleEncoding(28), "d28", FPUd); | |
187 | |
188 public static final Register d32 = new Register(64, getDoubleEncoding(32), "d32", FPUd); | |
189 public static final Register d34 = new Register(65, getDoubleEncoding(34), "d34", FPUd); | |
190 public static final Register d36 = new Register(66, getDoubleEncoding(36), "d36", FPUd); | |
191 public static final Register d38 = new Register(67, getDoubleEncoding(38), "d38", FPUd); | |
192 public static final Register d40 = new Register(68, getDoubleEncoding(40), "d40", FPUd); | |
193 public static final Register d42 = new Register(69, getDoubleEncoding(42), "d42", FPUd); | |
194 public static final Register d44 = new Register(70, getDoubleEncoding(44), "d44", FPUd); | |
195 public static final Register d46 = new Register(71, getDoubleEncoding(46), "d46", FPUd); | |
196 | |
197 public static final Register d48 = new Register(72, getDoubleEncoding(48), "d48", FPUd); | |
198 public static final Register d50 = new Register(73, getDoubleEncoding(50), "d50", FPUd); | |
199 public static final Register d52 = new Register(74, getDoubleEncoding(52), "d52", FPUd); | |
200 public static final Register d54 = new Register(75, getDoubleEncoding(54), "d54", FPUd); | |
201 public static final Register d56 = new Register(76, getDoubleEncoding(56), "d56", FPUd); | |
202 public static final Register d58 = new Register(77, getDoubleEncoding(58), "d58", FPUd); | |
203 public static final Register d60 = new Register(78, getDoubleEncoding(60), "d60", FPUd); | |
204 public static final Register d62 = new Register(79, getDoubleEncoding(62), "d62", FPUd); | |
205 | |
206 // @formatter:off | |
207 public static final Register[] fpuRegisters = { | |
208 f0, f1, f2, f3, f4, f5, f6, f7, | |
209 f8, f9, f10, f11, f12, f13, f14, f15, | |
210 f16, f17, f18, f19, f20, f21, f22, f23, | |
211 f24, f25, f26, f27, f28, f29, f30, f31, | |
212 d32, d34, d36, d38, d40, d42, d44, d46, | |
213 d48, d50, d52, d54, d56, d58, d60, d62 | |
214 }; | |
215 // @formatter:on | |
216 | |
217 // @formatter:off | |
218 public static final Register[] allRegisters = { | |
219 // CPU | |
220 r0, r1, r2, r3, r4, r5, r6, r7, | |
221 r8, r9, r10, r11, r12, r13, r14, r15, | |
222 r16, r17, r18, r19, r20, r21, r22, r23, | |
223 r24, r25, r26, r27, r28, r29, r30, r31, | |
224 // FPU | |
225 f0, f1, f2, f3, f4, f5, f6, f7, | |
226 f8, f9, f10, f11, f12, f13, f14, f15, | |
227 f16, f17, f18, f19, f20, f21, f22, f23, | |
228 f24, f25, f26, f27, f28, f29, f30, f31, | |
229 d32, d34, d36, d38, d40, d42, d44, d46, | |
230 d48, d50, d52, d54, d56, d58, d60, d62 | |
231 }; | |
232 // @formatter:on | |
233 | |
234 /** | |
235 * Stack bias for stack and frame pointer loads. | |
236 */ | |
237 public static final int STACK_BIAS = 0x7ff; | |
238 /** | |
239 * In fact there are 64 single floating point registers, 32 of them could be accessed. TODO: | |
240 * Improve handling of these float registers | |
241 */ | |
242 public static final int FLOAT_REGISTER_COUNT = 64; | |
243 | |
244 /** | |
245 * Alignment for valid memory access. | |
246 */ | |
247 public static final int MEMORY_ACCESS_ALIGN = 4; | |
248 | |
249 public static final int INSTRUCTION_SIZE = 4; | |
250 | |
251 /** | |
252 * Size to keep free for flushing the register-window to stack. | |
253 */ | |
254 public static final int REGISTER_SAFE_AREA_SIZE = 128; | |
255 | |
256 public static final int BLOCK_ZERO_LENGTH = 64; | |
257 | |
258 public final Set<CPUFeature> features; | |
259 | |
260 public SPARC(Set<CPUFeature> features) { | |
261 super("SPARC", SPARCKind.DWORD, BIG_ENDIAN, false, allRegisters, LOAD_LOAD | LOAD_STORE | STORE_STORE, 1, r31.encoding + FLOAT_REGISTER_COUNT + 1, 8); | |
262 this.features = features; | |
263 } | |
264 | |
265 @Override | |
266 public boolean canStoreValue(RegisterCategory category, PlatformKind kind) { | |
267 SPARCKind sparcKind = (SPARCKind) kind; | |
268 switch (sparcKind) { | |
269 case BYTE: | |
270 case HWORD: | |
271 case WORD: | |
272 case DWORD: | |
273 return SPARC.CPU.equals(category); | |
274 case SINGLE: | |
275 case V32_BYTE: | |
276 case V32_HWORD: | |
277 return SPARC.FPUs.equals(category); | |
278 case DOUBLE: | |
279 case V64_BYTE: | |
280 case V64_HWORD: | |
281 case V64_WORD: | |
282 case V64_SINGLE: | |
283 return SPARC.FPUd.equals(category); | |
284 default: | |
285 return false; | |
286 } | |
287 } | |
288 | |
289 @Override | |
290 public PlatformKind getLargestStorableKind(RegisterCategory category) { | |
291 if (category.equals(CPU)) { | |
292 return SPARCKind.DWORD; | |
293 } else if (category.equals(FPUd)) { | |
294 return SPARCKind.DOUBLE; | |
295 } else if (category.equals(FPUs)) { | |
296 return SPARCKind.SINGLE; | |
297 } else { | |
298 throw new IllegalArgumentException("Unknown register category: " + category); | |
299 } | |
300 } | |
301 | |
302 @Override | |
303 public PlatformKind getPlatformKind(JavaKind javaKind) { | |
304 switch (javaKind) { | |
305 case Boolean: | |
306 case Byte: | |
307 return SPARCKind.BYTE; | |
308 case Short: | |
309 case Char: | |
310 return SPARCKind.HWORD; | |
311 case Int: | |
312 return SPARCKind.WORD; | |
313 case Long: | |
314 case Object: | |
315 return SPARCKind.DWORD; | |
316 case Float: | |
317 return SPARCKind.SINGLE; | |
318 case Double: | |
319 return SPARCKind.DOUBLE; | |
320 default: | |
321 throw new IllegalArgumentException("Unknown JavaKind: " + javaKind); | |
322 } | |
323 } | |
324 | |
325 public static int getDoubleEncoding(int reg) { | |
326 assert reg < 64 && ((reg & 1) == 0); | |
327 // ignore v8 assertion for now | |
328 return (reg & 0x1e) | ((reg & 0x20) >> 5); | |
329 } | |
330 | |
331 public static boolean isCPURegister(Register r) { | |
332 return r.getRegisterCategory().equals(CPU); | |
333 } | |
334 | |
335 public static boolean isCPURegister(Register... regs) { | |
336 for (Register reg : regs) { | |
337 if (!isCPURegister(reg)) { | |
338 return false; | |
339 } | |
340 } | |
341 return true; | |
342 } | |
343 | |
344 public static boolean isGlobalRegister(Register r) { | |
345 return isCPURegister(r) && g0.number <= r.number && r.number <= g7.number; | |
346 } | |
347 | |
348 public static boolean isSingleFloatRegister(Register r) { | |
349 return r.name.startsWith("f"); | |
350 } | |
351 | |
352 public static boolean isDoubleFloatRegister(Register r) { | |
353 return r.name.startsWith("d"); | |
354 } | |
355 | |
356 public Set<CPUFeature> getFeatures() { | |
357 return features; | |
358 } | |
359 | |
360 public boolean hasFeature(CPUFeature feature) { | |
361 return features.contains(feature); | |
362 } | |
363 | |
364 public enum CPUFeature { | |
365 VIS1, | |
366 VIS2, | |
367 VIS3, | |
368 CBCOND, | |
369 BLOCK_ZEROING | |
370 } | |
371 } |