blob: 17540b9770411cd948676f464ed73a30fa9820d4 [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 Bik4d1a9d42017-10-19 14:40:55 -0700139 // Maps an integral type to the same-size unsigned type and leaves other types alone.
140 static DataType::Type ToUnsignedType(DataType::Type type) {
141 switch (type) {
142 case DataType::Type::kBool: // 1-byte storage unit
143 case DataType::Type::kInt8:
144 return DataType::Type::kUint8;
145 case DataType::Type::kInt16:
146 return DataType::Type::kUint16;
147 default:
148 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
149 return type;
150 }
151 }
152
Aart Bikf8f5a162017-02-06 15:35:29 -0800153 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
154
Aart Bikdb14fcf2017-04-25 15:53:58 -0700155 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800156 // Additional packed bits.
157 static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits;
158 static constexpr size_t kFieldTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100159 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Aart Bikf8f5a162017-02-06 15:35:29 -0800160 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldType + kFieldTypeSize;
161 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100162 using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800163
Aart Bikdb14fcf2017-04-25 15:53:58 -0700164 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800165 const size_t vector_length_;
166
167 DISALLOW_COPY_AND_ASSIGN(HVecOperation);
168};
169
170// Abstraction of a unary vector operation.
171class HVecUnaryOperation : public HVecOperation {
172 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100173 HVecUnaryOperation(ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700174 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100175 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800176 size_t vector_length,
177 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100178 : HVecOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800179 packed_type,
180 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700181 /* number_of_inputs */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800182 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700183 dex_pc) {
184 SetRawInputAt(0, input);
185 }
186
187 HInstruction* GetInput() const { return InputAt(0); }
188
Aart Bikf8f5a162017-02-06 15:35:29 -0800189 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700190
Aart Bikf8f5a162017-02-06 15:35:29 -0800191 private:
192 DISALLOW_COPY_AND_ASSIGN(HVecUnaryOperation);
193};
194
195// Abstraction of a binary vector operation.
196class HVecBinaryOperation : public HVecOperation {
197 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100198 HVecBinaryOperation(ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700199 HInstruction* left,
200 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100201 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800202 size_t vector_length,
203 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100204 : HVecOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800205 packed_type,
206 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700207 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800208 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700209 dex_pc) {
210 SetRawInputAt(0, left);
211 SetRawInputAt(1, right);
212 }
Artem Serovf34dd202017-04-10 17:41:46 +0100213
214 HInstruction* GetLeft() const { return InputAt(0); }
215 HInstruction* GetRight() const { return InputAt(1); }
216
Aart Bikf8f5a162017-02-06 15:35:29 -0800217 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700218
Aart Bikf8f5a162017-02-06 15:35:29 -0800219 private:
220 DISALLOW_COPY_AND_ASSIGN(HVecBinaryOperation);
221};
222
223// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700224// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800225class HVecMemoryOperation : public HVecOperation {
226 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100227 HVecMemoryOperation(ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100228 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800229 SideEffects side_effects,
230 size_t number_of_inputs,
231 size_t vector_length,
232 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100233 : HVecOperation(allocator,
234 packed_type,
235 side_effects,
236 number_of_inputs,
237 vector_length,
238 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100239 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100240 DCHECK_GE(number_of_inputs, 2u);
241 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800242
243 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
244
245 Alignment GetAlignment() const { return alignment_; }
246
Artem Serove1811ed2017-04-27 16:50:47 +0100247 HInstruction* GetArray() const { return InputAt(0); }
248 HInstruction* GetIndex() const { return InputAt(1); }
249
Aart Bikb79f4ac2017-07-10 10:10:37 -0700250 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
251 DCHECK(other->IsVecMemoryOperation());
252 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
253 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
254 }
255
Aart Bikf8f5a162017-02-06 15:35:29 -0800256 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
257
258 private:
259 Alignment alignment_;
260
261 DISALLOW_COPY_AND_ASSIGN(HVecMemoryOperation);
262};
263
Aart Bik0148de42017-09-05 09:25:01 -0700264// Packed type consistency checker ("same vector length" integral types may mix freely).
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100265inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700266 if (input->IsPhi()) {
267 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
268 }
Aart Bikd58bc322017-05-01 14:49:18 -0700269 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100270 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik4d1a9d42017-10-19 14:40:55 -0700271 DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
272 HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
Aart Bik46b6dbc2017-10-03 11:37:37 -0700273 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700274}
275
Aart Bikf8f5a162017-02-06 15:35:29 -0800276//
Aart Bik8de59162017-04-21 09:42:01 -0700277// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800278//
279
280// Replicates the given scalar into a vector,
281// viz. replicate(x) = [ x, .. , x ].
282class HVecReplicateScalar FINAL : public HVecUnaryOperation {
283 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100284 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800285 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100286 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800287 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700288 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100289 : HVecUnaryOperation(allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik8de59162017-04-21 09:42:01 -0700290 DCHECK(!scalar->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800291 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700292
293 // A replicate needs to stay in place, since SIMD registers are not
294 // kept alive across vector loop boundaries (yet).
295 bool CanBeMoved() const OVERRIDE { return false; }
296
Aart Bikf8f5a162017-02-06 15:35:29 -0800297 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700298
Aart Bikf8f5a162017-02-06 15:35:29 -0800299 private:
300 DISALLOW_COPY_AND_ASSIGN(HVecReplicateScalar);
301};
302
Aart Bik0148de42017-09-05 09:25:01 -0700303// Extracts a particular scalar from the given vector,
304// viz. extract[ x1, .. , xn ] = x_i.
305//
306// TODO: for now only i == 1 case supported.
307class HVecExtractScalar FINAL : public HVecUnaryOperation {
308 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100309 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700310 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100311 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700312 size_t vector_length,
313 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700314 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100315 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700316 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700317 DCHECK_LT(index, vector_length);
318 DCHECK_EQ(index, 0u);
319 }
320
321 // Yields a single component in the vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100322 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700323 return GetPackedType();
324 }
325
326 // An extract needs to stay in place, since SIMD registers are not
327 // kept alive across vector loop boundaries (yet).
328 bool CanBeMoved() const OVERRIDE { return false; }
329
330 DECLARE_INSTRUCTION(VecExtractScalar);
331
332 private:
333 DISALLOW_COPY_AND_ASSIGN(HVecExtractScalar);
334};
335
336// Reduces the given vector into the first element as sum/min/max,
337// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
338// and the "-" denotes "don't care" (implementation dependent).
339class HVecReduce FINAL : public HVecUnaryOperation {
340 public:
341 enum ReductionKind {
342 kSum = 1,
343 kMin = 2,
344 kMax = 3
345 };
346
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100347 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700348 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100349 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700350 size_t vector_length,
351 ReductionKind kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700352 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100353 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc),
Aart Bik0148de42017-09-05 09:25:01 -0700354 kind_(kind) {
355 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700356 }
357
Aart Bik0148de42017-09-05 09:25:01 -0700358 ReductionKind GetKind() const { return kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800359
Aart Bikb79f4ac2017-07-10 10:10:37 -0700360 bool CanBeMoved() const OVERRIDE { return true; }
361
Aart Bik0148de42017-09-05 09:25:01 -0700362 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
363 DCHECK(other->IsVecReduce());
364 const HVecReduce* o = other->AsVecReduce();
365 return HVecOperation::InstructionDataEquals(o) && GetKind() == o->GetKind();
366 }
367
368 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700369
Aart Bikf8f5a162017-02-06 15:35:29 -0800370 private:
Aart Bik0148de42017-09-05 09:25:01 -0700371 const ReductionKind kind_;
372
373 DISALLOW_COPY_AND_ASSIGN(HVecReduce);
Aart Bikf8f5a162017-02-06 15:35:29 -0800374};
375
376// Converts every component in the vector,
377// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
378class HVecCnv FINAL : public HVecUnaryOperation {
379 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100380 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800381 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100382 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800383 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700384 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100385 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800386 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700387 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800388 }
389
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100390 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
391 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800392
Aart Bikb79f4ac2017-07-10 10:10:37 -0700393 bool CanBeMoved() const OVERRIDE { return true; }
394
Aart Bikf8f5a162017-02-06 15:35:29 -0800395 DECLARE_INSTRUCTION(VecCnv);
396
397 private:
398 DISALLOW_COPY_AND_ASSIGN(HVecCnv);
399};
400
401// Negates every component in the vector,
402// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
403class HVecNeg FINAL : public HVecUnaryOperation {
404 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100405 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800406 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100407 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800408 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700409 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100410 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700411 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800412 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700413
414 bool CanBeMoved() const OVERRIDE { return true; }
415
Aart Bikf8f5a162017-02-06 15:35:29 -0800416 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700417
Aart Bikf8f5a162017-02-06 15:35:29 -0800418 private:
419 DISALLOW_COPY_AND_ASSIGN(HVecNeg);
420};
421
Aart Bik6daebeb2017-04-03 14:35:41 -0700422// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700423// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
424// for signed operand x.
Aart Bik6daebeb2017-04-03 14:35:41 -0700425class HVecAbs FINAL : public HVecUnaryOperation {
426 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100427 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700428 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100429 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700430 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700431 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100432 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700433 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700434 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700435
436 bool CanBeMoved() const OVERRIDE { return true; }
437
Aart Bik6daebeb2017-04-03 14:35:41 -0700438 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700439
Aart Bik6daebeb2017-04-03 14:35:41 -0700440 private:
441 DISALLOW_COPY_AND_ASSIGN(HVecAbs);
442};
443
Aart Bikf8f5a162017-02-06 15:35:29 -0800444// Bitwise- or boolean-nots every component in the vector,
445// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
446// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
447class HVecNot FINAL : public HVecUnaryOperation {
448 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100449 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800450 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100451 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800452 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700453 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100454 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800455 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800456 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700457
458 bool CanBeMoved() const OVERRIDE { return true; }
459
Aart Bikf8f5a162017-02-06 15:35:29 -0800460 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700461
Aart Bikf8f5a162017-02-06 15:35:29 -0800462 private:
463 DISALLOW_COPY_AND_ASSIGN(HVecNot);
464};
465
Aart Bik8de59162017-04-21 09:42:01 -0700466//
467// Definitions of concrete binary vector operations in HIR.
468//
469
Aart Bikf8f5a162017-02-06 15:35:29 -0800470// Adds every component in the two vectors,
471// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
472class HVecAdd FINAL : public HVecBinaryOperation {
473 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100474 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800475 HInstruction* left,
476 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100477 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800478 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700479 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100480 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700481 DCHECK(HasConsistentPackedTypes(left, packed_type));
482 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800483 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700484
485 bool CanBeMoved() const OVERRIDE { return true; }
486
Aart Bikf8f5a162017-02-06 15:35:29 -0800487 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700488
Aart Bikf8f5a162017-02-06 15:35:29 -0800489 private:
490 DISALLOW_COPY_AND_ASSIGN(HVecAdd);
491};
492
Aart Bikf3e61ee2017-04-12 17:09:20 -0700493// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700494// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
495// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik46b6dbc2017-10-03 11:37:37 -0700496// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700497class HVecHalvingAdd FINAL : public HVecBinaryOperation {
498 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100499 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700500 HInstruction* left,
501 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100502 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700503 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700504 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700505 bool is_unsigned,
506 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100507 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100508 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
509 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
510 DCHECK(!is_unsigned ||
511 packed_type == DataType::Type::kInt32 ||
512 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700513 DCHECK(HasConsistentPackedTypes(left, packed_type));
514 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700515 SetPackedFlag<kFieldHAddIsUnsigned>(is_unsigned);
516 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700517 }
518
Aart Bikdb14fcf2017-04-25 15:53:58 -0700519 bool IsUnsigned() const { return GetPackedFlag<kFieldHAddIsUnsigned>(); }
520 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700521
Aart Bikb79f4ac2017-07-10 10:10:37 -0700522 bool CanBeMoved() const OVERRIDE { return true; }
523
524 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
525 DCHECK(other->IsVecHalvingAdd());
526 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
527 return HVecOperation::InstructionDataEquals(o) &&
528 IsUnsigned() == o->IsUnsigned() &&
529 IsRounded() == o->IsRounded();
530 }
531
Aart Bikf3e61ee2017-04-12 17:09:20 -0700532 DECLARE_INSTRUCTION(VecHalvingAdd);
533
534 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700535 // Additional packed bits.
536 static constexpr size_t kFieldHAddIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
537 static constexpr size_t kFieldHAddIsRounded = kFieldHAddIsUnsigned + 1;
538 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
539 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700540
541 DISALLOW_COPY_AND_ASSIGN(HVecHalvingAdd);
542};
543
Aart Bikf8f5a162017-02-06 15:35:29 -0800544// Subtracts every component in the two vectors,
545// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
546class HVecSub FINAL : public HVecBinaryOperation {
547 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100548 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800549 HInstruction* left,
550 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100551 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800552 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700553 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100554 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700555 DCHECK(HasConsistentPackedTypes(left, packed_type));
556 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800557 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700558
559 bool CanBeMoved() const OVERRIDE { return true; }
560
Aart Bikf8f5a162017-02-06 15:35:29 -0800561 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700562
Aart Bikf8f5a162017-02-06 15:35:29 -0800563 private:
564 DISALLOW_COPY_AND_ASSIGN(HVecSub);
565};
566
567// Multiplies every component in the two vectors,
568// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
569class HVecMul FINAL : public HVecBinaryOperation {
570 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100571 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800572 HInstruction* left,
573 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100574 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800575 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700576 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100577 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700578 DCHECK(HasConsistentPackedTypes(left, packed_type));
579 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800580 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700581
582 bool CanBeMoved() const OVERRIDE { return true; }
583
Aart Bikf8f5a162017-02-06 15:35:29 -0800584 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700585
Aart Bikf8f5a162017-02-06 15:35:29 -0800586 private:
587 DISALLOW_COPY_AND_ASSIGN(HVecMul);
588};
589
590// Divides every component in the two vectors,
591// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
592class HVecDiv FINAL : public HVecBinaryOperation {
593 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100594 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800595 HInstruction* left,
596 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100597 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800598 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700599 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100600 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700601 DCHECK(HasConsistentPackedTypes(left, packed_type));
602 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800603 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700604
605 bool CanBeMoved() const OVERRIDE { return true; }
606
Aart Bikf8f5a162017-02-06 15:35:29 -0800607 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700608
Aart Bikf8f5a162017-02-06 15:35:29 -0800609 private:
610 DISALLOW_COPY_AND_ASSIGN(HVecDiv);
611};
612
Aart Bikf3e61ee2017-04-12 17:09:20 -0700613// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700614// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
615// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700616class HVecMin FINAL : public HVecBinaryOperation {
617 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100618 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700619 HInstruction* left,
620 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100621 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700622 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700623 bool is_unsigned,
624 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100625 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100626 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
627 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
628 DCHECK(!is_unsigned ||
629 packed_type == DataType::Type::kInt32 ||
630 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700631 DCHECK(HasConsistentPackedTypes(left, packed_type));
632 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikc8e93c72017-05-10 10:49:22 -0700633 SetPackedFlag<kFieldMinOpIsUnsigned>(is_unsigned);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700634 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700635
636 bool IsUnsigned() const { return GetPackedFlag<kFieldMinOpIsUnsigned>(); }
637
Aart Bikb79f4ac2017-07-10 10:10:37 -0700638 bool CanBeMoved() const OVERRIDE { return true; }
639
640 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
641 DCHECK(other->IsVecMin());
642 const HVecMin* o = other->AsVecMin();
643 return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned();
644 }
645
Aart Bikf3e61ee2017-04-12 17:09:20 -0700646 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700647
Aart Bikf3e61ee2017-04-12 17:09:20 -0700648 private:
Aart Bikc8e93c72017-05-10 10:49:22 -0700649 // Additional packed bits.
650 static constexpr size_t kFieldMinOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
651 static constexpr size_t kNumberOfMinOpPackedBits = kFieldMinOpIsUnsigned + 1;
652 static_assert(kNumberOfMinOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
653
Aart Bikf3e61ee2017-04-12 17:09:20 -0700654 DISALLOW_COPY_AND_ASSIGN(HVecMin);
655};
656
657// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700658// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
659// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700660class HVecMax FINAL : public HVecBinaryOperation {
661 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100662 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700663 HInstruction* left,
664 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100665 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700666 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700667 bool is_unsigned,
668 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100669 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100670 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
671 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
672 DCHECK(!is_unsigned ||
673 packed_type == DataType::Type::kInt32 ||
674 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700675 DCHECK(HasConsistentPackedTypes(left, packed_type));
676 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikc8e93c72017-05-10 10:49:22 -0700677 SetPackedFlag<kFieldMaxOpIsUnsigned>(is_unsigned);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700678 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700679
680 bool IsUnsigned() const { return GetPackedFlag<kFieldMaxOpIsUnsigned>(); }
681
Aart Bikb79f4ac2017-07-10 10:10:37 -0700682 bool CanBeMoved() const OVERRIDE { return true; }
683
684 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
685 DCHECK(other->IsVecMax());
686 const HVecMax* o = other->AsVecMax();
687 return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned();
688 }
689
Aart Bikf3e61ee2017-04-12 17:09:20 -0700690 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700691
Aart Bikf3e61ee2017-04-12 17:09:20 -0700692 private:
Aart Bikc8e93c72017-05-10 10:49:22 -0700693 // Additional packed bits.
694 static constexpr size_t kFieldMaxOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
695 static constexpr size_t kNumberOfMaxOpPackedBits = kFieldMaxOpIsUnsigned + 1;
696 static_assert(kNumberOfMaxOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
697
Aart Bikf3e61ee2017-04-12 17:09:20 -0700698 DISALLOW_COPY_AND_ASSIGN(HVecMax);
699};
700
Aart Bikf8f5a162017-02-06 15:35:29 -0800701// Bitwise-ands every component in the two vectors,
702// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
703class HVecAnd FINAL : public HVecBinaryOperation {
704 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100705 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800706 HInstruction* left,
707 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100708 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800709 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700710 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100711 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800712 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800713 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700714
715 bool CanBeMoved() const OVERRIDE { return true; }
716
Aart Bikf8f5a162017-02-06 15:35:29 -0800717 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700718
Aart Bikf8f5a162017-02-06 15:35:29 -0800719 private:
720 DISALLOW_COPY_AND_ASSIGN(HVecAnd);
721};
722
723// Bitwise-and-nots every component in the two vectors,
724// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
725class HVecAndNot FINAL : public HVecBinaryOperation {
726 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100727 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800728 HInstruction* left,
729 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100730 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800731 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700732 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100733 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800734 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800735 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700736
737 bool CanBeMoved() const OVERRIDE { return true; }
738
Aart Bikf8f5a162017-02-06 15:35:29 -0800739 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700740
Aart Bikf8f5a162017-02-06 15:35:29 -0800741 private:
742 DISALLOW_COPY_AND_ASSIGN(HVecAndNot);
743};
744
745// Bitwise-ors every component in the two vectors,
746// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
747class HVecOr FINAL : public HVecBinaryOperation {
748 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100749 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800750 HInstruction* left,
751 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100752 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800753 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700754 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100755 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800756 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800757 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700758
759 bool CanBeMoved() const OVERRIDE { return true; }
760
Aart Bikf8f5a162017-02-06 15:35:29 -0800761 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700762
Aart Bikf8f5a162017-02-06 15:35:29 -0800763 private:
764 DISALLOW_COPY_AND_ASSIGN(HVecOr);
765};
766
767// Bitwise-xors every component in the two vectors,
768// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
769class HVecXor FINAL : public HVecBinaryOperation {
770 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100771 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800772 HInstruction* left,
773 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100774 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800775 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700776 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100777 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800778 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800779 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700780
781 bool CanBeMoved() const OVERRIDE { return true; }
782
Aart Bikf8f5a162017-02-06 15:35:29 -0800783 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700784
Aart Bikf8f5a162017-02-06 15:35:29 -0800785 private:
786 DISALLOW_COPY_AND_ASSIGN(HVecXor);
787};
788
789// Logically shifts every component in the vector left by the given distance,
790// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
791class HVecShl FINAL : public HVecBinaryOperation {
792 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100793 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800794 HInstruction* left,
795 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100796 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800797 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700798 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100799 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700800 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800801 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700802
803 bool CanBeMoved() const OVERRIDE { return true; }
804
Aart Bikf8f5a162017-02-06 15:35:29 -0800805 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700806
Aart Bikf8f5a162017-02-06 15:35:29 -0800807 private:
808 DISALLOW_COPY_AND_ASSIGN(HVecShl);
809};
810
811// Arithmetically shifts every component in the vector right by the given distance,
812// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
813class HVecShr FINAL : public HVecBinaryOperation {
814 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100815 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800816 HInstruction* left,
817 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100818 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800819 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700820 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100821 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700822 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800823 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700824
825 bool CanBeMoved() const OVERRIDE { return true; }
826
Aart Bikf8f5a162017-02-06 15:35:29 -0800827 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700828
Aart Bikf8f5a162017-02-06 15:35:29 -0800829 private:
830 DISALLOW_COPY_AND_ASSIGN(HVecShr);
831};
832
833// Logically shifts every component in the vector right by the given distance,
834// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
835class HVecUShr FINAL : public HVecBinaryOperation {
836 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100837 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800838 HInstruction* left,
839 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100840 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800841 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700842 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100843 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700844 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800845 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700846
847 bool CanBeMoved() const OVERRIDE { return true; }
848
Aart Bikf8f5a162017-02-06 15:35:29 -0800849 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700850
Aart Bikf8f5a162017-02-06 15:35:29 -0800851 private:
852 DISALLOW_COPY_AND_ASSIGN(HVecUShr);
853};
854
Aart Bik8de59162017-04-21 09:42:01 -0700855//
856// Definitions of concrete miscellaneous vector operations in HIR.
857//
858
859// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700860// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
861// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Aart Bik8de59162017-04-21 09:42:01 -0700862class HVecSetScalars FINAL : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700863 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100864 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700865 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100866 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700867 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700868 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700869 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100870 : HVecOperation(allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700871 packed_type,
872 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700873 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700874 vector_length,
875 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700876 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik5e3afa92017-09-20 14:11:11 -0700877 DCHECK(!scalars[i]->IsVecOperation() || scalars[i]->IsVecExtractScalar());
Aart Bik8de59162017-04-21 09:42:01 -0700878 SetRawInputAt(0, scalars[i]);
879 }
880 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700881
882 // Setting scalars needs to stay in place, since SIMD registers are not
883 // kept alive across vector loop boundaries (yet).
884 bool CanBeMoved() const OVERRIDE { return false; }
885
Aart Bik8de59162017-04-21 09:42:01 -0700886 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700887
Aart Bik8de59162017-04-21 09:42:01 -0700888 private:
889 DISALLOW_COPY_AND_ASSIGN(HVecSetScalars);
890};
891
Aart Bikdbbac8f2017-09-01 13:06:08 -0700892// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
893// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Artem Serovf34dd202017-04-10 17:41:46 +0100894class HVecMultiplyAccumulate FINAL : public HVecOperation {
895 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100896 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100897 InstructionKind op,
898 HInstruction* accumulator,
899 HInstruction* mul_left,
900 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100901 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +0100902 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700903 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100904 : HVecOperation(allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100905 packed_type,
906 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700907 /* number_of_inputs */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +0100908 vector_length,
909 dex_pc),
910 op_kind_(op) {
911 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -0700912 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
913 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
914 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700915 SetRawInputAt(0, accumulator);
916 SetRawInputAt(1, mul_left);
917 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +0100918 }
919
Nicolas Geoffray9858bf72017-07-08 12:34:55 +0000920 bool CanBeMoved() const OVERRIDE { return true; }
921
Artem Serovf34dd202017-04-10 17:41:46 +0100922 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700923 DCHECK(other->IsVecMultiplyAccumulate());
924 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
925 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +0100926 }
927
928 InstructionKind GetOpKind() const { return op_kind_; }
929
930 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
931
932 private:
933 // Indicates if this is a MADD or MSUB.
934 const InstructionKind op_kind_;
935
936 DISALLOW_COPY_AND_ASSIGN(HVecMultiplyAccumulate);
937};
938
Aart Bikdbbac8f2017-09-01 13:06:08 -0700939// Takes the absolute difference of two vectors, and adds the results to
940// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700941// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -0700942// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -0700943// for m <= n, non-overlapping sums, and signed operands x, y.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700944class HVecSADAccumulate FINAL : public HVecOperation {
945 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100946 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700947 HInstruction* accumulator,
948 HInstruction* sad_left,
949 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100950 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700951 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700952 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100953 : HVecOperation(allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700954 packed_type,
955 SideEffects::None(),
956 /* number_of_inputs */ 3,
957 vector_length,
958 dex_pc) {
959 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
960 DCHECK(sad_left->IsVecOperation());
961 DCHECK(sad_right->IsVecOperation());
Vladimir Marko61b92282017-10-11 13:23:17 +0100962 DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
963 ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700964 SetRawInputAt(0, accumulator);
965 SetRawInputAt(1, sad_left);
966 SetRawInputAt(2, sad_right);
967 }
968
969 DECLARE_INSTRUCTION(VecSADAccumulate);
970
971 private:
972 DISALLOW_COPY_AND_ASSIGN(HVecSADAccumulate);
973};
974
Aart Bikf8f5a162017-02-06 15:35:29 -0800975// Loads a vector from memory, viz. load(mem, 1)
976// yield the vector [ mem(1), .. , mem(n) ].
977class HVecLoad FINAL : public HVecMemoryOperation {
978 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100979 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800980 HInstruction* base,
981 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100982 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100983 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -0800984 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -0700985 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700986 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100987 : HVecMemoryOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800988 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100989 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -0700990 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800991 vector_length,
992 dex_pc) {
993 SetRawInputAt(0, base);
994 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -0700995 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -0800996 }
Aart Bikdb14fcf2017-04-25 15:53:58 -0700997
998 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
999
Aart Bikb79f4ac2017-07-10 10:10:37 -07001000 bool CanBeMoved() const OVERRIDE { return true; }
1001
1002 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
1003 DCHECK(other->IsVecLoad());
1004 const HVecLoad* o = other->AsVecLoad();
1005 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
1006 }
1007
1008 DECLARE_INSTRUCTION(VecLoad);
1009
Aart Bikf8f5a162017-02-06 15:35:29 -08001010 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -07001011 // Additional packed bits.
1012 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
1013 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
1014 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
1015
Aart Bikf8f5a162017-02-06 15:35:29 -08001016 DISALLOW_COPY_AND_ASSIGN(HVecLoad);
1017};
1018
1019// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1020// sets mem(1) = x1, .. , mem(n) = xn.
1021class HVecStore FINAL : public HVecMemoryOperation {
1022 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001023 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001024 HInstruction* base,
1025 HInstruction* index,
1026 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001027 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001028 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001029 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001030 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001031 : HVecMemoryOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001032 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001033 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001034 /* number_of_inputs */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001035 vector_length,
1036 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001037 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001038 SetRawInputAt(0, base);
1039 SetRawInputAt(1, index);
1040 SetRawInputAt(2, value);
1041 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001042
1043 // A store needs to stay in place.
1044 bool CanBeMoved() const OVERRIDE { return false; }
1045
Aart Bikf8f5a162017-02-06 15:35:29 -08001046 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001047
Aart Bikf8f5a162017-02-06 15:35:29 -08001048 private:
1049 DISALLOW_COPY_AND_ASSIGN(HVecStore);
1050};
1051
1052} // namespace art
1053
1054#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_