50609
|
1 |
/*
|
57537
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
50609
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
50609
|
25 |
package org.graalvm.compiler.lir.amd64.vector;
|
|
26 |
|
|
27 |
import static jdk.vm.ci.code.ValueUtil.asRegister;
|
|
28 |
import static jdk.vm.ci.code.ValueUtil.isRegister;
|
|
29 |
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.COMPOSITE;
|
|
30 |
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
|
|
31 |
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
|
|
32 |
|
51436
|
33 |
import org.graalvm.compiler.asm.amd64.AMD64Address;
|
|
34 |
import org.graalvm.compiler.asm.amd64.AMD64Assembler.VexRRIOp;
|
|
35 |
import org.graalvm.compiler.asm.amd64.AMD64Assembler.VexRVMOp;
|
|
36 |
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
|
|
37 |
import org.graalvm.compiler.asm.amd64.AVXKind;
|
57537
|
38 |
import org.graalvm.compiler.lir.ConstantValue;
|
51436
|
39 |
import org.graalvm.compiler.lir.LIRFrameState;
|
|
40 |
import org.graalvm.compiler.lir.LIRInstructionClass;
|
|
41 |
import org.graalvm.compiler.lir.Opcode;
|
|
42 |
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
|
|
43 |
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
|
44 |
|
57537
|
45 |
import jdk.vm.ci.amd64.AMD64Kind;
|
51436
|
46 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
47 |
|
50609
|
48 |
public class AMD64VectorBinary {
|
|
49 |
|
59095
|
50 |
public static final class AVXBinaryOp extends AMD64VectorInstruction {
|
50609
|
51 |
public static final LIRInstructionClass<AVXBinaryOp> TYPE = LIRInstructionClass.create(AVXBinaryOp.class);
|
|
52 |
|
51436
|
53 |
@Opcode private final VexRVMOp opcode;
|
50609
|
54 |
|
|
55 |
@Def({REG}) protected AllocatableValue result;
|
|
56 |
@Use({REG}) protected AllocatableValue x;
|
|
57 |
@Use({REG, STACK}) protected AllocatableValue y;
|
|
58 |
|
51436
|
59 |
public AVXBinaryOp(VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, AllocatableValue y) {
|
59095
|
60 |
super(TYPE, size);
|
50609
|
61 |
this.opcode = opcode;
|
|
62 |
this.result = result;
|
|
63 |
this.x = x;
|
|
64 |
this.y = y;
|
|
65 |
}
|
|
66 |
|
|
67 |
@Override
|
51436
|
68 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
50609
|
69 |
if (isRegister(y)) {
|
51436
|
70 |
opcode.emit(masm, size, asRegister(result), asRegister(x), asRegister(y));
|
50609
|
71 |
} else {
|
51436
|
72 |
opcode.emit(masm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asAddress(y));
|
50609
|
73 |
}
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
59095
|
77 |
public static final class AVXBinaryConstOp extends AMD64VectorInstruction {
|
50609
|
78 |
|
|
79 |
public static final LIRInstructionClass<AVXBinaryConstOp> TYPE = LIRInstructionClass.create(AVXBinaryConstOp.class);
|
|
80 |
|
51436
|
81 |
@Opcode private final VexRRIOp opcode;
|
50609
|
82 |
|
|
83 |
@Def({REG}) protected AllocatableValue result;
|
|
84 |
@Use({REG}) protected AllocatableValue x;
|
|
85 |
protected int y;
|
|
86 |
|
51436
|
87 |
public AVXBinaryConstOp(VexRRIOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, int y) {
|
59095
|
88 |
super(TYPE, size);
|
50609
|
89 |
assert (y & 0xFF) == y;
|
|
90 |
this.opcode = opcode;
|
|
91 |
this.result = result;
|
|
92 |
this.x = x;
|
|
93 |
this.y = y;
|
|
94 |
}
|
|
95 |
|
|
96 |
@Override
|
51436
|
97 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
|
98 |
opcode.emit(masm, size, asRegister(result), asRegister(x), y);
|
50609
|
99 |
}
|
|
100 |
}
|
|
101 |
|
59095
|
102 |
public static final class AVXBinaryConstFloatOp extends AMD64VectorInstruction {
|
57537
|
103 |
|
|
104 |
public static final LIRInstructionClass<AVXBinaryConstFloatOp> TYPE = LIRInstructionClass.create(AVXBinaryConstFloatOp.class);
|
|
105 |
|
|
106 |
@Opcode private final VexRVMOp opcode;
|
|
107 |
|
|
108 |
@Def({REG}) protected AllocatableValue result;
|
|
109 |
@Use({REG}) protected AllocatableValue x;
|
|
110 |
protected ConstantValue y;
|
|
111 |
|
|
112 |
public AVXBinaryConstFloatOp(VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, ConstantValue y) {
|
59095
|
113 |
super(TYPE, size);
|
57537
|
114 |
assert y.getPlatformKind() == AMD64Kind.SINGLE || y.getPlatformKind() == AMD64Kind.DOUBLE;
|
|
115 |
this.opcode = opcode;
|
|
116 |
this.result = result;
|
|
117 |
this.x = x;
|
|
118 |
this.y = y;
|
|
119 |
}
|
|
120 |
|
|
121 |
@Override
|
|
122 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
|
123 |
if (y.getPlatformKind() == AMD64Kind.SINGLE) {
|
|
124 |
opcode.emit(masm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asFloatConstRef(y.getJavaConstant()));
|
|
125 |
} else {
|
|
126 |
assert y.getPlatformKind() == AMD64Kind.DOUBLE;
|
|
127 |
opcode.emit(masm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asDoubleConstRef(y.getJavaConstant()));
|
|
128 |
}
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
59095
|
132 |
public static final class AVXBinaryMemoryOp extends AMD64VectorInstruction {
|
50609
|
133 |
public static final LIRInstructionClass<AVXBinaryMemoryOp> TYPE = LIRInstructionClass.create(AVXBinaryMemoryOp.class);
|
|
134 |
|
51436
|
135 |
@Opcode private final VexRVMOp opcode;
|
50609
|
136 |
|
|
137 |
@Def({REG}) protected AllocatableValue result;
|
|
138 |
@Use({REG}) protected AllocatableValue x;
|
|
139 |
@Use({COMPOSITE}) protected AMD64AddressValue y;
|
|
140 |
@State protected LIRFrameState state;
|
|
141 |
|
51436
|
142 |
public AVXBinaryMemoryOp(VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, AMD64AddressValue y, LIRFrameState state) {
|
59095
|
143 |
super(TYPE, size);
|
50609
|
144 |
this.opcode = opcode;
|
|
145 |
this.result = result;
|
|
146 |
this.x = x;
|
|
147 |
this.y = y;
|
|
148 |
this.state = state;
|
|
149 |
}
|
|
150 |
|
|
151 |
@Override
|
51436
|
152 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
50609
|
153 |
if (state != null) {
|
51436
|
154 |
crb.recordImplicitException(masm.position(), state);
|
50609
|
155 |
}
|
51436
|
156 |
opcode.emit(masm, size, asRegister(result), asRegister(x), y.toAddress());
|
50609
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|