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 com.oracle.graal.lir.hsail;
24
25 import static com.oracle.graal.api.code.ValueUtil.*;
26 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
27
28 import com.oracle.graal.api.meta.*;
29 import com.oracle.graal.asm.hsail.*;
30 import com.oracle.graal.graph.*;
31 import com.oracle.graal.lir.*;
32 import com.oracle.graal.lir.asm.*;
33
34 /**
35 * Defines arithmetic instruction nodes.
36 */
37 public enum HSAILArithmetic {
38 CALL,
39 FDIV,
40 FREM,
41 DADD,
42 DDIV,
43 DMUL,
44 DNEG,
45 DREM,
46 DSUB,
47 FADD,
48 FMUL,
49 FNEG,
50 FSUB,
51 IADD,
52 IAND,
53 ICARRY,
54 IDIV,
55 IMAX,
56 IMIN,
57 IMUL,
58 INEG,
59 INOT,
80 LMIN,
81 LMUL,
82 LNEG,
83 LNOT,
84 LOR,
85 LREM,
86 LSHL,
87 LSHR,
88 LSUB,
89 LUADD,
90 LUCARRY,
91 LUDIV,
92 LUMAX,
93 LUMIN,
94 LUMUL,
95 LUREM,
96 LUSHR,
97 LUSUB,
98 LXOR,
99 OADD,
100 SQRT,
101 UNDEF;
102
103 public static class ConvertOp extends HSAILLIRInstruction {
104 private final Kind from;
105 private final Kind to;
106 @Def({REG}) protected AllocatableValue result;
107 @Use({REG, STACK}) protected AllocatableValue x;
108
109 public ConvertOp(AllocatableValue result, AllocatableValue x, Kind to, Kind from) {
110 this.from = from;
111 this.to = to;
112 this.result = result;
113 this.x = x;
114 }
115
116 @Override
117 public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) {
118 masm.emitConvert(result, x, to, from);
119 }
272 @Override
273 public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) {
274 emit(crb, masm, opcode, result, y, state);
275 }
276
277 @Override
278 protected void verify() {
279 super.verify();
280 verifyKind(opcode, result, x, y);
281 }
282 }
283
284 @SuppressWarnings("unused")
285 protected static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value result) {
286 switch (opcode) {
287 default:
288 throw GraalInternalError.shouldNotReachHere();
289 }
290 }
291
292 public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src, LIRFrameState info) {
293 int exceptionOffset = -1;
294 if (isRegister(src)) {
295 switch (opcode) {
296 case SQRT:
297 masm.emit("sqrt", dst, src);
298 break;
299 case UNDEF:
300 masm.undefined("undefined node");
301 break;
302 case CALL:
303 masm.undefined("undefined node CALL");
304 break;
305 case INOT:
306 case LNOT:
307 // Emit the HSAIL instruction for a bitwise not.
308 masm.emitForceBitwise("not", dst, src);
309 break;
310 case INEG:
311 case LNEG:
312 case FNEG:
313 case DNEG:
314 // Emit the HSAIL instruction for a negate operation.
315 masm.emit("neg", dst, src);
316 break;
317 default:
318 throw GraalInternalError.shouldNotReachHere();
319 }
320 } else {
321 throw GraalInternalError.shouldNotReachHere();
322 }
323 if (info != null) {
324 assert exceptionOffset != -1;
325 crb.recordImplicitException(exceptionOffset, info);
326 }
327 }
328
329 public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src1, Value src2, LIRFrameState info) {
330 /**
331 * First check if one of src1 or src2 is an AddressValue. If it is, convert the address to a
332 * register using an lda instruction. We can just reuse the eventual dst register for this.
333 */
334 if (src1 instanceof HSAILAddressValue) {
|
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 com.oracle.graal.lir.hsail;
24
25 import static com.oracle.graal.api.code.ValueUtil.*;
26 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
27
28 import com.oracle.graal.api.meta.*;
29 import com.oracle.graal.asm.hsail.*;
30 import com.oracle.graal.graph.*;
31 import com.oracle.graal.lir.*;
32 import com.oracle.graal.lir.asm.CompilationResultBuilder;
33
34 /**
35 * Defines arithmetic instruction nodes.
36 */
37 public enum HSAILArithmetic {
38 ABS,
39 CALL,
40 CEIL,
41 FDIV,
42 FLOOR,
43 FREM,
44 DADD,
45 DDIV,
46 DMUL,
47 DNEG,
48 DREM,
49 DSUB,
50 FADD,
51 FMUL,
52 FNEG,
53 FSUB,
54 IADD,
55 IAND,
56 ICARRY,
57 IDIV,
58 IMAX,
59 IMIN,
60 IMUL,
61 INEG,
62 INOT,
83 LMIN,
84 LMUL,
85 LNEG,
86 LNOT,
87 LOR,
88 LREM,
89 LSHL,
90 LSHR,
91 LSUB,
92 LUADD,
93 LUCARRY,
94 LUDIV,
95 LUMAX,
96 LUMIN,
97 LUMUL,
98 LUREM,
99 LUSHR,
100 LUSUB,
101 LXOR,
102 OADD,
103 RINT,
104 SQRT,
105 UNDEF;
106
107 public static class ConvertOp extends HSAILLIRInstruction {
108 private final Kind from;
109 private final Kind to;
110 @Def({REG}) protected AllocatableValue result;
111 @Use({REG, STACK}) protected AllocatableValue x;
112
113 public ConvertOp(AllocatableValue result, AllocatableValue x, Kind to, Kind from) {
114 this.from = from;
115 this.to = to;
116 this.result = result;
117 this.x = x;
118 }
119
120 @Override
121 public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) {
122 masm.emitConvert(result, x, to, from);
123 }
276 @Override
277 public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) {
278 emit(crb, masm, opcode, result, y, state);
279 }
280
281 @Override
282 protected void verify() {
283 super.verify();
284 verifyKind(opcode, result, x, y);
285 }
286 }
287
288 @SuppressWarnings("unused")
289 protected static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value result) {
290 switch (opcode) {
291 default:
292 throw GraalInternalError.shouldNotReachHere();
293 }
294 }
295
296 /**
297 * Emit the HSAIL code for an arithmetic operation taking one input parameter.
298 *
299 * @param crb the CompilationResultBuilder
300 * @param masm the HSAIL assembler
301 * @param opcode the opcode of the arithmetic operation
302 * @param dst the destination
303 * @param src the source parameter
304 * @param info structure that stores the LIRFrameState. Used for exception handling.
305 */
306
307 public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src, LIRFrameState info) {
308 int exceptionOffset = -1;
309 if (isRegister(src)) {
310 switch (opcode) {
311 case ABS:
312 masm.emit("abs", dst, src);
313 break;
314 case CEIL:
315 masm.emit("ceil", dst, src);
316 break;
317 case FLOOR:
318 masm.emit("floor", dst, src);
319 break;
320 case RINT:
321 masm.emit("rint", dst, src);
322 break;
323 case SQRT:
324 masm.emit("sqrt", dst, src);
325 break;
326 case UNDEF:
327 masm.undefined("undefined node");
328 break;
329 case CALL:
330 masm.undefined("undefined node CALL");
331 break;
332 case INOT:
333 case LNOT:
334 masm.emitForceBitwise("not", dst, src);
335 break;
336 case INEG:
337 case LNEG:
338 case FNEG:
339 case DNEG:
340 masm.emit("neg", dst, src);
341 break;
342 default:
343 throw GraalInternalError.shouldNotReachHere();
344 }
345 } else {
346 throw GraalInternalError.shouldNotReachHere();
347 }
348 if (info != null) {
349 assert exceptionOffset != -1;
350 crb.recordImplicitException(exceptionOffset, info);
351 }
352 }
353
354 public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src1, Value src2, LIRFrameState info) {
355 /**
356 * First check if one of src1 or src2 is an AddressValue. If it is, convert the address to a
357 * register using an lda instruction. We can just reuse the eventual dst register for this.
358 */
359 if (src1 instanceof HSAILAddressValue) {
|