1 /* |
|
2 * Copyright (c) 2015, 2016, 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 |
|
24 package compiler.jvmci.code.sparc; |
|
25 |
|
26 import jdk.vm.ci.code.CodeCacheProvider; |
|
27 import jdk.vm.ci.code.DebugInfo; |
|
28 import jdk.vm.ci.code.Register; |
|
29 import jdk.vm.ci.code.StackSlot; |
|
30 import jdk.vm.ci.code.site.ConstantReference; |
|
31 import jdk.vm.ci.code.site.DataSectionReference; |
|
32 import jdk.vm.ci.hotspot.HotSpotCallingConventionType; |
|
33 import jdk.vm.ci.hotspot.HotSpotCompiledCode; |
|
34 import jdk.vm.ci.hotspot.HotSpotConstant; |
|
35 import jdk.vm.ci.hotspot.HotSpotForeignCallTarget; |
|
36 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
|
37 import jdk.vm.ci.hotspot.HotSpotVMConfig; |
|
38 import jdk.vm.ci.meta.JavaKind; |
|
39 import jdk.vm.ci.meta.LIRKind; |
|
40 import jdk.vm.ci.meta.VMConstant; |
|
41 import jdk.vm.ci.sparc.SPARC; |
|
42 import jdk.vm.ci.sparc.SPARCKind; |
|
43 |
|
44 import compiler.jvmci.code.TestAssembler; |
|
45 |
|
46 public class SPARCTestAssembler extends TestAssembler { |
|
47 |
|
48 private static final int MASK13 = (1 << 13) - 1; |
|
49 |
|
50 public SPARCTestAssembler(CodeCacheProvider codeCache) { |
|
51 super(codeCache, 0, 16, SPARCKind.WORD, SPARC.l0, SPARC.l1, SPARC.l2, SPARC.l3, SPARC.l4, SPARC.l5, SPARC.l6, SPARC.l7); |
|
52 } |
|
53 |
|
54 private void emitOp2(Register rd, int op2, int imm22) { |
|
55 code.emitInt((0b00 << 30) | (rd.encoding << 25) | (op2 << 22) | imm22); |
|
56 } |
|
57 |
|
58 private void emitOp3(int op, Register rd, int op3, Register rs1, Register rs2) { |
|
59 code.emitInt((op << 30) | (rd.encoding << 25) | (op3 << 19) | (rs1.encoding << 14) | rs2.encoding); |
|
60 } |
|
61 |
|
62 private void emitOp3(int op, Register rd, int op3, Register rs1, int simm13) { |
|
63 code.emitInt((op << 30) | (rd.encoding << 25) | (op3 << 19) | (rs1.encoding << 14) | (1 << 13) | (simm13 & MASK13)); |
|
64 } |
|
65 |
|
66 private void emitNop() { |
|
67 code.emitInt(1 << 24); |
|
68 } |
|
69 |
|
70 @Override |
|
71 public void emitPrologue() { |
|
72 emitOp3(0b10, SPARC.sp, 0b111100, SPARC.sp, -SPARC.REGISTER_SAFE_AREA_SIZE); // SAVE sp, -128, sp |
|
73 setDeoptRescueSlot(newStackSlot(LIRKind.value(SPARCKind.XWORD))); |
|
74 } |
|
75 |
|
76 @Override |
|
77 public void emitEpilogue() { |
|
78 HotSpotVMConfig config = HotSpotVMConfig.config(); |
|
79 recordMark(config.MARKID_DEOPT_HANDLER_ENTRY); |
|
80 recordCall(new HotSpotForeignCallTarget(config.handleDeoptStub), 4, true, null); |
|
81 code.emitInt(1 << 30); // CALL |
|
82 } |
|
83 |
|
84 @Override |
|
85 public HotSpotCompiledCode finish(HotSpotResolvedJavaMethod method) { |
|
86 frameSize += SPARC.REGISTER_SAFE_AREA_SIZE; |
|
87 return super.finish(method); |
|
88 } |
|
89 |
|
90 @Override |
|
91 public void emitGrowStack(int size) { |
|
92 emitOp3(0b10, SPARC.sp, 0b000100, SPARC.sp, size); // SUB sp, size, sp |
|
93 } |
|
94 |
|
95 @Override |
|
96 public Register emitIntArg0() { |
|
97 return codeCache.getRegisterConfig().getCallingConventionRegisters(HotSpotCallingConventionType.JavaCallee, JavaKind.Int)[0]; |
|
98 } |
|
99 |
|
100 @Override |
|
101 public Register emitIntArg1() { |
|
102 return codeCache.getRegisterConfig().getCallingConventionRegisters(HotSpotCallingConventionType.JavaCallee, JavaKind.Int)[1]; |
|
103 } |
|
104 |
|
105 @Override |
|
106 public Register emitLoadInt(int c) { |
|
107 Register ret = newRegister(); |
|
108 int hi = c >>> 10; |
|
109 int lo = c & ((1 << 10) - 1); |
|
110 if (hi == 0) { |
|
111 emitOp3(0b10, ret, 0b000010, SPARC.g0, lo); // OR g0, lo, ret |
|
112 } else { |
|
113 emitOp2(ret, 0b100, hi); // SETHI hi, ret |
|
114 if (lo != 0) { |
|
115 emitOp3(0b10, ret, 0b000010, ret, lo); // OR ret, lo, ret |
|
116 } |
|
117 } |
|
118 return ret; |
|
119 } |
|
120 |
|
121 @Override |
|
122 public Register emitLoadLong(long c) { |
|
123 if ((c & 0xFFFF_FFFFL) == c) { |
|
124 return emitLoadInt((int) c); |
|
125 } else { |
|
126 DataSectionReference ref = new DataSectionReference(); |
|
127 data.align(8); |
|
128 ref.setOffset(data.position()); |
|
129 data.emitLong(c); |
|
130 return emitLoadPointer(ref); |
|
131 } |
|
132 } |
|
133 |
|
134 private void emitPatchableSethi(Register ret, boolean wide) { |
|
135 int startPos = code.position(); |
|
136 emitOp2(ret, 0b100, 0); // SETHI 0, ret |
|
137 if (wide) { |
|
138 // pad for later patching |
|
139 while (code.position() < (startPos + 28)) { |
|
140 emitNop(); |
|
141 } |
|
142 } |
|
143 } |
|
144 |
|
145 @Override |
|
146 public Register emitLoadFloat(float c) { |
|
147 DataSectionReference ref = new DataSectionReference(); |
|
148 data.align(4); |
|
149 ref.setOffset(data.position()); |
|
150 data.emitFloat(c); |
|
151 |
|
152 Register ptr = newRegister(); |
|
153 recordDataPatchInCode(ref); |
|
154 emitPatchableSethi(ptr, true); |
|
155 emitOp3(0b11, SPARC.f0, 0b100000, ptr, 0); // LDF [ptr+0], f0 |
|
156 return SPARC.f0; |
|
157 } |
|
158 |
|
159 @Override |
|
160 public Register emitLoadPointer(HotSpotConstant c) { |
|
161 Register ret = newRegister(); |
|
162 recordDataPatchInCode(new ConstantReference((VMConstant) c)); |
|
163 |
|
164 emitPatchableSethi(ret, !c.isCompressed()); |
|
165 emitOp3(0b10, ret, 0b000010, ret, 0); // OR ret, 0, ret |
|
166 |
|
167 return ret; |
|
168 } |
|
169 |
|
170 @Override |
|
171 public Register emitLoadPointer(DataSectionReference ref) { |
|
172 Register ret = newRegister(); |
|
173 recordDataPatchInCode(ref); |
|
174 emitPatchableSethi(ret, true); |
|
175 emitOp3(0b11, ret, 0b001011, ret, 0); // LDX [ret+0], ret |
|
176 return ret; |
|
177 } |
|
178 |
|
179 @Override |
|
180 public Register emitLoadNarrowPointer(DataSectionReference ref) { |
|
181 Register ret = newRegister(); |
|
182 recordDataPatchInCode(ref); |
|
183 emitPatchableSethi(ret, true); |
|
184 emitOp3(0b11, ret, 0b000000, ret, 0); // LDUW [ret+0], ret |
|
185 return ret; |
|
186 } |
|
187 |
|
188 @Override |
|
189 public Register emitLoadPointer(Register b, int offset) { |
|
190 Register ret = newRegister(); |
|
191 emitOp3(0b11, ret, 0b001011, b, offset); // LDX [b+offset], ret |
|
192 return ret; |
|
193 } |
|
194 |
|
195 @Override |
|
196 public StackSlot emitIntToStack(Register a) { |
|
197 StackSlot ret = newStackSlot(LIRKind.value(SPARCKind.WORD)); |
|
198 emitOp3(0b11, a, 0b000100, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STW a, [fp+offset] |
|
199 return ret; |
|
200 } |
|
201 |
|
202 @Override |
|
203 public StackSlot emitLongToStack(Register a) { |
|
204 StackSlot ret = newStackSlot(LIRKind.value(SPARCKind.XWORD)); |
|
205 emitOp3(0b11, a, 0b001110, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STX a, [fp+offset] |
|
206 return ret; |
|
207 } |
|
208 |
|
209 @Override |
|
210 public StackSlot emitFloatToStack(Register a) { |
|
211 StackSlot ret = newStackSlot(LIRKind.value(SPARCKind.SINGLE)); |
|
212 emitOp3(0b11, a, 0b100100, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STF a, [fp+offset] |
|
213 return ret; |
|
214 } |
|
215 |
|
216 @Override |
|
217 public StackSlot emitPointerToStack(Register a) { |
|
218 StackSlot ret = newStackSlot(LIRKind.reference(SPARCKind.XWORD)); |
|
219 emitOp3(0b11, a, 0b001110, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STX a, [fp+offset] |
|
220 return ret; |
|
221 } |
|
222 |
|
223 @Override |
|
224 public StackSlot emitNarrowPointerToStack(Register a) { |
|
225 StackSlot ret = newStackSlot(LIRKind.reference(SPARCKind.WORD)); |
|
226 emitOp3(0b11, a, 0b000100, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STW a, [fp+offset] |
|
227 return ret; |
|
228 } |
|
229 |
|
230 @Override |
|
231 public Register emitUncompressPointer(Register compressed, long base, int shift) { |
|
232 Register ret; |
|
233 if (shift > 0) { |
|
234 ret = newRegister(); |
|
235 emitOp3(0b10, ret, 0b100101, compressed, shift); // SLL compressed, shift, ret |
|
236 } else { |
|
237 ret = compressed; |
|
238 } |
|
239 if (base == 0) { |
|
240 return ret; |
|
241 } else { |
|
242 Register b = emitLoadLong(base); |
|
243 emitOp3(0b10, b, 0b00000, ret, b); // ADD b, ret, b |
|
244 return b; |
|
245 } |
|
246 } |
|
247 |
|
248 @Override |
|
249 public Register emitIntAdd(Register a, Register b) { |
|
250 Register ret = newRegister(); |
|
251 emitOp3(0b10, ret, 0b00000, a, b); // ADD a, b, ret |
|
252 return ret; |
|
253 } |
|
254 |
|
255 private void emitMove(Register to, Register from) { |
|
256 if (to != from) { |
|
257 emitOp3(0b10, to, 0b000010, from, SPARC.g0); // OR from, g0, to |
|
258 } |
|
259 } |
|
260 |
|
261 @Override |
|
262 public void emitIntRet(Register a) { |
|
263 emitPointerRet(a); |
|
264 } |
|
265 |
|
266 @Override |
|
267 public void emitPointerRet(Register a) { |
|
268 emitMove(SPARC.i0, a); |
|
269 emitOp3(0b10, SPARC.g0, 0b111000, SPARC.i7, 8); // JMPL [i7+8], g0 |
|
270 emitOp3(0b10, SPARC.g0, 0b111101, SPARC.g0, SPARC.g0); // RESTORE g0, g0, g0 |
|
271 } |
|
272 |
|
273 @Override |
|
274 public void emitTrap(DebugInfo info) { |
|
275 recordImplicitException(info); |
|
276 emitOp3(0b11, SPARC.g0, 0b001011, SPARC.g0, 0); // LDX [g0+0], g0 |
|
277 } |
|
278 |
|
279 @Override |
|
280 public DataSectionReference emitDataItem(HotSpotConstant c) { |
|
281 if (c.isCompressed()) { |
|
282 data.align(4); |
|
283 } else { |
|
284 data.align(8); |
|
285 } |
|
286 return super.emitDataItem(c); |
|
287 } |
|
288 } |
|