blob: 781a59f661937a2e54c8c79e7753344971887074 [file] [log] [blame]
Aart Bikf8f5a162017-02-06 15:35:29 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_
18#define ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_
19
20// This #include should never be used by compilation, because this header file (nodes_vector.h)
21// is included in the header file nodes.h itself. However it gives editing tools better context.
22#include "nodes.h"
23
24namespace art {
25
26// Memory alignment, represented as an offset relative to a base, where 0 <= offset < base,
27// and base is a power of two. For example, the value Alignment(16, 0) means memory is
28// perfectly aligned at a 16-byte boundary, whereas the value Alignment(16, 4) means
29// memory is always exactly 4 bytes above such a boundary.
30class Alignment {
31 public:
32 Alignment(size_t base, size_t offset) : base_(base), offset_(offset) {
33 DCHECK_LT(offset, base);
34 DCHECK(IsPowerOfTwo(base));
35 }
36
Aart Bik46b6dbc2017-10-03 11:37:37 -070037 // Returns true if memory is at least aligned at the given boundary.
Aart Bikf8f5a162017-02-06 15:35:29 -080038 // Assumes requested base is power of two.
39 bool IsAlignedAt(size_t base) const {
40 DCHECK_NE(0u, base);
41 DCHECK(IsPowerOfTwo(base));
42 return ((offset_ | base_) & (base - 1u)) == 0;
43 }
44
Aart Bik46b6dbc2017-10-03 11:37:37 -070045 size_t Base() const { return base_; }
46
47 size_t Offset() const { return offset_; }
48
Aart Bikf8f5a162017-02-06 15:35:29 -080049 std::string ToString() const {
50 return "ALIGN(" + std::to_string(base_) + "," + std::to_string(offset_) + ")";
51 }
52
Aart Bikb79f4ac2017-07-10 10:10:37 -070053 bool operator==(const Alignment& other) const {
54 return base_ == other.base_ && offset_ == other.offset_;
55 }
56
Aart Bikf8f5a162017-02-06 15:35:29 -080057 private:
58 size_t base_;
59 size_t offset_;
60};
61
62//
63// Definitions of abstract vector operations in HIR.
64//
65
66// Abstraction of a vector operation, i.e., an operation that performs
67// GetVectorLength() x GetPackedType() operations simultaneously.
68class HVecOperation : public HVariableInputSizeInstruction {
69 public:
Aart Bik0148de42017-09-05 09:25:01 -070070 // A SIMD operation looks like a FPU location.
71 // TODO: we could introduce SIMD types in HIR.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010072 static constexpr DataType::Type kSIMDType = DataType::Type::kFloat64;
Aart Bik0148de42017-09-05 09:25:01 -070073
Vladimir Markoe764d2e2017-10-05 14:35:55 +010074 HVecOperation(ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010075 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -080076 SideEffects side_effects,
77 size_t number_of_inputs,
78 size_t vector_length,
79 uint32_t dex_pc)
80 : HVariableInputSizeInstruction(side_effects,
81 dex_pc,
Vladimir Markoe764d2e2017-10-05 14:35:55 +010082 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -080083 number_of_inputs,
84 kArenaAllocVectorNode),
85 vector_length_(vector_length) {
86 SetPackedField<TypeField>(packed_type);
87 DCHECK_LT(1u, vector_length);
88 }
89
90 // Returns the number of elements packed in a vector.
91 size_t GetVectorLength() const {
92 return vector_length_;
93 }
94
95 // Returns the number of bytes in a full vector.
96 size_t GetVectorNumberOfBytes() const {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010097 return vector_length_ * DataType::Size(GetPackedType());
Aart Bikf8f5a162017-02-06 15:35:29 -080098 }
99
Aart Bik0148de42017-09-05 09:25:01 -0700100 // Returns the type of the vector operation.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100101 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700102 return kSIMDType;
Aart Bikf8f5a162017-02-06 15:35:29 -0800103 }
104
105 // Returns the true component type packed in a vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100106 DataType::Type GetPackedType() const {
Aart Bikf8f5a162017-02-06 15:35:29 -0800107 return GetPackedField<TypeField>();
108 }
109
Aart Bikb79f4ac2017-07-10 10:10:37 -0700110 // Assumes vector nodes cannot be moved by default. Each concrete implementation
111 // that can be moved should override this method and return true.
112 bool CanBeMoved() const OVERRIDE { return false; }
113
114 // Tests if all data of a vector node (vector length and packed type) is equal.
115 // Each concrete implementation that adds more fields should test equality of
116 // those fields in its own method *and* call all super methods.
117 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
118 DCHECK(other->IsVecOperation());
119 const HVecOperation* o = other->AsVecOperation();
120 return GetVectorLength() == o->GetVectorLength() && GetPackedType() == o->GetPackedType();
121 }
122
Aart Bik46b6dbc2017-10-03 11:37:37 -0700123 // Maps an integral type to the same-size signed type and leaves other types alone.
124 // Can be used to test relaxed type consistency in which packed same-size integral
125 // types can co-exist, but other type mixes are an error.
126 static DataType::Type ToSignedType(DataType::Type type) {
127 switch (type) {
128 case DataType::Type::kBool: // 1-byte storage unit
129 case DataType::Type::kUint8:
130 return DataType::Type::kInt8;
131 case DataType::Type::kUint16:
132 return DataType::Type::kInt16;
133 default:
134 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
135 return type;
136 }
137 }
138
Aart Bikf8f5a162017-02-06 15:35:29 -0800139 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
140
Aart Bikdb14fcf2017-04-25 15:53:58 -0700141 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800142 // Additional packed bits.
143 static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits;
144 static constexpr size_t kFieldTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100145 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Aart Bikf8f5a162017-02-06 15:35:29 -0800146 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldType + kFieldTypeSize;
147 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100148 using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800149
Aart Bikdb14fcf2017-04-25 15:53:58 -0700150 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800151 const size_t vector_length_;
152
153 DISALLOW_COPY_AND_ASSIGN(HVecOperation);
154};
155
156// Abstraction of a unary vector operation.
157class HVecUnaryOperation : public HVecOperation {
158 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100159 HVecUnaryOperation(ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700160 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100161 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800162 size_t vector_length,
163 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100164 : HVecOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800165 packed_type,
166 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700167 /* number_of_inputs */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800168 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700169 dex_pc) {
170 SetRawInputAt(0, input);
171 }
172
173 HInstruction* GetInput() const { return InputAt(0); }
174
Aart Bikf8f5a162017-02-06 15:35:29 -0800175 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700176
Aart Bikf8f5a162017-02-06 15:35:29 -0800177 private:
178 DISALLOW_COPY_AND_ASSIGN(HVecUnaryOperation);
179};
180
181// Abstraction of a binary vector operation.
182class HVecBinaryOperation : public HVecOperation {
183 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100184 HVecBinaryOperation(ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700185 HInstruction* left,
186 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100187 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800188 size_t vector_length,
189 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100190 : HVecOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800191 packed_type,
192 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700193 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800194 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700195 dex_pc) {
196 SetRawInputAt(0, left);
197 SetRawInputAt(1, right);
198 }
Artem Serovf34dd202017-04-10 17:41:46 +0100199
200 HInstruction* GetLeft() const { return InputAt(0); }
201 HInstruction* GetRight() const { return InputAt(1); }
202
Aart Bikf8f5a162017-02-06 15:35:29 -0800203 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700204
Aart Bikf8f5a162017-02-06 15:35:29 -0800205 private:
206 DISALLOW_COPY_AND_ASSIGN(HVecBinaryOperation);
207};
208
209// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700210// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800211class HVecMemoryOperation : public HVecOperation {
212 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100213 HVecMemoryOperation(ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100214 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800215 SideEffects side_effects,
216 size_t number_of_inputs,
217 size_t vector_length,
218 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100219 : HVecOperation(allocator,
220 packed_type,
221 side_effects,
222 number_of_inputs,
223 vector_length,
224 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100225 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100226 DCHECK_GE(number_of_inputs, 2u);
227 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800228
229 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
230
231 Alignment GetAlignment() const { return alignment_; }
232
Artem Serove1811ed2017-04-27 16:50:47 +0100233 HInstruction* GetArray() const { return InputAt(0); }
234 HInstruction* GetIndex() const { return InputAt(1); }
235
Aart Bikb79f4ac2017-07-10 10:10:37 -0700236 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
237 DCHECK(other->IsVecMemoryOperation());
238 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
239 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
240 }
241
Aart Bikf8f5a162017-02-06 15:35:29 -0800242 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
243
244 private:
245 Alignment alignment_;
246
247 DISALLOW_COPY_AND_ASSIGN(HVecMemoryOperation);
248};
249
Aart Bik0148de42017-09-05 09:25:01 -0700250// Packed type consistency checker ("same vector length" integral types may mix freely).
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100251inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700252 if (input->IsPhi()) {
253 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
254 }
Aart Bikd58bc322017-05-01 14:49:18 -0700255 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100256 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik46b6dbc2017-10-03 11:37:37 -0700257 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700258}
259
Aart Bikf8f5a162017-02-06 15:35:29 -0800260//
Aart Bik8de59162017-04-21 09:42:01 -0700261// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800262//
263
264// Replicates the given scalar into a vector,
265// viz. replicate(x) = [ x, .. , x ].
266class HVecReplicateScalar FINAL : public HVecUnaryOperation {
267 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100268 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800269 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100270 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800271 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700272 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100273 : HVecUnaryOperation(allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik8de59162017-04-21 09:42:01 -0700274 DCHECK(!scalar->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800275 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700276
277 // A replicate needs to stay in place, since SIMD registers are not
278 // kept alive across vector loop boundaries (yet).
279 bool CanBeMoved() const OVERRIDE { return false; }
280
Aart Bikf8f5a162017-02-06 15:35:29 -0800281 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700282
Aart Bikf8f5a162017-02-06 15:35:29 -0800283 private:
284 DISALLOW_COPY_AND_ASSIGN(HVecReplicateScalar);
285};
286
Aart Bik0148de42017-09-05 09:25:01 -0700287// Extracts a particular scalar from the given vector,
288// viz. extract[ x1, .. , xn ] = x_i.
289//
290// TODO: for now only i == 1 case supported.
291class HVecExtractScalar FINAL : public HVecUnaryOperation {
292 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100293 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700294 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100295 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700296 size_t vector_length,
297 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700298 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100299 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700300 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700301 DCHECK_LT(index, vector_length);
302 DCHECK_EQ(index, 0u);
303 }
304
305 // Yields a single component in the vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100306 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700307 return GetPackedType();
308 }
309
310 // An extract needs to stay in place, since SIMD registers are not
311 // kept alive across vector loop boundaries (yet).
312 bool CanBeMoved() const OVERRIDE { return false; }
313
314 DECLARE_INSTRUCTION(VecExtractScalar);
315
316 private:
317 DISALLOW_COPY_AND_ASSIGN(HVecExtractScalar);
318};
319
320// Reduces the given vector into the first element as sum/min/max,
321// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
322// and the "-" denotes "don't care" (implementation dependent).
323class HVecReduce FINAL : public HVecUnaryOperation {
324 public:
325 enum ReductionKind {
326 kSum = 1,
327 kMin = 2,
328 kMax = 3
329 };
330
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100331 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700332 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100333 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700334 size_t vector_length,
335 ReductionKind kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700336 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100337 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc),
Aart Bik0148de42017-09-05 09:25:01 -0700338 kind_(kind) {
339 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700340 }
341
Aart Bik0148de42017-09-05 09:25:01 -0700342 ReductionKind GetKind() const { return kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800343
Aart Bikb79f4ac2017-07-10 10:10:37 -0700344 bool CanBeMoved() const OVERRIDE { return true; }
345
Aart Bik0148de42017-09-05 09:25:01 -0700346 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
347 DCHECK(other->IsVecReduce());
348 const HVecReduce* o = other->AsVecReduce();
349 return HVecOperation::InstructionDataEquals(o) && GetKind() == o->GetKind();
350 }
351
352 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700353
Aart Bikf8f5a162017-02-06 15:35:29 -0800354 private:
Aart Bik0148de42017-09-05 09:25:01 -0700355 const ReductionKind kind_;
356
357 DISALLOW_COPY_AND_ASSIGN(HVecReduce);
Aart Bikf8f5a162017-02-06 15:35:29 -0800358};
359
360// Converts every component in the vector,
361// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
362class HVecCnv FINAL : public HVecUnaryOperation {
363 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100364 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800365 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100366 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800367 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700368 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100369 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800370 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700371 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800372 }
373
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100374 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
375 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800376
Aart Bikb79f4ac2017-07-10 10:10:37 -0700377 bool CanBeMoved() const OVERRIDE { return true; }
378
Aart Bikf8f5a162017-02-06 15:35:29 -0800379 DECLARE_INSTRUCTION(VecCnv);
380
381 private:
382 DISALLOW_COPY_AND_ASSIGN(HVecCnv);
383};
384
385// Negates every component in the vector,
386// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
387class HVecNeg FINAL : public HVecUnaryOperation {
388 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100389 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800390 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100391 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800392 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700393 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100394 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700395 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800396 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700397
398 bool CanBeMoved() const OVERRIDE { return true; }
399
Aart Bikf8f5a162017-02-06 15:35:29 -0800400 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700401
Aart Bikf8f5a162017-02-06 15:35:29 -0800402 private:
403 DISALLOW_COPY_AND_ASSIGN(HVecNeg);
404};
405
Aart Bik6daebeb2017-04-03 14:35:41 -0700406// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700407// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
408// for signed operand x.
Aart Bik6daebeb2017-04-03 14:35:41 -0700409class HVecAbs FINAL : public HVecUnaryOperation {
410 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100411 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700412 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100413 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700414 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700415 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100416 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700417 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700418 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700419
420 bool CanBeMoved() const OVERRIDE { return true; }
421
Aart Bik6daebeb2017-04-03 14:35:41 -0700422 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700423
Aart Bik6daebeb2017-04-03 14:35:41 -0700424 private:
425 DISALLOW_COPY_AND_ASSIGN(HVecAbs);
426};
427
Aart Bikf8f5a162017-02-06 15:35:29 -0800428// Bitwise- or boolean-nots every component in the vector,
429// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
430// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
431class HVecNot FINAL : public HVecUnaryOperation {
432 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100433 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800434 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100435 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800436 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700437 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100438 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800439 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800440 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700441
442 bool CanBeMoved() const OVERRIDE { return true; }
443
Aart Bikf8f5a162017-02-06 15:35:29 -0800444 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700445
Aart Bikf8f5a162017-02-06 15:35:29 -0800446 private:
447 DISALLOW_COPY_AND_ASSIGN(HVecNot);
448};
449
Aart Bik8de59162017-04-21 09:42:01 -0700450//
451// Definitions of concrete binary vector operations in HIR.
452//
453
Aart Bikf8f5a162017-02-06 15:35:29 -0800454// Adds every component in the two vectors,
455// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
456class HVecAdd FINAL : public HVecBinaryOperation {
457 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100458 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800459 HInstruction* left,
460 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100461 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800462 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700463 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100464 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700465 DCHECK(HasConsistentPackedTypes(left, packed_type));
466 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800467 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700468
469 bool CanBeMoved() const OVERRIDE { return true; }
470
Aart Bikf8f5a162017-02-06 15:35:29 -0800471 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700472
Aart Bikf8f5a162017-02-06 15:35:29 -0800473 private:
474 DISALLOW_COPY_AND_ASSIGN(HVecAdd);
475};
476
Aart Bikf3e61ee2017-04-12 17:09:20 -0700477// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700478// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
479// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik46b6dbc2017-10-03 11:37:37 -0700480// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700481class HVecHalvingAdd FINAL : public HVecBinaryOperation {
482 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100483 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700484 HInstruction* left,
485 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100486 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700487 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700488 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700489 bool is_unsigned,
490 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100491 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100492 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
493 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
494 DCHECK(!is_unsigned ||
495 packed_type == DataType::Type::kInt32 ||
496 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700497 DCHECK(HasConsistentPackedTypes(left, packed_type));
498 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700499 SetPackedFlag<kFieldHAddIsUnsigned>(is_unsigned);
500 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700501 }
502
Aart Bikdb14fcf2017-04-25 15:53:58 -0700503 bool IsUnsigned() const { return GetPackedFlag<kFieldHAddIsUnsigned>(); }
504 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700505
Aart Bikb79f4ac2017-07-10 10:10:37 -0700506 bool CanBeMoved() const OVERRIDE { return true; }
507
508 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
509 DCHECK(other->IsVecHalvingAdd());
510 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
511 return HVecOperation::InstructionDataEquals(o) &&
512 IsUnsigned() == o->IsUnsigned() &&
513 IsRounded() == o->IsRounded();
514 }
515
Aart Bikf3e61ee2017-04-12 17:09:20 -0700516 DECLARE_INSTRUCTION(VecHalvingAdd);
517
518 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700519 // Additional packed bits.
520 static constexpr size_t kFieldHAddIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
521 static constexpr size_t kFieldHAddIsRounded = kFieldHAddIsUnsigned + 1;
522 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
523 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700524
525 DISALLOW_COPY_AND_ASSIGN(HVecHalvingAdd);
526};
527
Aart Bikf8f5a162017-02-06 15:35:29 -0800528// Subtracts every component in the two vectors,
529// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
530class HVecSub FINAL : public HVecBinaryOperation {
531 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100532 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800533 HInstruction* left,
534 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100535 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800536 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700537 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100538 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700539 DCHECK(HasConsistentPackedTypes(left, packed_type));
540 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800541 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700542
543 bool CanBeMoved() const OVERRIDE { return true; }
544
Aart Bikf8f5a162017-02-06 15:35:29 -0800545 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700546
Aart Bikf8f5a162017-02-06 15:35:29 -0800547 private:
548 DISALLOW_COPY_AND_ASSIGN(HVecSub);
549};
550
551// Multiplies every component in the two vectors,
552// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
553class HVecMul FINAL : public HVecBinaryOperation {
554 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100555 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800556 HInstruction* left,
557 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100558 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800559 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700560 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100561 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700562 DCHECK(HasConsistentPackedTypes(left, packed_type));
563 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800564 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700565
566 bool CanBeMoved() const OVERRIDE { return true; }
567
Aart Bikf8f5a162017-02-06 15:35:29 -0800568 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700569
Aart Bikf8f5a162017-02-06 15:35:29 -0800570 private:
571 DISALLOW_COPY_AND_ASSIGN(HVecMul);
572};
573
574// Divides every component in the two vectors,
575// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
576class HVecDiv FINAL : public HVecBinaryOperation {
577 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100578 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800579 HInstruction* left,
580 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100581 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800582 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700583 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100584 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700585 DCHECK(HasConsistentPackedTypes(left, packed_type));
586 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800587 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700588
589 bool CanBeMoved() const OVERRIDE { return true; }
590
Aart Bikf8f5a162017-02-06 15:35:29 -0800591 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700592
Aart Bikf8f5a162017-02-06 15:35:29 -0800593 private:
594 DISALLOW_COPY_AND_ASSIGN(HVecDiv);
595};
596
Aart Bikf3e61ee2017-04-12 17:09:20 -0700597// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700598// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
599// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700600class HVecMin FINAL : public HVecBinaryOperation {
601 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100602 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700603 HInstruction* left,
604 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100605 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700606 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700607 bool is_unsigned,
608 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100609 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100610 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
611 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
612 DCHECK(!is_unsigned ||
613 packed_type == DataType::Type::kInt32 ||
614 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700615 DCHECK(HasConsistentPackedTypes(left, packed_type));
616 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikc8e93c72017-05-10 10:49:22 -0700617 SetPackedFlag<kFieldMinOpIsUnsigned>(is_unsigned);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700618 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700619
620 bool IsUnsigned() const { return GetPackedFlag<kFieldMinOpIsUnsigned>(); }
621
Aart Bikb79f4ac2017-07-10 10:10:37 -0700622 bool CanBeMoved() const OVERRIDE { return true; }
623
624 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
625 DCHECK(other->IsVecMin());
626 const HVecMin* o = other->AsVecMin();
627 return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned();
628 }
629
Aart Bikf3e61ee2017-04-12 17:09:20 -0700630 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700631
Aart Bikf3e61ee2017-04-12 17:09:20 -0700632 private:
Aart Bikc8e93c72017-05-10 10:49:22 -0700633 // Additional packed bits.
634 static constexpr size_t kFieldMinOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
635 static constexpr size_t kNumberOfMinOpPackedBits = kFieldMinOpIsUnsigned + 1;
636 static_assert(kNumberOfMinOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
637
Aart Bikf3e61ee2017-04-12 17:09:20 -0700638 DISALLOW_COPY_AND_ASSIGN(HVecMin);
639};
640
641// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700642// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
643// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700644class HVecMax FINAL : public HVecBinaryOperation {
645 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100646 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700647 HInstruction* left,
648 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100649 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700650 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700651 bool is_unsigned,
652 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100653 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100654 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
655 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
656 DCHECK(!is_unsigned ||
657 packed_type == DataType::Type::kInt32 ||
658 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700659 DCHECK(HasConsistentPackedTypes(left, packed_type));
660 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikc8e93c72017-05-10 10:49:22 -0700661 SetPackedFlag<kFieldMaxOpIsUnsigned>(is_unsigned);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700662 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700663
664 bool IsUnsigned() const { return GetPackedFlag<kFieldMaxOpIsUnsigned>(); }
665
Aart Bikb79f4ac2017-07-10 10:10:37 -0700666 bool CanBeMoved() const OVERRIDE { return true; }
667
668 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
669 DCHECK(other->IsVecMax());
670 const HVecMax* o = other->AsVecMax();
671 return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned();
672 }
673
Aart Bikf3e61ee2017-04-12 17:09:20 -0700674 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700675
Aart Bikf3e61ee2017-04-12 17:09:20 -0700676 private:
Aart Bikc8e93c72017-05-10 10:49:22 -0700677 // Additional packed bits.
678 static constexpr size_t kFieldMaxOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
679 static constexpr size_t kNumberOfMaxOpPackedBits = kFieldMaxOpIsUnsigned + 1;
680 static_assert(kNumberOfMaxOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
681
Aart Bikf3e61ee2017-04-12 17:09:20 -0700682 DISALLOW_COPY_AND_ASSIGN(HVecMax);
683};
684
Aart Bikf8f5a162017-02-06 15:35:29 -0800685// Bitwise-ands every component in the two vectors,
686// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
687class HVecAnd FINAL : public HVecBinaryOperation {
688 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100689 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800690 HInstruction* left,
691 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100692 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800693 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700694 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100695 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800696 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800697 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700698
699 bool CanBeMoved() const OVERRIDE { return true; }
700
Aart Bikf8f5a162017-02-06 15:35:29 -0800701 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700702
Aart Bikf8f5a162017-02-06 15:35:29 -0800703 private:
704 DISALLOW_COPY_AND_ASSIGN(HVecAnd);
705};
706
707// Bitwise-and-nots every component in the two vectors,
708// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
709class HVecAndNot FINAL : public HVecBinaryOperation {
710 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100711 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800712 HInstruction* left,
713 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100714 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800715 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700716 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100717 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800718 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800719 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700720
721 bool CanBeMoved() const OVERRIDE { return true; }
722
Aart Bikf8f5a162017-02-06 15:35:29 -0800723 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700724
Aart Bikf8f5a162017-02-06 15:35:29 -0800725 private:
726 DISALLOW_COPY_AND_ASSIGN(HVecAndNot);
727};
728
729// Bitwise-ors every component in the two vectors,
730// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
731class HVecOr FINAL : public HVecBinaryOperation {
732 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100733 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800734 HInstruction* left,
735 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100736 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800737 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700738 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100739 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800740 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800741 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700742
743 bool CanBeMoved() const OVERRIDE { return true; }
744
Aart Bikf8f5a162017-02-06 15:35:29 -0800745 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700746
Aart Bikf8f5a162017-02-06 15:35:29 -0800747 private:
748 DISALLOW_COPY_AND_ASSIGN(HVecOr);
749};
750
751// Bitwise-xors every component in the two vectors,
752// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
753class HVecXor FINAL : public HVecBinaryOperation {
754 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100755 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800756 HInstruction* left,
757 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100758 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800759 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700760 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100761 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800762 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800763 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700764
765 bool CanBeMoved() const OVERRIDE { return true; }
766
Aart Bikf8f5a162017-02-06 15:35:29 -0800767 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700768
Aart Bikf8f5a162017-02-06 15:35:29 -0800769 private:
770 DISALLOW_COPY_AND_ASSIGN(HVecXor);
771};
772
773// Logically shifts every component in the vector left by the given distance,
774// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
775class HVecShl FINAL : public HVecBinaryOperation {
776 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100777 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800778 HInstruction* left,
779 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100780 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800781 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700782 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100783 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700784 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800785 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700786
787 bool CanBeMoved() const OVERRIDE { return true; }
788
Aart Bikf8f5a162017-02-06 15:35:29 -0800789 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700790
Aart Bikf8f5a162017-02-06 15:35:29 -0800791 private:
792 DISALLOW_COPY_AND_ASSIGN(HVecShl);
793};
794
795// Arithmetically shifts every component in the vector right by the given distance,
796// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
797class HVecShr FINAL : public HVecBinaryOperation {
798 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100799 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800800 HInstruction* left,
801 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100802 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800803 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700804 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100805 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700806 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800807 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700808
809 bool CanBeMoved() const OVERRIDE { return true; }
810
Aart Bikf8f5a162017-02-06 15:35:29 -0800811 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700812
Aart Bikf8f5a162017-02-06 15:35:29 -0800813 private:
814 DISALLOW_COPY_AND_ASSIGN(HVecShr);
815};
816
817// Logically shifts every component in the vector right by the given distance,
818// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
819class HVecUShr FINAL : public HVecBinaryOperation {
820 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100821 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800822 HInstruction* left,
823 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100824 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800825 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700826 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100827 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700828 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800829 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700830
831 bool CanBeMoved() const OVERRIDE { return true; }
832
Aart Bikf8f5a162017-02-06 15:35:29 -0800833 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700834
Aart Bikf8f5a162017-02-06 15:35:29 -0800835 private:
836 DISALLOW_COPY_AND_ASSIGN(HVecUShr);
837};
838
Aart Bik8de59162017-04-21 09:42:01 -0700839//
840// Definitions of concrete miscellaneous vector operations in HIR.
841//
842
843// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700844// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
845// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Aart Bik8de59162017-04-21 09:42:01 -0700846class HVecSetScalars FINAL : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700847 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100848 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700849 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100850 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700851 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700852 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700853 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100854 : HVecOperation(allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700855 packed_type,
856 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700857 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700858 vector_length,
859 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700860 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik5e3afa92017-09-20 14:11:11 -0700861 DCHECK(!scalars[i]->IsVecOperation() || scalars[i]->IsVecExtractScalar());
Aart Bik8de59162017-04-21 09:42:01 -0700862 SetRawInputAt(0, scalars[i]);
863 }
864 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700865
866 // Setting scalars needs to stay in place, since SIMD registers are not
867 // kept alive across vector loop boundaries (yet).
868 bool CanBeMoved() const OVERRIDE { return false; }
869
Aart Bik8de59162017-04-21 09:42:01 -0700870 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700871
Aart Bik8de59162017-04-21 09:42:01 -0700872 private:
873 DISALLOW_COPY_AND_ASSIGN(HVecSetScalars);
874};
875
Aart Bikdbbac8f2017-09-01 13:06:08 -0700876// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
877// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Artem Serovf34dd202017-04-10 17:41:46 +0100878class HVecMultiplyAccumulate FINAL : public HVecOperation {
879 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100880 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100881 InstructionKind op,
882 HInstruction* accumulator,
883 HInstruction* mul_left,
884 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100885 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +0100886 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700887 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100888 : HVecOperation(allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100889 packed_type,
890 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700891 /* number_of_inputs */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +0100892 vector_length,
893 dex_pc),
894 op_kind_(op) {
895 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -0700896 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
897 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
898 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700899 SetRawInputAt(0, accumulator);
900 SetRawInputAt(1, mul_left);
901 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +0100902 }
903
Nicolas Geoffray9858bf72017-07-08 12:34:55 +0000904 bool CanBeMoved() const OVERRIDE { return true; }
905
Artem Serovf34dd202017-04-10 17:41:46 +0100906 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700907 DCHECK(other->IsVecMultiplyAccumulate());
908 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
909 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +0100910 }
911
912 InstructionKind GetOpKind() const { return op_kind_; }
913
914 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
915
916 private:
917 // Indicates if this is a MADD or MSUB.
918 const InstructionKind op_kind_;
919
920 DISALLOW_COPY_AND_ASSIGN(HVecMultiplyAccumulate);
921};
922
Aart Bikdbbac8f2017-09-01 13:06:08 -0700923// Takes the absolute difference of two vectors, and adds the results to
924// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700925// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -0700926// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -0700927// for m <= n, non-overlapping sums, and signed operands x, y.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700928class HVecSADAccumulate FINAL : public HVecOperation {
929 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100930 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700931 HInstruction* accumulator,
932 HInstruction* sad_left,
933 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100934 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700935 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700936 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100937 : HVecOperation(allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700938 packed_type,
939 SideEffects::None(),
940 /* number_of_inputs */ 3,
941 vector_length,
942 dex_pc) {
943 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
944 DCHECK(sad_left->IsVecOperation());
945 DCHECK(sad_right->IsVecOperation());
946 DCHECK_EQ(sad_left->AsVecOperation()->GetPackedType(),
947 sad_right->AsVecOperation()->GetPackedType());
948 SetRawInputAt(0, accumulator);
949 SetRawInputAt(1, sad_left);
950 SetRawInputAt(2, sad_right);
951 }
952
953 DECLARE_INSTRUCTION(VecSADAccumulate);
954
955 private:
956 DISALLOW_COPY_AND_ASSIGN(HVecSADAccumulate);
957};
958
Aart Bikf8f5a162017-02-06 15:35:29 -0800959// Loads a vector from memory, viz. load(mem, 1)
960// yield the vector [ mem(1), .. , mem(n) ].
961class HVecLoad FINAL : public HVecMemoryOperation {
962 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100963 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800964 HInstruction* base,
965 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100966 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100967 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -0800968 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -0700969 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700970 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100971 : HVecMemoryOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800972 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100973 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -0700974 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800975 vector_length,
976 dex_pc) {
977 SetRawInputAt(0, base);
978 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -0700979 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -0800980 }
Aart Bikdb14fcf2017-04-25 15:53:58 -0700981
982 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
983
Aart Bikb79f4ac2017-07-10 10:10:37 -0700984 bool CanBeMoved() const OVERRIDE { return true; }
985
986 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
987 DCHECK(other->IsVecLoad());
988 const HVecLoad* o = other->AsVecLoad();
989 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
990 }
991
992 DECLARE_INSTRUCTION(VecLoad);
993
Aart Bikf8f5a162017-02-06 15:35:29 -0800994 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700995 // Additional packed bits.
996 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
997 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
998 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
999
Aart Bikf8f5a162017-02-06 15:35:29 -08001000 DISALLOW_COPY_AND_ASSIGN(HVecLoad);
1001};
1002
1003// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1004// sets mem(1) = x1, .. , mem(n) = xn.
1005class HVecStore FINAL : public HVecMemoryOperation {
1006 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001007 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001008 HInstruction* base,
1009 HInstruction* index,
1010 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001011 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001012 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001013 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001014 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001015 : HVecMemoryOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001016 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001017 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001018 /* number_of_inputs */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001019 vector_length,
1020 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001021 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001022 SetRawInputAt(0, base);
1023 SetRawInputAt(1, index);
1024 SetRawInputAt(2, value);
1025 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001026
1027 // A store needs to stay in place.
1028 bool CanBeMoved() const OVERRIDE { return false; }
1029
Aart Bikf8f5a162017-02-06 15:35:29 -08001030 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001031
Aart Bikf8f5a162017-02-06 15:35:29 -08001032 private:
1033 DISALLOW_COPY_AND_ASSIGN(HVecStore);
1034};
1035
1036} // namespace art
1037
1038#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_