blob: 9c6b422c871052ad7fe6c7d4244dab4f63232b5f [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
Vladimir Marko0a516052019-10-14 13:00:44 +000024namespace art {
Aart Bikf8f5a162017-02-06 15:35:29 -080025
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
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +053074 HVecOperation(InstructionKind kind,
75 ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010076 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -080077 SideEffects side_effects,
78 size_t number_of_inputs,
79 size_t vector_length,
80 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +053081 : HVariableInputSizeInstruction(kind,
Vladimir Markobd785672018-05-03 17:09:09 +010082 kSIMDType,
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +053083 side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -080084 dex_pc,
Vladimir Markoe764d2e2017-10-05 14:35:55 +010085 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -080086 number_of_inputs,
87 kArenaAllocVectorNode),
88 vector_length_(vector_length) {
Vladimir Markobd785672018-05-03 17:09:09 +010089 SetPackedField<PackedTypeField>(packed_type);
Artem Serov07718842020-02-24 18:51:42 +000090 // By default vector operations are not predicated.
91 SetPackedField<PredicationKindField>(PredicationKind::kNotPredicated);
Aart Bikf8f5a162017-02-06 15:35:29 -080092 DCHECK_LT(1u, vector_length);
93 }
94
Artem Serov07718842020-02-24 18:51:42 +000095 // Predicated instructions execute a corresponding operation only on vector elements which are
96 // active (governing predicate is true for that element); the following modes determine what
97 // is happening with inactive elements.
98 //
99 // See HVecPredSetOperation.
100 enum class PredicationKind {
101 kNotPredicated, // Instruction doesn't take any predicate as an input.
102 kZeroingForm, // Inactive elements are reset to zero.
103 kMergingForm, // Inactive elements keep their value.
104 kLast = kMergingForm,
105 };
106
107 PredicationKind GetPredicationKind() const { return GetPackedField<PredicationKindField>(); }
108
109 // Returns whether the vector operation must be predicated in predicated SIMD mode
110 // (see CodeGenerator::SupportsPredicatedSIMD). The method reflects semantics of
111 // the instruction class rather than the state of a particular instruction instance.
112 //
113 // This property is introduced for robustness purpose - to maintain and check the invariant:
114 // all instructions of the same vector operation class must be either all predicated or all
115 // not predicated (depending on the predicated SIMD support) in a correct graph.
116 virtual bool MustBePredicatedInPredicatedSIMDMode() {
117 return true;
118 }
119
120 bool IsPredicated() const {
121 return GetPredicationKind() != PredicationKind::kNotPredicated;
122 }
123
124 // See HVecPredSetOperation.
125 void SetGoverningPredicate(HInstruction* input, PredicationKind pred_kind) {
126 DCHECK(!IsPredicated());
127 DCHECK(input->IsVecPredSetOperation());
128 AddInput(input);
129 SetPackedField<PredicationKindField>(pred_kind);
130 DCHECK(IsPredicated());
131 }
132
133 void SetMergingGoverningPredicate(HInstruction* input) {
134 SetGoverningPredicate(input, PredicationKind::kMergingForm);
135 }
136 void SetZeroingGoverningPredicate(HInstruction* input) {
137 SetGoverningPredicate(input, PredicationKind::kZeroingForm);
138 }
139
140 // See HVecPredSetOperation.
141 HVecPredSetOperation* GetGoverningPredicate() const {
142 DCHECK(IsPredicated());
143 HInstruction* pred_input = InputAt(InputCount() - 1);
144 DCHECK(pred_input->IsVecPredSetOperation());
145 return pred_input->AsVecPredSetOperation();
146 }
147
Aart Bikf8f5a162017-02-06 15:35:29 -0800148 // Returns the number of elements packed in a vector.
149 size_t GetVectorLength() const {
150 return vector_length_;
151 }
152
153 // Returns the number of bytes in a full vector.
154 size_t GetVectorNumberOfBytes() const {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100155 return vector_length_ * DataType::Size(GetPackedType());
Aart Bikf8f5a162017-02-06 15:35:29 -0800156 }
157
Aart Bikf8f5a162017-02-06 15:35:29 -0800158 // Returns the true component type packed in a vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100159 DataType::Type GetPackedType() const {
Vladimir Markobd785672018-05-03 17:09:09 +0100160 return GetPackedField<PackedTypeField>();
Aart Bikf8f5a162017-02-06 15:35:29 -0800161 }
162
Aart Bikb79f4ac2017-07-10 10:10:37 -0700163 // Assumes vector nodes cannot be moved by default. Each concrete implementation
164 // that can be moved should override this method and return true.
Artem Serov89ff8b22017-11-20 11:51:05 +0000165 //
166 // Note: similar approach is used for instruction scheduling (if it is turned on for the target):
167 // by default HScheduler::IsSchedulable returns false for a particular HVecOperation.
168 // HScheduler${ARCH}::IsSchedulable can be overridden to return true for an instruction (see
169 // scheduler_arm64.h for example) if it is safe to schedule it; in this case one *must* also
170 // look at/update HScheduler${ARCH}::IsSchedulingBarrier for this instruction.
171 //
172 // Note: For newly introduced vector instructions HScheduler${ARCH}::IsSchedulingBarrier must be
173 // altered to return true if the instruction might reside outside the SIMD loop body since SIMD
174 // registers are not kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100175 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700176
177 // Tests if all data of a vector node (vector length and packed type) is equal.
178 // Each concrete implementation that adds more fields should test equality of
179 // those fields in its own method *and* call all super methods.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100180 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700181 DCHECK(other->IsVecOperation());
182 const HVecOperation* o = other->AsVecOperation();
183 return GetVectorLength() == o->GetVectorLength() && GetPackedType() == o->GetPackedType();
184 }
185
Aart Bik46b6dbc2017-10-03 11:37:37 -0700186 // Maps an integral type to the same-size signed type and leaves other types alone.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700187 static DataType::Type ToSignedType(DataType::Type type) {
188 switch (type) {
189 case DataType::Type::kBool: // 1-byte storage unit
190 case DataType::Type::kUint8:
191 return DataType::Type::kInt8;
192 case DataType::Type::kUint16:
193 return DataType::Type::kInt16;
194 default:
195 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
196 return type;
197 }
198 }
199
Aart Bik4d1a9d42017-10-19 14:40:55 -0700200 // Maps an integral type to the same-size unsigned type and leaves other types alone.
201 static DataType::Type ToUnsignedType(DataType::Type type) {
202 switch (type) {
203 case DataType::Type::kBool: // 1-byte storage unit
204 case DataType::Type::kInt8:
205 return DataType::Type::kUint8;
206 case DataType::Type::kInt16:
207 return DataType::Type::kUint16;
208 default:
209 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
210 return type;
211 }
212 }
213
Aart Bik66c158e2018-01-31 12:55:04 -0800214 // Maps an integral type to the same-size (un)signed type. Leaves other types alone.
215 static DataType::Type ToProperType(DataType::Type type, bool is_unsigned) {
216 return is_unsigned ? ToUnsignedType(type) : ToSignedType(type);
217 }
218
Aart Bik2dd7b672017-12-07 11:11:22 -0800219 // Helper method to determine if an instruction returns a SIMD value.
220 // TODO: This method is needed until we introduce SIMD as proper type.
221 static bool ReturnsSIMDValue(HInstruction* instruction) {
222 if (instruction->IsVecOperation()) {
223 return !instruction->IsVecExtractScalar(); // only scalar returning vec op
224 } else if (instruction->IsPhi()) {
Aart Bik3f8e02c2018-04-10 11:55:00 -0700225 // Vectorizer only uses Phis in reductions, so checking for a 2-way phi
226 // with a direct vector operand as second argument suffices.
Aart Bik2dd7b672017-12-07 11:11:22 -0800227 return
228 instruction->GetType() == kSIMDType &&
Aart Bik3f8e02c2018-04-10 11:55:00 -0700229 instruction->InputCount() == 2 &&
230 instruction->InputAt(1)->IsVecOperation();
Aart Bik2dd7b672017-12-07 11:11:22 -0800231 }
232 return false;
233 }
234
Aart Bikf8f5a162017-02-06 15:35:29 -0800235 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
236
Aart Bikdb14fcf2017-04-25 15:53:58 -0700237 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800238 // Additional packed bits.
Artem Serov07718842020-02-24 18:51:42 +0000239 static constexpr size_t kPredicationKind = HInstruction::kNumberOfGenericPackedBits;
240 static constexpr size_t kPredicationKindSize =
241 MinimumBitsToStore(static_cast<size_t>(PredicationKind::kLast));
242 static constexpr size_t kFieldPackedType = kPredicationKind + kPredicationKindSize;
Vladimir Markobd785672018-05-03 17:09:09 +0100243 static constexpr size_t kFieldPackedTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100244 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Vladimir Markobd785672018-05-03 17:09:09 +0100245 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldPackedType + kFieldPackedTypeSize;
Aart Bikf8f5a162017-02-06 15:35:29 -0800246 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Markobd785672018-05-03 17:09:09 +0100247 using PackedTypeField = BitField<DataType::Type, kFieldPackedType, kFieldPackedTypeSize>;
Artem Serov07718842020-02-24 18:51:42 +0000248 using PredicationKindField = BitField<PredicationKind, kPredicationKind, kPredicationKindSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800249
Artem Serovcced8ba2017-07-19 18:18:09 +0100250 DEFAULT_COPY_CONSTRUCTOR(VecOperation);
251
Aart Bikdb14fcf2017-04-25 15:53:58 -0700252 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800253 const size_t vector_length_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800254};
255
256// Abstraction of a unary vector operation.
257class HVecUnaryOperation : public HVecOperation {
258 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530259 HVecUnaryOperation(InstructionKind kind,
260 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700261 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100262 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800263 size_t vector_length,
264 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530265 : HVecOperation(kind,
266 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800267 packed_type,
268 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -0800269 /* number_of_inputs= */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800270 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700271 dex_pc) {
272 SetRawInputAt(0, input);
273 }
274
275 HInstruction* GetInput() const { return InputAt(0); }
276
Aart Bikf8f5a162017-02-06 15:35:29 -0800277 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700278
Artem Serovcced8ba2017-07-19 18:18:09 +0100279 protected:
280 DEFAULT_COPY_CONSTRUCTOR(VecUnaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800281};
282
283// Abstraction of a binary vector operation.
284class HVecBinaryOperation : public HVecOperation {
285 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530286 HVecBinaryOperation(InstructionKind kind,
287 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700288 HInstruction* left,
289 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100290 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800291 size_t vector_length,
292 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530293 : HVecOperation(kind,
294 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800295 packed_type,
296 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -0800297 /* number_of_inputs= */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800298 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700299 dex_pc) {
300 SetRawInputAt(0, left);
301 SetRawInputAt(1, right);
302 }
Artem Serovf34dd202017-04-10 17:41:46 +0100303
304 HInstruction* GetLeft() const { return InputAt(0); }
305 HInstruction* GetRight() const { return InputAt(1); }
306
Aart Bikf8f5a162017-02-06 15:35:29 -0800307 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700308
Artem Serovcced8ba2017-07-19 18:18:09 +0100309 protected:
310 DEFAULT_COPY_CONSTRUCTOR(VecBinaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800311};
312
313// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700314// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800315class HVecMemoryOperation : public HVecOperation {
316 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530317 HVecMemoryOperation(InstructionKind kind,
318 ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100319 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800320 SideEffects side_effects,
321 size_t number_of_inputs,
322 size_t vector_length,
323 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530324 : HVecOperation(kind,
325 allocator,
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100326 packed_type,
327 side_effects,
328 number_of_inputs,
329 vector_length,
330 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100331 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100332 DCHECK_GE(number_of_inputs, 2u);
333 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800334
335 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
336
337 Alignment GetAlignment() const { return alignment_; }
338
Artem Serove1811ed2017-04-27 16:50:47 +0100339 HInstruction* GetArray() const { return InputAt(0); }
340 HInstruction* GetIndex() const { return InputAt(1); }
341
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100342 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700343 DCHECK(other->IsVecMemoryOperation());
344 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
345 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
346 }
347
Aart Bikf8f5a162017-02-06 15:35:29 -0800348 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
349
Artem Serovcced8ba2017-07-19 18:18:09 +0100350 protected:
351 DEFAULT_COPY_CONSTRUCTOR(VecMemoryOperation);
352
Aart Bikf8f5a162017-02-06 15:35:29 -0800353 private:
354 Alignment alignment_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800355};
356
Aart Bik0148de42017-09-05 09:25:01 -0700357// Packed type consistency checker ("same vector length" integral types may mix freely).
Aart Bik66c158e2018-01-31 12:55:04 -0800358// Tests relaxed type consistency in which packed same-size integral types can co-exist,
359// but other type mixes are an error.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100360inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700361 if (input->IsPhi()) {
362 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
363 }
Aart Bikd58bc322017-05-01 14:49:18 -0700364 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100365 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik4d1a9d42017-10-19 14:40:55 -0700366 DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
367 HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
Aart Bik46b6dbc2017-10-03 11:37:37 -0700368 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700369}
370
Aart Bikf8f5a162017-02-06 15:35:29 -0800371//
Aart Bik8de59162017-04-21 09:42:01 -0700372// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800373//
374
375// Replicates the given scalar into a vector,
376// viz. replicate(x) = [ x, .. , x ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100377class HVecReplicateScalar final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800378 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100379 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800380 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100381 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800382 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700383 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530384 : HVecUnaryOperation(
385 kVecReplicateScalar, allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik5a0eb0c2018-03-16 15:00:19 -0700386 DCHECK(!ReturnsSIMDValue(scalar));
Aart Bikf8f5a162017-02-06 15:35:29 -0800387 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700388
389 // A replicate needs to stay in place, since SIMD registers are not
390 // kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100391 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700392
Aart Bikf8f5a162017-02-06 15:35:29 -0800393 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700394
Artem Serovcced8ba2017-07-19 18:18:09 +0100395 protected:
396 DEFAULT_COPY_CONSTRUCTOR(VecReplicateScalar);
Aart Bikf8f5a162017-02-06 15:35:29 -0800397};
398
Aart Bik0148de42017-09-05 09:25:01 -0700399// Extracts a particular scalar from the given vector,
400// viz. extract[ x1, .. , xn ] = x_i.
401//
402// TODO: for now only i == 1 case supported.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100403class HVecExtractScalar final : public HVecUnaryOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700404 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100405 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700406 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100407 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700408 size_t vector_length,
409 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700410 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530411 : HVecUnaryOperation(
412 kVecExtractScalar, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700413 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700414 DCHECK_LT(index, vector_length);
415 DCHECK_EQ(index, 0u);
Vladimir Markobd785672018-05-03 17:09:09 +0100416 // Yields a single component in the vector.
417 // Overrides the kSIMDType set by the VecOperation constructor.
418 SetPackedField<TypeField>(packed_type);
Aart Bik0148de42017-09-05 09:25:01 -0700419 }
420
421 // An extract needs to stay in place, since SIMD registers are not
422 // kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100423 bool CanBeMoved() const override { return false; }
Aart Bik0148de42017-09-05 09:25:01 -0700424
425 DECLARE_INSTRUCTION(VecExtractScalar);
426
Artem Serovcced8ba2017-07-19 18:18:09 +0100427 protected:
428 DEFAULT_COPY_CONSTRUCTOR(VecExtractScalar);
Aart Bik0148de42017-09-05 09:25:01 -0700429};
430
431// Reduces the given vector into the first element as sum/min/max,
432// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
433// and the "-" denotes "don't care" (implementation dependent).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100434class HVecReduce final : public HVecUnaryOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700435 public:
436 enum ReductionKind {
437 kSum = 1,
438 kMin = 2,
439 kMax = 3
440 };
441
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100442 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700443 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100444 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700445 size_t vector_length,
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000446 ReductionKind reduction_kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700447 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530448 : HVecUnaryOperation(kVecReduce, allocator, input, packed_type, vector_length, dex_pc),
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000449 reduction_kind_(reduction_kind) {
Aart Bik0148de42017-09-05 09:25:01 -0700450 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700451 }
452
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000453 ReductionKind GetReductionKind() const { return reduction_kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800454
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100455 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700456
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100457 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bik0148de42017-09-05 09:25:01 -0700458 DCHECK(other->IsVecReduce());
459 const HVecReduce* o = other->AsVecReduce();
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000460 return HVecOperation::InstructionDataEquals(o) && GetReductionKind() == o->GetReductionKind();
Aart Bik0148de42017-09-05 09:25:01 -0700461 }
462
463 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700464
Artem Serovcced8ba2017-07-19 18:18:09 +0100465 protected:
466 DEFAULT_COPY_CONSTRUCTOR(VecReduce);
467
Aart Bikf8f5a162017-02-06 15:35:29 -0800468 private:
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000469 const ReductionKind reduction_kind_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800470};
471
472// Converts every component in the vector,
473// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100474class HVecCnv final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800475 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100476 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800477 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100478 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800479 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700480 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530481 : HVecUnaryOperation(kVecCnv, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800482 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700483 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800484 }
485
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100486 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
487 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800488
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100489 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700490
Aart Bikf8f5a162017-02-06 15:35:29 -0800491 DECLARE_INSTRUCTION(VecCnv);
492
Artem Serovcced8ba2017-07-19 18:18:09 +0100493 protected:
494 DEFAULT_COPY_CONSTRUCTOR(VecCnv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800495};
496
497// Negates every component in the vector,
498// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100499class HVecNeg final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800500 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100501 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800502 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100503 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800504 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700505 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530506 : HVecUnaryOperation(kVecNeg, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700507 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800508 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700509
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100510 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700511
Aart Bikf8f5a162017-02-06 15:35:29 -0800512 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700513
Artem Serovcced8ba2017-07-19 18:18:09 +0100514 protected:
515 DEFAULT_COPY_CONSTRUCTOR(VecNeg);
Aart Bikf8f5a162017-02-06 15:35:29 -0800516};
517
Aart Bik6daebeb2017-04-03 14:35:41 -0700518// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700519// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
520// for signed operand x.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100521class HVecAbs final : public HVecUnaryOperation {
Aart Bik6daebeb2017-04-03 14:35:41 -0700522 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100523 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700524 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100525 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700526 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700527 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530528 : HVecUnaryOperation(kVecAbs, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700529 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700530 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700531
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100532 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700533
Aart Bik6daebeb2017-04-03 14:35:41 -0700534 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700535
Artem Serovcced8ba2017-07-19 18:18:09 +0100536 protected:
537 DEFAULT_COPY_CONSTRUCTOR(VecAbs);
Aart Bik6daebeb2017-04-03 14:35:41 -0700538};
539
Aart Bikf8f5a162017-02-06 15:35:29 -0800540// Bitwise- or boolean-nots every component in the vector,
541// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
542// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100543class HVecNot final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800544 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100545 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800546 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100547 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800548 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700549 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530550 : HVecUnaryOperation(kVecNot, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800551 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800552 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700553
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100554 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700555
Aart Bikf8f5a162017-02-06 15:35:29 -0800556 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700557
Artem Serovcced8ba2017-07-19 18:18:09 +0100558 protected:
559 DEFAULT_COPY_CONSTRUCTOR(VecNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800560};
561
Aart Bik8de59162017-04-21 09:42:01 -0700562//
563// Definitions of concrete binary vector operations in HIR.
564//
565
Aart Bikf8f5a162017-02-06 15:35:29 -0800566// Adds every component in the two vectors,
567// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100568class HVecAdd final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800569 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100570 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800571 HInstruction* left,
572 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100573 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800574 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700575 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530576 : HVecBinaryOperation(kVecAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700577 DCHECK(HasConsistentPackedTypes(left, packed_type));
578 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800579 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700580
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100581 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700582
Aart Bikf8f5a162017-02-06 15:35:29 -0800583 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700584
Artem Serovcced8ba2017-07-19 18:18:09 +0100585 protected:
586 DEFAULT_COPY_CONSTRUCTOR(VecAdd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800587};
588
Aart Bik29aa0822018-03-08 11:28:00 -0800589// Adds every component in the two vectors using saturation arithmetic,
590// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 +_sat y1, .. , xn +_sat yn ]
591// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100592class HVecSaturationAdd final : public HVecBinaryOperation {
Aart Bik29aa0822018-03-08 11:28:00 -0800593 public:
594 HVecSaturationAdd(ArenaAllocator* allocator,
595 HInstruction* left,
596 HInstruction* right,
597 DataType::Type packed_type,
598 size_t vector_length,
599 uint32_t dex_pc)
600 : HVecBinaryOperation(
601 kVecSaturationAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
602 DCHECK(HasConsistentPackedTypes(left, packed_type));
603 DCHECK(HasConsistentPackedTypes(right, packed_type));
604 }
605
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100606 bool CanBeMoved() const override { return true; }
Aart Bik29aa0822018-03-08 11:28:00 -0800607
608 DECLARE_INSTRUCTION(VecSaturationAdd);
609
610 protected:
611 DEFAULT_COPY_CONSTRUCTOR(VecSaturationAdd);
612};
613
Aart Bikf3e61ee2017-04-12 17:09:20 -0700614// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700615// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
616// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik66c158e2018-01-31 12:55:04 -0800617// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100618class HVecHalvingAdd final : public HVecBinaryOperation {
Aart Bikf3e61ee2017-04-12 17:09:20 -0700619 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100620 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700621 HInstruction* left,
622 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100623 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700624 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700625 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700626 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530627 : HVecBinaryOperation(
628 kVecHalvingAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700629 DCHECK(HasConsistentPackedTypes(left, packed_type));
630 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700631 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700632 }
633
Aart Bikdb14fcf2017-04-25 15:53:58 -0700634 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700635
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100636 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700637
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100638 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700639 DCHECK(other->IsVecHalvingAdd());
640 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
Aart Bik66c158e2018-01-31 12:55:04 -0800641 return HVecOperation::InstructionDataEquals(o) && IsRounded() == o->IsRounded();
Aart Bikb79f4ac2017-07-10 10:10:37 -0700642 }
643
Aart Bikf3e61ee2017-04-12 17:09:20 -0700644 DECLARE_INSTRUCTION(VecHalvingAdd);
645
Artem Serovcced8ba2017-07-19 18:18:09 +0100646 protected:
647 DEFAULT_COPY_CONSTRUCTOR(VecHalvingAdd);
648
Aart Bikf3e61ee2017-04-12 17:09:20 -0700649 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700650 // Additional packed bits.
Aart Bik66c158e2018-01-31 12:55:04 -0800651 static constexpr size_t kFieldHAddIsRounded = HVecOperation::kNumberOfVectorOpPackedBits;
Aart Bikdb14fcf2017-04-25 15:53:58 -0700652 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
653 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700654};
655
Aart Bikf8f5a162017-02-06 15:35:29 -0800656// Subtracts every component in the two vectors,
657// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100658class HVecSub final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800659 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100660 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800661 HInstruction* left,
662 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100663 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800664 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700665 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530666 : HVecBinaryOperation(kVecSub, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700667 DCHECK(HasConsistentPackedTypes(left, packed_type));
668 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800669 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700670
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100671 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700672
Aart Bikf8f5a162017-02-06 15:35:29 -0800673 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700674
Artem Serovcced8ba2017-07-19 18:18:09 +0100675 protected:
676 DEFAULT_COPY_CONSTRUCTOR(VecSub);
Aart Bikf8f5a162017-02-06 15:35:29 -0800677};
678
Aart Bik29aa0822018-03-08 11:28:00 -0800679// Subtracts every component in the two vectors using saturation arithmetic,
680// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 -_sat y1, .. , xn -_sat yn ]
681// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100682class HVecSaturationSub final : public HVecBinaryOperation {
Aart Bik29aa0822018-03-08 11:28:00 -0800683 public:
684 HVecSaturationSub(ArenaAllocator* allocator,
685 HInstruction* left,
686 HInstruction* right,
687 DataType::Type packed_type,
688 size_t vector_length,
689 uint32_t dex_pc)
690 : HVecBinaryOperation(
691 kVecSaturationSub, allocator, left, right, packed_type, vector_length, dex_pc) {
692 DCHECK(HasConsistentPackedTypes(left, packed_type));
693 DCHECK(HasConsistentPackedTypes(right, packed_type));
694 }
695
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100696 bool CanBeMoved() const override { return true; }
Aart Bik29aa0822018-03-08 11:28:00 -0800697
698 DECLARE_INSTRUCTION(VecSaturationSub);
699
700 protected:
701 DEFAULT_COPY_CONSTRUCTOR(VecSaturationSub);
702};
703
Aart Bikf8f5a162017-02-06 15:35:29 -0800704// Multiplies every component in the two vectors,
705// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100706class HVecMul final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800707 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100708 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800709 HInstruction* left,
710 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100711 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800712 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700713 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530714 : HVecBinaryOperation(kVecMul, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700715 DCHECK(HasConsistentPackedTypes(left, packed_type));
716 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800717 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700718
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100719 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700720
Aart Bikf8f5a162017-02-06 15:35:29 -0800721 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700722
Artem Serovcced8ba2017-07-19 18:18:09 +0100723 protected:
724 DEFAULT_COPY_CONSTRUCTOR(VecMul);
Aart Bikf8f5a162017-02-06 15:35:29 -0800725};
726
727// Divides every component in the two vectors,
728// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100729class HVecDiv final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800730 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100731 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800732 HInstruction* left,
733 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100734 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800735 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700736 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530737 : HVecBinaryOperation(kVecDiv, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700738 DCHECK(HasConsistentPackedTypes(left, packed_type));
739 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800740 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700741
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100742 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700743
Aart Bikf8f5a162017-02-06 15:35:29 -0800744 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700745
Artem Serovcced8ba2017-07-19 18:18:09 +0100746 protected:
747 DEFAULT_COPY_CONSTRUCTOR(VecDiv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800748};
749
Aart Bikf3e61ee2017-04-12 17:09:20 -0700750// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700751// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800752// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100753class HVecMin final : public HVecBinaryOperation {
Aart Bikf3e61ee2017-04-12 17:09:20 -0700754 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100755 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700756 HInstruction* left,
757 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100758 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700759 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700760 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530761 : HVecBinaryOperation(kVecMin, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700762 DCHECK(HasConsistentPackedTypes(left, packed_type));
763 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700764 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700765
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100766 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700767
Aart Bikf3e61ee2017-04-12 17:09:20 -0700768 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700769
Artem Serovcced8ba2017-07-19 18:18:09 +0100770 protected:
771 DEFAULT_COPY_CONSTRUCTOR(VecMin);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700772};
773
774// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700775// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800776// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100777class HVecMax final : public HVecBinaryOperation {
Aart Bikf3e61ee2017-04-12 17:09:20 -0700778 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100779 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700780 HInstruction* left,
781 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100782 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700783 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700784 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530785 : HVecBinaryOperation(kVecMax, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700786 DCHECK(HasConsistentPackedTypes(left, packed_type));
787 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700788 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700789
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100790 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700791
Aart Bikf3e61ee2017-04-12 17:09:20 -0700792 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700793
Artem Serovcced8ba2017-07-19 18:18:09 +0100794 protected:
795 DEFAULT_COPY_CONSTRUCTOR(VecMax);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700796};
797
Aart Bikf8f5a162017-02-06 15:35:29 -0800798// Bitwise-ands every component in the two vectors,
799// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100800class HVecAnd final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800801 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100802 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800803 HInstruction* left,
804 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100805 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800806 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700807 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530808 : HVecBinaryOperation(kVecAnd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800809 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800810 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700811
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100812 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700813
Aart Bikf8f5a162017-02-06 15:35:29 -0800814 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700815
Artem Serovcced8ba2017-07-19 18:18:09 +0100816 protected:
817 DEFAULT_COPY_CONSTRUCTOR(VecAnd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800818};
819
820// Bitwise-and-nots every component in the two vectors,
821// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100822class HVecAndNot final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800823 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100824 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800825 HInstruction* left,
826 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100827 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800828 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700829 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530830 : HVecBinaryOperation(
831 kVecAndNot, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800832 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800833 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700834
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100835 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700836
Aart Bikf8f5a162017-02-06 15:35:29 -0800837 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700838
Artem Serovcced8ba2017-07-19 18:18:09 +0100839 protected:
840 DEFAULT_COPY_CONSTRUCTOR(VecAndNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800841};
842
843// Bitwise-ors every component in the two vectors,
844// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100845class HVecOr final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800846 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100847 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800848 HInstruction* left,
849 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100850 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800851 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700852 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530853 : HVecBinaryOperation(kVecOr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800854 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800855 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700856
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100857 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700858
Aart Bikf8f5a162017-02-06 15:35:29 -0800859 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700860
Artem Serovcced8ba2017-07-19 18:18:09 +0100861 protected:
862 DEFAULT_COPY_CONSTRUCTOR(VecOr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800863};
864
865// Bitwise-xors every component in the two vectors,
866// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100867class HVecXor final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800868 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100869 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800870 HInstruction* left,
871 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100872 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800873 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700874 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530875 : HVecBinaryOperation(kVecXor, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800876 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800877 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700878
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100879 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700880
Aart Bikf8f5a162017-02-06 15:35:29 -0800881 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700882
Artem Serovcced8ba2017-07-19 18:18:09 +0100883 protected:
884 DEFAULT_COPY_CONSTRUCTOR(VecXor);
Aart Bikf8f5a162017-02-06 15:35:29 -0800885};
886
887// Logically shifts every component in the vector left by the given distance,
888// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100889class HVecShl final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800890 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100891 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800892 HInstruction* left,
893 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100894 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800895 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700896 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530897 : HVecBinaryOperation(kVecShl, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700898 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800899 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700900
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100901 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700902
Aart Bikf8f5a162017-02-06 15:35:29 -0800903 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700904
Artem Serovcced8ba2017-07-19 18:18:09 +0100905 protected:
906 DEFAULT_COPY_CONSTRUCTOR(VecShl);
Aart Bikf8f5a162017-02-06 15:35:29 -0800907};
908
909// Arithmetically shifts every component in the vector right by the given distance,
910// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100911class HVecShr final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800912 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100913 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800914 HInstruction* left,
915 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100916 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800917 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700918 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530919 : HVecBinaryOperation(kVecShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700920 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800921 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700922
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100923 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700924
Aart Bikf8f5a162017-02-06 15:35:29 -0800925 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700926
Artem Serovcced8ba2017-07-19 18:18:09 +0100927 protected:
928 DEFAULT_COPY_CONSTRUCTOR(VecShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800929};
930
931// Logically shifts every component in the vector right by the given distance,
932// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100933class HVecUShr final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800934 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100935 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800936 HInstruction* left,
937 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100938 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800939 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700940 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530941 : HVecBinaryOperation(kVecUShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700942 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800943 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700944
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100945 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700946
Aart Bikf8f5a162017-02-06 15:35:29 -0800947 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700948
Artem Serovcced8ba2017-07-19 18:18:09 +0100949 protected:
950 DEFAULT_COPY_CONSTRUCTOR(VecUShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800951};
952
Aart Bik8de59162017-04-21 09:42:01 -0700953//
954// Definitions of concrete miscellaneous vector operations in HIR.
955//
956
957// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700958// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
959// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100960class HVecSetScalars final : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700961 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100962 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700963 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100964 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700965 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700966 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700967 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530968 : HVecOperation(kVecSetScalars,
969 allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700970 packed_type,
971 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700972 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700973 vector_length,
974 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700975 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik2dd7b672017-12-07 11:11:22 -0800976 DCHECK(!ReturnsSIMDValue(scalars[i]));
Aart Bik8de59162017-04-21 09:42:01 -0700977 SetRawInputAt(0, scalars[i]);
978 }
979 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700980
981 // Setting scalars needs to stay in place, since SIMD registers are not
982 // kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100983 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700984
Aart Bik8de59162017-04-21 09:42:01 -0700985 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700986
Artem Serovcced8ba2017-07-19 18:18:09 +0100987 protected:
988 DEFAULT_COPY_CONSTRUCTOR(VecSetScalars);
Aart Bik8de59162017-04-21 09:42:01 -0700989};
990
Aart Bikdbbac8f2017-09-01 13:06:08 -0700991// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
992// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Hans Boehm94344872018-07-13 09:57:50 -0700993// For floating point types, Java rounding behavior must be preserved; the products are rounded to
994// the proper precision before being added. "Fused" multiply-add operations available on several
995// architectures are not usable since they would violate Java language rules.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100996class HVecMultiplyAccumulate final : public HVecOperation {
Artem Serovf34dd202017-04-10 17:41:46 +0100997 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100998 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100999 InstructionKind op,
1000 HInstruction* accumulator,
1001 HInstruction* mul_left,
1002 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001003 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +01001004 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001005 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301006 : HVecOperation(kVecMultiplyAccumulate,
1007 allocator,
Artem Serovf34dd202017-04-10 17:41:46 +01001008 packed_type,
1009 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -08001010 /* number_of_inputs= */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +01001011 vector_length,
1012 dex_pc),
1013 op_kind_(op) {
1014 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -07001015 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1016 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
1017 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Hans Boehm94344872018-07-13 09:57:50 -07001018 // Remove the following if we add an architecture that supports floating point multiply-add
1019 // with Java-compatible rounding.
1020 DCHECK(DataType::IsIntegralType(packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -07001021 SetRawInputAt(0, accumulator);
1022 SetRawInputAt(1, mul_left);
1023 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +01001024 }
1025
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001026 bool CanBeMoved() const override { return true; }
Nicolas Geoffray9858bf72017-07-08 12:34:55 +00001027
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001028 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -07001029 DCHECK(other->IsVecMultiplyAccumulate());
1030 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
1031 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +01001032 }
1033
1034 InstructionKind GetOpKind() const { return op_kind_; }
1035
1036 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
1037
Artem Serovcced8ba2017-07-19 18:18:09 +01001038 protected:
1039 DEFAULT_COPY_CONSTRUCTOR(VecMultiplyAccumulate);
1040
Artem Serovf34dd202017-04-10 17:41:46 +01001041 private:
1042 // Indicates if this is a MADD or MSUB.
1043 const InstructionKind op_kind_;
Artem Serovf34dd202017-04-10 17:41:46 +01001044};
1045
Aart Bikdbbac8f2017-09-01 13:06:08 -07001046// Takes the absolute difference of two vectors, and adds the results to
1047// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001048// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -07001049// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -07001050// for m <= n, non-overlapping sums, and signed operands x, y.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001051class HVecSADAccumulate final : public HVecOperation {
Aart Bikdbbac8f2017-09-01 13:06:08 -07001052 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001053 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001054 HInstruction* accumulator,
1055 HInstruction* sad_left,
1056 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001057 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001058 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001059 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301060 : HVecOperation(kVecSADAccumulate,
1061 allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001062 packed_type,
1063 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -08001064 /* number_of_inputs= */ 3,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001065 vector_length,
1066 dex_pc) {
1067 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1068 DCHECK(sad_left->IsVecOperation());
1069 DCHECK(sad_right->IsVecOperation());
Vladimir Marko61b92282017-10-11 13:23:17 +01001070 DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
1071 ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
Aart Bikdbbac8f2017-09-01 13:06:08 -07001072 SetRawInputAt(0, accumulator);
1073 SetRawInputAt(1, sad_left);
1074 SetRawInputAt(2, sad_right);
1075 }
1076
1077 DECLARE_INSTRUCTION(VecSADAccumulate);
1078
Artem Serovcced8ba2017-07-19 18:18:09 +01001079 protected:
1080 DEFAULT_COPY_CONSTRUCTOR(VecSADAccumulate);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001081};
1082
Artem Serovaaac0e32018-08-07 00:52:22 +01001083// Performs dot product of two vectors and adds the result to wider precision components in
1084// the accumulator.
1085//
1086// viz. DOT_PRODUCT([ a1, .. , am], [ x1, .. , xn ], [ y1, .. , yn ]) =
1087// [ a1 + sum(xi * yi), .. , am + sum(xj * yj) ],
1088// for m <= n, non-overlapping sums,
1089// for either both signed or both unsigned operands x, y.
1090//
1091// Notes:
1092// - packed type reflects the type of sum reduction, not the type of the operands.
1093// - IsZeroExtending() is used to determine the kind of signed/zero extension to be
1094// performed for the operands.
1095//
1096// TODO: Support types other than kInt32 for packed type.
1097class HVecDotProd final : public HVecOperation {
1098 public:
1099 HVecDotProd(ArenaAllocator* allocator,
1100 HInstruction* accumulator,
1101 HInstruction* left,
1102 HInstruction* right,
1103 DataType::Type packed_type,
1104 bool is_zero_extending,
1105 size_t vector_length,
1106 uint32_t dex_pc)
1107 : HVecOperation(kVecDotProd,
1108 allocator,
1109 packed_type,
1110 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -08001111 /* number_of_inputs= */ 3,
Artem Serovaaac0e32018-08-07 00:52:22 +01001112 vector_length,
1113 dex_pc) {
1114 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1115 DCHECK(DataType::IsIntegralType(packed_type));
1116 DCHECK(left->IsVecOperation());
1117 DCHECK(right->IsVecOperation());
1118 DCHECK_EQ(ToSignedType(left->AsVecOperation()->GetPackedType()),
1119 ToSignedType(right->AsVecOperation()->GetPackedType()));
1120 SetRawInputAt(0, accumulator);
1121 SetRawInputAt(1, left);
1122 SetRawInputAt(2, right);
1123 SetPackedFlag<kFieldHDotProdIsZeroExtending>(is_zero_extending);
1124 }
1125
1126 bool IsZeroExtending() const { return GetPackedFlag<kFieldHDotProdIsZeroExtending>(); }
1127
1128 bool CanBeMoved() const override { return true; }
1129
1130 DECLARE_INSTRUCTION(VecDotProd);
1131
1132 protected:
1133 DEFAULT_COPY_CONSTRUCTOR(VecDotProd);
1134
1135 private:
1136 // Additional packed bits.
1137 static constexpr size_t kFieldHDotProdIsZeroExtending =
1138 HVecOperation::kNumberOfVectorOpPackedBits;
1139 static constexpr size_t kNumberOfHDotProdPackedBits = kFieldHDotProdIsZeroExtending + 1;
1140 static_assert(kNumberOfHDotProdPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
1141};
1142
Aart Bikf8f5a162017-02-06 15:35:29 -08001143// Loads a vector from memory, viz. load(mem, 1)
1144// yield the vector [ mem(1), .. , mem(n) ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001145class HVecLoad final : public HVecMemoryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -08001146 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001147 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001148 HInstruction* base,
1149 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001150 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001151 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001152 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -07001153 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001154 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301155 : HVecMemoryOperation(kVecLoad,
1156 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001157 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001158 side_effects,
Andreas Gampe3db70682018-12-26 15:12:03 -08001159 /* number_of_inputs= */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -08001160 vector_length,
1161 dex_pc) {
1162 SetRawInputAt(0, base);
1163 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -07001164 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -08001165 }
Aart Bikdb14fcf2017-04-25 15:53:58 -07001166
1167 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
1168
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001169 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001170
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001171 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -07001172 DCHECK(other->IsVecLoad());
1173 const HVecLoad* o = other->AsVecLoad();
1174 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
1175 }
1176
1177 DECLARE_INSTRUCTION(VecLoad);
1178
Artem Serovcced8ba2017-07-19 18:18:09 +01001179 protected:
1180 DEFAULT_COPY_CONSTRUCTOR(VecLoad);
1181
Aart Bikf8f5a162017-02-06 15:35:29 -08001182 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -07001183 // Additional packed bits.
1184 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
1185 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
1186 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf8f5a162017-02-06 15:35:29 -08001187};
1188
1189// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1190// sets mem(1) = x1, .. , mem(n) = xn.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001191class HVecStore final : public HVecMemoryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -08001192 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001193 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001194 HInstruction* base,
1195 HInstruction* index,
1196 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001197 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001198 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001199 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001200 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301201 : HVecMemoryOperation(kVecStore,
1202 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001203 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001204 side_effects,
Andreas Gampe3db70682018-12-26 15:12:03 -08001205 /* number_of_inputs= */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001206 vector_length,
1207 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001208 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001209 SetRawInputAt(0, base);
1210 SetRawInputAt(1, index);
1211 SetRawInputAt(2, value);
1212 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001213
1214 // A store needs to stay in place.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001215 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001216
xueliang.zhongd71f1dc2018-01-24 17:24:16 +00001217 HInstruction* GetValue() const { return InputAt(2); }
1218
Aart Bikf8f5a162017-02-06 15:35:29 -08001219 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001220
Artem Serovcced8ba2017-07-19 18:18:09 +01001221 protected:
1222 DEFAULT_COPY_CONSTRUCTOR(VecStore)
Aart Bikf8f5a162017-02-06 15:35:29 -08001223};
1224
Artem Serov07718842020-02-24 18:51:42 +00001225//
1226// 'Predicate-setting' instructions.
1227//
1228
1229// An abstract class for instructions for which the output value is a vector predicate -
1230// a special kind of vector value:
1231//
1232// viz. [ p1, .. , pn ], where p_i is from { 0, 1 }.
1233//
1234// A VecOperation OP executes the same operation (e.g. ADD) on multiple elements of the vector.
1235// It can be either unpredicated (operation is done on ALL of the elements) or predicated (only
1236// on SOME elements, determined by a special extra input - vector predicate).
1237// Implementations can vary depending on the ISA; the general idea is that for each element of the
1238// regular vector a vector predicate has a corresponding element with either 0 or 1.
1239// The value determines whether a vector element will be involved in OP calculations or not
1240// (active or inactive). A vector predicate is referred as governing one if it is used to
1241// control the execution of a predicated instruction.
1242//
1243// Note: vector predicate value type is introduced alongside existing vectors of booleans and
1244// vectors of bytes to reflect their special semantics.
1245//
1246// TODO: we could introduce SIMD types in HIR.
1247class HVecPredSetOperation : public HVecOperation {
1248 public:
1249 // A vector predicate-setting operation looks like a Int64 location.
1250 // TODO: we could introduce vector types in HIR.
1251 static constexpr DataType::Type kSIMDPredType = DataType::Type::kInt64;
1252
1253 HVecPredSetOperation(InstructionKind kind,
1254 ArenaAllocator* allocator,
1255 DataType::Type packed_type,
1256 SideEffects side_effects,
1257 size_t number_of_inputs,
1258 size_t vector_length,
1259 uint32_t dex_pc)
1260 : HVecOperation(kind,
1261 allocator,
1262 packed_type,
1263 side_effects,
1264 number_of_inputs,
1265 vector_length,
1266 dex_pc) {
1267 // Overrides the kSIMDType set by the VecOperation constructor.
1268 SetPackedField<TypeField>(kSIMDPredType);
1269 }
1270
1271 bool CanBeMoved() const override { return true; }
1272
1273 DECLARE_ABSTRACT_INSTRUCTION(VecPredSetOperation);
1274
1275 protected:
1276 DEFAULT_COPY_CONSTRUCTOR(VecPredSetOperation);
1277};
1278
1279// Sets all the vector predicate elements as active or inactive.
1280//
1281// viz. [ p1, .. , pn ] = [ val, .. , val ] where val is from { 1, 0 }.
1282class HVecPredSetAll final : public HVecPredSetOperation {
1283 public:
1284 HVecPredSetAll(ArenaAllocator* allocator,
1285 HInstruction* input,
1286 DataType::Type packed_type,
1287 size_t vector_length,
1288 uint32_t dex_pc) :
1289 HVecPredSetOperation(kVecPredSetAll,
1290 allocator,
1291 packed_type,
1292 SideEffects::None(),
1293 /* number_of_inputs= */ 1,
1294 vector_length,
1295 dex_pc) {
1296 DCHECK(input->IsIntConstant());
1297 SetRawInputAt(0, input);
1298 MarkEmittedAtUseSite();
1299 }
1300
1301 // Having governing predicate doesn't make sense for set all TRUE/FALSE instruction.
1302 bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
1303
1304 bool IsSetTrue() const { return InputAt(0)->AsIntConstant()->IsTrue(); }
1305
1306 // Vector predicates are not kept alive across vector loop boundaries.
1307 bool CanBeMoved() const override { return false; }
1308
1309 DECLARE_INSTRUCTION(VecPredSetAll);
1310
1311 protected:
1312 DEFAULT_COPY_CONSTRUCTOR(VecPredSetAll);
1313};
1314
1315//
1316// Arm64 SVE-specific instructions.
1317//
1318// Classes of instructions which are specific to Arm64 SVE (though could be adopted
1319// by other targets, possibly being lowered to a number of ISA instructions) and
1320// implement SIMD loop predicated execution idiom.
1321//
1322
1323// Takes two scalar values x and y, creates a vector S: s(n) = x + n, compares (OP) each s(n)
1324// with y and set the corresponding element of the predicate register to the result of the
1325// comparison.
1326//
1327// viz. [ p1, .. , pn ] = [ x OP y , (x + 1) OP y, .. , (x + n) OP y ] where OP is CondKind
1328// condition.
1329class HVecPredWhile final : public HVecPredSetOperation {
1330 public:
1331 enum class CondKind {
1332 kLE, // signed less than or equal.
1333 kLO, // unsigned lower.
1334 kLS, // unsigned lower or same.
1335 kLT, // signed less.
1336 kLast = kLT,
1337 };
1338
1339 HVecPredWhile(ArenaAllocator* allocator,
1340 HInstruction* left,
1341 HInstruction* right,
1342 CondKind cond,
1343 DataType::Type packed_type,
1344 size_t vector_length,
1345 uint32_t dex_pc) :
1346 HVecPredSetOperation(kVecPredWhile,
1347 allocator,
1348 packed_type,
1349 SideEffects::None(),
1350 /* number_of_inputs= */ 2,
1351 vector_length,
1352 dex_pc) {
1353 DCHECK(!left->IsVecOperation());
1354 DCHECK(!left->IsVecPredSetOperation());
1355 DCHECK(!right->IsVecOperation());
1356 DCHECK(!right->IsVecPredSetOperation());
1357 DCHECK(DataType::IsIntegralType(left->GetType()));
1358 DCHECK(DataType::IsIntegralType(right->GetType()));
1359 SetRawInputAt(0, left);
1360 SetRawInputAt(1, right);
1361 SetPackedField<CondKindField>(cond);
1362 }
1363
1364 // This is a special loop control instruction which must not be predicated.
1365 bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
1366
1367 CondKind GetCondKind() const {
1368 return GetPackedField<CondKindField>();
1369 }
1370
1371 DECLARE_INSTRUCTION(VecPredWhile);
1372
1373 protected:
1374 // Additional packed bits.
1375 static constexpr size_t kCondKind = HVecOperation::kNumberOfVectorOpPackedBits;
1376 static constexpr size_t kCondKindSize =
1377 MinimumBitsToStore(static_cast<size_t>(CondKind::kLast));
1378 static constexpr size_t kNumberOfVecPredConditionPackedBits = kCondKind + kCondKindSize;
1379 static_assert(kNumberOfVecPredConditionPackedBits <= kMaxNumberOfPackedBits,
1380 "Too many packed fields.");
1381 using CondKindField = BitField<CondKind, kCondKind, kCondKindSize>;
1382
1383 DEFAULT_COPY_CONSTRUCTOR(VecPredWhile);
1384};
1385
1386// Evaluates the predicate condition (PCondKind) for a vector predicate; outputs
1387// a scalar boolean value result.
1388//
1389// Note: as VecPredCondition can be also predicated, only active elements (determined by the
1390// instruction's governing predicate) of the input vector predicate are used for condition
1391// evaluation.
1392//
1393// Note: this instruction is currently used as a workaround for the fact that IR instructions
1394// can't have more than one output.
1395class HVecPredCondition final : public HVecOperation {
1396 public:
1397 // To get more info on the condition kinds please see "2.2 Process state, PSTATE" section of
1398 // "ARM Architecture Reference Manual Supplement. The Scalable Vector Extension (SVE),
1399 // for ARMv8-A".
1400 enum class PCondKind {
1401 kNone, // No active elements were TRUE.
1402 kAny, // An active element was TRUE.
1403 kNLast, // The last active element was not TRUE.
1404 kLast, // The last active element was TRUE.
1405 kFirst, // The first active element was TRUE.
1406 kNFirst, // The first active element was not TRUE.
1407 kPMore, // An active element was TRUE but not the last active element.
1408 kPLast, // The last active element was TRUE or no active elements were TRUE.
1409 kEnumLast = kPLast
1410 };
1411
1412 HVecPredCondition(ArenaAllocator* allocator,
1413 HInstruction* input,
1414 PCondKind pred_cond,
1415 DataType::Type packed_type,
1416 size_t vector_length,
1417 uint32_t dex_pc)
1418 : HVecOperation(kVecPredCondition,
1419 allocator,
1420 packed_type,
1421 SideEffects::None(),
1422 /* number_of_inputs */ 1,
1423 vector_length,
1424 dex_pc) {
1425 DCHECK(input->IsVecPredSetOperation());
1426 SetRawInputAt(0, input);
1427 // Overrides the kSIMDType set by the VecOperation constructor.
1428 SetPackedField<TypeField>(DataType::Type::kBool);
1429 SetPackedField<CondKindField>(pred_cond);
1430 }
1431
1432 // This instruction is currently used only as a special loop control instruction
1433 // which must not be predicated.
1434 // TODO: Remove the constraint.
1435 bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
1436
1437 PCondKind GetPCondKind() const {
1438 return GetPackedField<CondKindField>();
1439 }
1440
1441 DECLARE_INSTRUCTION(VecPredCondition);
1442
1443 protected:
1444 // Additional packed bits.
1445 static constexpr size_t kCondKind = HVecOperation::kNumberOfVectorOpPackedBits;
1446 static constexpr size_t kCondKindSize =
1447 MinimumBitsToStore(static_cast<size_t>(PCondKind::kEnumLast));
1448 static constexpr size_t kNumberOfVecPredConditionPackedBits = kCondKind + kCondKindSize;
1449 static_assert(kNumberOfVecPredConditionPackedBits <= kMaxNumberOfPackedBits,
1450 "Too many packed fields.");
1451 using CondKindField = BitField<PCondKind, kCondKind, kCondKindSize>;
1452
1453 DEFAULT_COPY_CONSTRUCTOR(VecPredCondition);
1454};
1455
Aart Bikf8f5a162017-02-06 15:35:29 -08001456} // namespace art
1457
1458#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_