blob: a2cd86dc3345745461ec983cba73926ad0235b96 [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
Artem Serov8ba4de12019-12-04 21:10:23 +0000148 // Returns whether two vector operations are predicated by the same vector predicate
149 // with the same predication type.
150 static bool HaveSamePredicate(HVecOperation* instr0, HVecOperation* instr1) {
151 HVecPredSetOperation* instr0_predicate = instr0->GetGoverningPredicate();
152 HVecOperation::PredicationKind instr0_predicate_kind = instr0->GetPredicationKind();
153 return instr1->GetGoverningPredicate() == instr0_predicate &&
154 instr1->GetPredicationKind() == instr0_predicate_kind;
155 }
156
Aart Bikf8f5a162017-02-06 15:35:29 -0800157 // Returns the number of elements packed in a vector.
158 size_t GetVectorLength() const {
159 return vector_length_;
160 }
161
162 // Returns the number of bytes in a full vector.
163 size_t GetVectorNumberOfBytes() const {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100164 return vector_length_ * DataType::Size(GetPackedType());
Aart Bikf8f5a162017-02-06 15:35:29 -0800165 }
166
Aart Bikf8f5a162017-02-06 15:35:29 -0800167 // Returns the true component type packed in a vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100168 DataType::Type GetPackedType() const {
Vladimir Markobd785672018-05-03 17:09:09 +0100169 return GetPackedField<PackedTypeField>();
Aart Bikf8f5a162017-02-06 15:35:29 -0800170 }
171
Aart Bikb79f4ac2017-07-10 10:10:37 -0700172 // Assumes vector nodes cannot be moved by default. Each concrete implementation
173 // that can be moved should override this method and return true.
Artem Serov89ff8b22017-11-20 11:51:05 +0000174 //
175 // Note: similar approach is used for instruction scheduling (if it is turned on for the target):
176 // by default HScheduler::IsSchedulable returns false for a particular HVecOperation.
177 // HScheduler${ARCH}::IsSchedulable can be overridden to return true for an instruction (see
178 // scheduler_arm64.h for example) if it is safe to schedule it; in this case one *must* also
179 // look at/update HScheduler${ARCH}::IsSchedulingBarrier for this instruction.
180 //
181 // Note: For newly introduced vector instructions HScheduler${ARCH}::IsSchedulingBarrier must be
182 // altered to return true if the instruction might reside outside the SIMD loop body since SIMD
183 // registers are not kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100184 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700185
186 // Tests if all data of a vector node (vector length and packed type) is equal.
187 // Each concrete implementation that adds more fields should test equality of
188 // those fields in its own method *and* call all super methods.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100189 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700190 DCHECK(other->IsVecOperation());
191 const HVecOperation* o = other->AsVecOperation();
192 return GetVectorLength() == o->GetVectorLength() && GetPackedType() == o->GetPackedType();
193 }
194
Aart Bik46b6dbc2017-10-03 11:37:37 -0700195 // Maps an integral type to the same-size signed type and leaves other types alone.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700196 static DataType::Type ToSignedType(DataType::Type type) {
197 switch (type) {
198 case DataType::Type::kBool: // 1-byte storage unit
199 case DataType::Type::kUint8:
200 return DataType::Type::kInt8;
201 case DataType::Type::kUint16:
202 return DataType::Type::kInt16;
203 default:
204 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
205 return type;
206 }
207 }
208
Aart Bik4d1a9d42017-10-19 14:40:55 -0700209 // Maps an integral type to the same-size unsigned type and leaves other types alone.
210 static DataType::Type ToUnsignedType(DataType::Type type) {
211 switch (type) {
212 case DataType::Type::kBool: // 1-byte storage unit
213 case DataType::Type::kInt8:
214 return DataType::Type::kUint8;
215 case DataType::Type::kInt16:
216 return DataType::Type::kUint16;
217 default:
218 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
219 return type;
220 }
221 }
222
Aart Bik66c158e2018-01-31 12:55:04 -0800223 // Maps an integral type to the same-size (un)signed type. Leaves other types alone.
224 static DataType::Type ToProperType(DataType::Type type, bool is_unsigned) {
225 return is_unsigned ? ToUnsignedType(type) : ToSignedType(type);
226 }
227
Aart Bik2dd7b672017-12-07 11:11:22 -0800228 // Helper method to determine if an instruction returns a SIMD value.
229 // TODO: This method is needed until we introduce SIMD as proper type.
230 static bool ReturnsSIMDValue(HInstruction* instruction) {
231 if (instruction->IsVecOperation()) {
232 return !instruction->IsVecExtractScalar(); // only scalar returning vec op
233 } else if (instruction->IsPhi()) {
Aart Bik3f8e02c2018-04-10 11:55:00 -0700234 // Vectorizer only uses Phis in reductions, so checking for a 2-way phi
235 // with a direct vector operand as second argument suffices.
Aart Bik2dd7b672017-12-07 11:11:22 -0800236 return
237 instruction->GetType() == kSIMDType &&
Aart Bik3f8e02c2018-04-10 11:55:00 -0700238 instruction->InputCount() == 2 &&
239 instruction->InputAt(1)->IsVecOperation();
Aart Bik2dd7b672017-12-07 11:11:22 -0800240 }
241 return false;
242 }
243
Aart Bikf8f5a162017-02-06 15:35:29 -0800244 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
245
Aart Bikdb14fcf2017-04-25 15:53:58 -0700246 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800247 // Additional packed bits.
Artem Serov07718842020-02-24 18:51:42 +0000248 static constexpr size_t kPredicationKind = HInstruction::kNumberOfGenericPackedBits;
249 static constexpr size_t kPredicationKindSize =
250 MinimumBitsToStore(static_cast<size_t>(PredicationKind::kLast));
251 static constexpr size_t kFieldPackedType = kPredicationKind + kPredicationKindSize;
Vladimir Markobd785672018-05-03 17:09:09 +0100252 static constexpr size_t kFieldPackedTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100253 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Vladimir Markobd785672018-05-03 17:09:09 +0100254 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldPackedType + kFieldPackedTypeSize;
Aart Bikf8f5a162017-02-06 15:35:29 -0800255 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Markobd785672018-05-03 17:09:09 +0100256 using PackedTypeField = BitField<DataType::Type, kFieldPackedType, kFieldPackedTypeSize>;
Artem Serov07718842020-02-24 18:51:42 +0000257 using PredicationKindField = BitField<PredicationKind, kPredicationKind, kPredicationKindSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800258
Artem Serovcced8ba2017-07-19 18:18:09 +0100259 DEFAULT_COPY_CONSTRUCTOR(VecOperation);
260
Aart Bikdb14fcf2017-04-25 15:53:58 -0700261 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800262 const size_t vector_length_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800263};
264
265// Abstraction of a unary vector operation.
266class HVecUnaryOperation : public HVecOperation {
267 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530268 HVecUnaryOperation(InstructionKind kind,
269 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700270 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100271 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800272 size_t vector_length,
273 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530274 : HVecOperation(kind,
275 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800276 packed_type,
277 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -0800278 /* number_of_inputs= */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800279 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700280 dex_pc) {
281 SetRawInputAt(0, input);
282 }
283
284 HInstruction* GetInput() const { return InputAt(0); }
285
Aart Bikf8f5a162017-02-06 15:35:29 -0800286 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700287
Artem Serovcced8ba2017-07-19 18:18:09 +0100288 protected:
289 DEFAULT_COPY_CONSTRUCTOR(VecUnaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800290};
291
292// Abstraction of a binary vector operation.
293class HVecBinaryOperation : public HVecOperation {
294 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530295 HVecBinaryOperation(InstructionKind kind,
296 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700297 HInstruction* left,
298 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100299 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800300 size_t vector_length,
301 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530302 : HVecOperation(kind,
303 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800304 packed_type,
305 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -0800306 /* number_of_inputs= */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800307 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700308 dex_pc) {
309 SetRawInputAt(0, left);
310 SetRawInputAt(1, right);
311 }
Artem Serovf34dd202017-04-10 17:41:46 +0100312
313 HInstruction* GetLeft() const { return InputAt(0); }
314 HInstruction* GetRight() const { return InputAt(1); }
315
Aart Bikf8f5a162017-02-06 15:35:29 -0800316 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700317
Artem Serovcced8ba2017-07-19 18:18:09 +0100318 protected:
319 DEFAULT_COPY_CONSTRUCTOR(VecBinaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800320};
321
322// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700323// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800324class HVecMemoryOperation : public HVecOperation {
325 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530326 HVecMemoryOperation(InstructionKind kind,
327 ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100328 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800329 SideEffects side_effects,
330 size_t number_of_inputs,
331 size_t vector_length,
332 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530333 : HVecOperation(kind,
334 allocator,
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100335 packed_type,
336 side_effects,
337 number_of_inputs,
338 vector_length,
339 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100340 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100341 DCHECK_GE(number_of_inputs, 2u);
342 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800343
344 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
345
346 Alignment GetAlignment() const { return alignment_; }
347
Artem Serove1811ed2017-04-27 16:50:47 +0100348 HInstruction* GetArray() const { return InputAt(0); }
349 HInstruction* GetIndex() const { return InputAt(1); }
350
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100351 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700352 DCHECK(other->IsVecMemoryOperation());
353 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
354 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
355 }
356
Aart Bikf8f5a162017-02-06 15:35:29 -0800357 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
358
Artem Serovcced8ba2017-07-19 18:18:09 +0100359 protected:
360 DEFAULT_COPY_CONSTRUCTOR(VecMemoryOperation);
361
Aart Bikf8f5a162017-02-06 15:35:29 -0800362 private:
363 Alignment alignment_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800364};
365
Aart Bik0148de42017-09-05 09:25:01 -0700366// Packed type consistency checker ("same vector length" integral types may mix freely).
Aart Bik66c158e2018-01-31 12:55:04 -0800367// Tests relaxed type consistency in which packed same-size integral types can co-exist,
368// but other type mixes are an error.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100369inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700370 if (input->IsPhi()) {
371 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
372 }
Aart Bikd58bc322017-05-01 14:49:18 -0700373 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100374 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik4d1a9d42017-10-19 14:40:55 -0700375 DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
376 HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
Aart Bik46b6dbc2017-10-03 11:37:37 -0700377 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700378}
379
Aart Bikf8f5a162017-02-06 15:35:29 -0800380//
Aart Bik8de59162017-04-21 09:42:01 -0700381// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800382//
383
384// Replicates the given scalar into a vector,
385// viz. replicate(x) = [ x, .. , x ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100386class HVecReplicateScalar final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800387 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100388 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800389 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100390 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800391 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700392 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530393 : HVecUnaryOperation(
394 kVecReplicateScalar, allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik5a0eb0c2018-03-16 15:00:19 -0700395 DCHECK(!ReturnsSIMDValue(scalar));
Aart Bikf8f5a162017-02-06 15:35:29 -0800396 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700397
398 // A replicate needs to stay in place, since SIMD registers are not
399 // kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100400 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700401
Aart Bikf8f5a162017-02-06 15:35:29 -0800402 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700403
Artem Serovcced8ba2017-07-19 18:18:09 +0100404 protected:
405 DEFAULT_COPY_CONSTRUCTOR(VecReplicateScalar);
Aart Bikf8f5a162017-02-06 15:35:29 -0800406};
407
Aart Bik0148de42017-09-05 09:25:01 -0700408// Extracts a particular scalar from the given vector,
409// viz. extract[ x1, .. , xn ] = x_i.
410//
411// TODO: for now only i == 1 case supported.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100412class HVecExtractScalar final : public HVecUnaryOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700413 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100414 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700415 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100416 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700417 size_t vector_length,
418 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700419 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530420 : HVecUnaryOperation(
421 kVecExtractScalar, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700422 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700423 DCHECK_LT(index, vector_length);
424 DCHECK_EQ(index, 0u);
Vladimir Markobd785672018-05-03 17:09:09 +0100425 // Yields a single component in the vector.
426 // Overrides the kSIMDType set by the VecOperation constructor.
427 SetPackedField<TypeField>(packed_type);
Aart Bik0148de42017-09-05 09:25:01 -0700428 }
429
430 // An extract needs to stay in place, since SIMD registers are not
431 // kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100432 bool CanBeMoved() const override { return false; }
Aart Bik0148de42017-09-05 09:25:01 -0700433
434 DECLARE_INSTRUCTION(VecExtractScalar);
435
Artem Serovcced8ba2017-07-19 18:18:09 +0100436 protected:
437 DEFAULT_COPY_CONSTRUCTOR(VecExtractScalar);
Aart Bik0148de42017-09-05 09:25:01 -0700438};
439
440// Reduces the given vector into the first element as sum/min/max,
441// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
442// and the "-" denotes "don't care" (implementation dependent).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100443class HVecReduce final : public HVecUnaryOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700444 public:
445 enum ReductionKind {
446 kSum = 1,
447 kMin = 2,
448 kMax = 3
449 };
450
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100451 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700452 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100453 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700454 size_t vector_length,
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000455 ReductionKind reduction_kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700456 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530457 : HVecUnaryOperation(kVecReduce, allocator, input, packed_type, vector_length, dex_pc),
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000458 reduction_kind_(reduction_kind) {
Aart Bik0148de42017-09-05 09:25:01 -0700459 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700460 }
461
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000462 ReductionKind GetReductionKind() const { return reduction_kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800463
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100464 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700465
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100466 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bik0148de42017-09-05 09:25:01 -0700467 DCHECK(other->IsVecReduce());
468 const HVecReduce* o = other->AsVecReduce();
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000469 return HVecOperation::InstructionDataEquals(o) && GetReductionKind() == o->GetReductionKind();
Aart Bik0148de42017-09-05 09:25:01 -0700470 }
471
472 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700473
Artem Serovcced8ba2017-07-19 18:18:09 +0100474 protected:
475 DEFAULT_COPY_CONSTRUCTOR(VecReduce);
476
Aart Bikf8f5a162017-02-06 15:35:29 -0800477 private:
Vladimir Marko4e3734a2018-11-14 15:45:28 +0000478 const ReductionKind reduction_kind_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800479};
480
481// Converts every component in the vector,
482// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100483class HVecCnv final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800484 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100485 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800486 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100487 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800488 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700489 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530490 : HVecUnaryOperation(kVecCnv, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800491 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700492 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800493 }
494
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100495 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
496 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800497
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100498 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700499
Aart Bikf8f5a162017-02-06 15:35:29 -0800500 DECLARE_INSTRUCTION(VecCnv);
501
Artem Serovcced8ba2017-07-19 18:18:09 +0100502 protected:
503 DEFAULT_COPY_CONSTRUCTOR(VecCnv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800504};
505
506// Negates every component in the vector,
507// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100508class HVecNeg final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800509 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100510 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800511 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100512 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800513 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700514 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530515 : HVecUnaryOperation(kVecNeg, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700516 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800517 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700518
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100519 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700520
Aart Bikf8f5a162017-02-06 15:35:29 -0800521 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700522
Artem Serovcced8ba2017-07-19 18:18:09 +0100523 protected:
524 DEFAULT_COPY_CONSTRUCTOR(VecNeg);
Aart Bikf8f5a162017-02-06 15:35:29 -0800525};
526
Aart Bik6daebeb2017-04-03 14:35:41 -0700527// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700528// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
529// for signed operand x.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100530class HVecAbs final : public HVecUnaryOperation {
Aart Bik6daebeb2017-04-03 14:35:41 -0700531 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100532 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700533 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100534 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700535 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700536 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530537 : HVecUnaryOperation(kVecAbs, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700538 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700539 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700540
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100541 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700542
Aart Bik6daebeb2017-04-03 14:35:41 -0700543 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700544
Artem Serovcced8ba2017-07-19 18:18:09 +0100545 protected:
546 DEFAULT_COPY_CONSTRUCTOR(VecAbs);
Aart Bik6daebeb2017-04-03 14:35:41 -0700547};
548
Aart Bikf8f5a162017-02-06 15:35:29 -0800549// Bitwise- or boolean-nots every component in the vector,
550// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
551// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100552class HVecNot final : public HVecUnaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800553 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100554 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800555 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100556 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800557 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700558 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530559 : HVecUnaryOperation(kVecNot, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800560 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800561 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700562
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100563 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700564
Aart Bikf8f5a162017-02-06 15:35:29 -0800565 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700566
Artem Serovcced8ba2017-07-19 18:18:09 +0100567 protected:
568 DEFAULT_COPY_CONSTRUCTOR(VecNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800569};
570
Aart Bik8de59162017-04-21 09:42:01 -0700571//
572// Definitions of concrete binary vector operations in HIR.
573//
574
Aart Bikf8f5a162017-02-06 15:35:29 -0800575// Adds every component in the two vectors,
576// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100577class HVecAdd final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800578 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100579 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800580 HInstruction* left,
581 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100582 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800583 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700584 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530585 : HVecBinaryOperation(kVecAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700586 DCHECK(HasConsistentPackedTypes(left, packed_type));
587 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800588 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700589
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100590 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700591
Aart Bikf8f5a162017-02-06 15:35:29 -0800592 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700593
Artem Serovcced8ba2017-07-19 18:18:09 +0100594 protected:
595 DEFAULT_COPY_CONSTRUCTOR(VecAdd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800596};
597
Aart Bik29aa0822018-03-08 11:28:00 -0800598// Adds every component in the two vectors using saturation arithmetic,
599// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 +_sat y1, .. , xn +_sat yn ]
600// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100601class HVecSaturationAdd final : public HVecBinaryOperation {
Aart Bik29aa0822018-03-08 11:28:00 -0800602 public:
603 HVecSaturationAdd(ArenaAllocator* allocator,
604 HInstruction* left,
605 HInstruction* right,
606 DataType::Type packed_type,
607 size_t vector_length,
608 uint32_t dex_pc)
609 : HVecBinaryOperation(
610 kVecSaturationAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
611 DCHECK(HasConsistentPackedTypes(left, packed_type));
612 DCHECK(HasConsistentPackedTypes(right, packed_type));
613 }
614
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100615 bool CanBeMoved() const override { return true; }
Aart Bik29aa0822018-03-08 11:28:00 -0800616
617 DECLARE_INSTRUCTION(VecSaturationAdd);
618
619 protected:
620 DEFAULT_COPY_CONSTRUCTOR(VecSaturationAdd);
621};
622
Aart Bikf3e61ee2017-04-12 17:09:20 -0700623// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700624// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
625// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik66c158e2018-01-31 12:55:04 -0800626// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100627class HVecHalvingAdd final : public HVecBinaryOperation {
Aart Bikf3e61ee2017-04-12 17:09:20 -0700628 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100629 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700630 HInstruction* left,
631 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100632 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700633 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700634 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700635 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530636 : HVecBinaryOperation(
637 kVecHalvingAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700638 DCHECK(HasConsistentPackedTypes(left, packed_type));
639 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700640 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700641 }
642
Aart Bikdb14fcf2017-04-25 15:53:58 -0700643 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700644
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100645 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700646
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100647 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700648 DCHECK(other->IsVecHalvingAdd());
649 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
Aart Bik66c158e2018-01-31 12:55:04 -0800650 return HVecOperation::InstructionDataEquals(o) && IsRounded() == o->IsRounded();
Aart Bikb79f4ac2017-07-10 10:10:37 -0700651 }
652
Aart Bikf3e61ee2017-04-12 17:09:20 -0700653 DECLARE_INSTRUCTION(VecHalvingAdd);
654
Artem Serovcced8ba2017-07-19 18:18:09 +0100655 protected:
656 DEFAULT_COPY_CONSTRUCTOR(VecHalvingAdd);
657
Aart Bikf3e61ee2017-04-12 17:09:20 -0700658 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700659 // Additional packed bits.
Aart Bik66c158e2018-01-31 12:55:04 -0800660 static constexpr size_t kFieldHAddIsRounded = HVecOperation::kNumberOfVectorOpPackedBits;
Aart Bikdb14fcf2017-04-25 15:53:58 -0700661 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
662 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700663};
664
Aart Bikf8f5a162017-02-06 15:35:29 -0800665// Subtracts every component in the two vectors,
666// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100667class HVecSub final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800668 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100669 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800670 HInstruction* left,
671 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100672 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800673 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700674 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530675 : HVecBinaryOperation(kVecSub, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700676 DCHECK(HasConsistentPackedTypes(left, packed_type));
677 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800678 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700679
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100680 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700681
Aart Bikf8f5a162017-02-06 15:35:29 -0800682 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700683
Artem Serovcced8ba2017-07-19 18:18:09 +0100684 protected:
685 DEFAULT_COPY_CONSTRUCTOR(VecSub);
Aart Bikf8f5a162017-02-06 15:35:29 -0800686};
687
Aart Bik29aa0822018-03-08 11:28:00 -0800688// Subtracts every component in the two vectors using saturation arithmetic,
689// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 -_sat y1, .. , xn -_sat yn ]
690// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100691class HVecSaturationSub final : public HVecBinaryOperation {
Aart Bik29aa0822018-03-08 11:28:00 -0800692 public:
693 HVecSaturationSub(ArenaAllocator* allocator,
694 HInstruction* left,
695 HInstruction* right,
696 DataType::Type packed_type,
697 size_t vector_length,
698 uint32_t dex_pc)
699 : HVecBinaryOperation(
700 kVecSaturationSub, allocator, left, right, packed_type, vector_length, dex_pc) {
701 DCHECK(HasConsistentPackedTypes(left, packed_type));
702 DCHECK(HasConsistentPackedTypes(right, packed_type));
703 }
704
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100705 bool CanBeMoved() const override { return true; }
Aart Bik29aa0822018-03-08 11:28:00 -0800706
707 DECLARE_INSTRUCTION(VecSaturationSub);
708
709 protected:
710 DEFAULT_COPY_CONSTRUCTOR(VecSaturationSub);
711};
712
Aart Bikf8f5a162017-02-06 15:35:29 -0800713// Multiplies every component in the two vectors,
714// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100715class HVecMul final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800716 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100717 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800718 HInstruction* left,
719 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100720 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800721 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700722 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530723 : HVecBinaryOperation(kVecMul, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700724 DCHECK(HasConsistentPackedTypes(left, packed_type));
725 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800726 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700727
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100728 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700729
Aart Bikf8f5a162017-02-06 15:35:29 -0800730 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700731
Artem Serovcced8ba2017-07-19 18:18:09 +0100732 protected:
733 DEFAULT_COPY_CONSTRUCTOR(VecMul);
Aart Bikf8f5a162017-02-06 15:35:29 -0800734};
735
736// Divides every component in the two vectors,
737// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100738class HVecDiv final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800739 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100740 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800741 HInstruction* left,
742 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100743 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800744 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700745 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530746 : HVecBinaryOperation(kVecDiv, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700747 DCHECK(HasConsistentPackedTypes(left, packed_type));
748 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800749 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700750
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100751 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700752
Aart Bikf8f5a162017-02-06 15:35:29 -0800753 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700754
Artem Serovcced8ba2017-07-19 18:18:09 +0100755 protected:
756 DEFAULT_COPY_CONSTRUCTOR(VecDiv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800757};
758
Aart Bikf3e61ee2017-04-12 17:09:20 -0700759// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700760// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800761// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100762class HVecMin final : public HVecBinaryOperation {
Aart Bikf3e61ee2017-04-12 17:09:20 -0700763 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100764 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700765 HInstruction* left,
766 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100767 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700768 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700769 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530770 : HVecBinaryOperation(kVecMin, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700771 DCHECK(HasConsistentPackedTypes(left, packed_type));
772 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700773 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700774
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100775 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700776
Aart Bikf3e61ee2017-04-12 17:09:20 -0700777 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700778
Artem Serovcced8ba2017-07-19 18:18:09 +0100779 protected:
780 DEFAULT_COPY_CONSTRUCTOR(VecMin);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700781};
782
783// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700784// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800785// for either both signed or both unsigned operands x, y (reflected in packed_type).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100786class HVecMax final : public HVecBinaryOperation {
Aart Bikf3e61ee2017-04-12 17:09:20 -0700787 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100788 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700789 HInstruction* left,
790 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100791 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700792 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700793 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530794 : HVecBinaryOperation(kVecMax, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700795 DCHECK(HasConsistentPackedTypes(left, packed_type));
796 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700797 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700798
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100799 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700800
Aart Bikf3e61ee2017-04-12 17:09:20 -0700801 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700802
Artem Serovcced8ba2017-07-19 18:18:09 +0100803 protected:
804 DEFAULT_COPY_CONSTRUCTOR(VecMax);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700805};
806
Aart Bikf8f5a162017-02-06 15:35:29 -0800807// Bitwise-ands every component in the two vectors,
808// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100809class HVecAnd final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800810 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100811 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800812 HInstruction* left,
813 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100814 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800815 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700816 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530817 : HVecBinaryOperation(kVecAnd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800818 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800819 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700820
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100821 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700822
Aart Bikf8f5a162017-02-06 15:35:29 -0800823 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700824
Artem Serovcced8ba2017-07-19 18:18:09 +0100825 protected:
826 DEFAULT_COPY_CONSTRUCTOR(VecAnd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800827};
828
829// Bitwise-and-nots every component in the two vectors,
830// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100831class HVecAndNot final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800832 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100833 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800834 HInstruction* left,
835 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100836 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800837 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700838 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530839 : HVecBinaryOperation(
840 kVecAndNot, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800841 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800842 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700843
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100844 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700845
Aart Bikf8f5a162017-02-06 15:35:29 -0800846 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700847
Artem Serovcced8ba2017-07-19 18:18:09 +0100848 protected:
849 DEFAULT_COPY_CONSTRUCTOR(VecAndNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800850};
851
852// Bitwise-ors every component in the two vectors,
853// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100854class HVecOr final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800855 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100856 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800857 HInstruction* left,
858 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100859 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800860 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700861 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530862 : HVecBinaryOperation(kVecOr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800863 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800864 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700865
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100866 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700867
Aart Bikf8f5a162017-02-06 15:35:29 -0800868 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700869
Artem Serovcced8ba2017-07-19 18:18:09 +0100870 protected:
871 DEFAULT_COPY_CONSTRUCTOR(VecOr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800872};
873
874// Bitwise-xors every component in the two vectors,
875// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100876class HVecXor final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800877 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100878 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800879 HInstruction* left,
880 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100881 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800882 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700883 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530884 : HVecBinaryOperation(kVecXor, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800885 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800886 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700887
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100888 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700889
Aart Bikf8f5a162017-02-06 15:35:29 -0800890 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700891
Artem Serovcced8ba2017-07-19 18:18:09 +0100892 protected:
893 DEFAULT_COPY_CONSTRUCTOR(VecXor);
Aart Bikf8f5a162017-02-06 15:35:29 -0800894};
895
896// Logically shifts every component in the vector left by the given distance,
897// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100898class HVecShl final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800899 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100900 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800901 HInstruction* left,
902 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100903 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800904 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700905 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530906 : HVecBinaryOperation(kVecShl, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700907 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800908 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700909
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100910 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700911
Aart Bikf8f5a162017-02-06 15:35:29 -0800912 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700913
Artem Serovcced8ba2017-07-19 18:18:09 +0100914 protected:
915 DEFAULT_COPY_CONSTRUCTOR(VecShl);
Aart Bikf8f5a162017-02-06 15:35:29 -0800916};
917
918// Arithmetically shifts every component in the vector right by the given distance,
919// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100920class HVecShr final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800921 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100922 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800923 HInstruction* left,
924 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100925 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800926 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700927 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530928 : HVecBinaryOperation(kVecShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700929 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800930 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700931
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100932 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700933
Aart Bikf8f5a162017-02-06 15:35:29 -0800934 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700935
Artem Serovcced8ba2017-07-19 18:18:09 +0100936 protected:
937 DEFAULT_COPY_CONSTRUCTOR(VecShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800938};
939
940// Logically shifts every component in the vector right by the given distance,
941// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100942class HVecUShr final : public HVecBinaryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -0800943 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100944 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800945 HInstruction* left,
946 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100947 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800948 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700949 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530950 : HVecBinaryOperation(kVecUShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700951 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800952 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700953
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100954 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700955
Aart Bikf8f5a162017-02-06 15:35:29 -0800956 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700957
Artem Serovcced8ba2017-07-19 18:18:09 +0100958 protected:
959 DEFAULT_COPY_CONSTRUCTOR(VecUShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800960};
961
Aart Bik8de59162017-04-21 09:42:01 -0700962//
963// Definitions of concrete miscellaneous vector operations in HIR.
964//
965
966// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700967// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
968// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100969class HVecSetScalars final : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700970 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100971 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700972 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100973 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700974 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700975 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700976 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530977 : HVecOperation(kVecSetScalars,
978 allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700979 packed_type,
980 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700981 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700982 vector_length,
983 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700984 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik2dd7b672017-12-07 11:11:22 -0800985 DCHECK(!ReturnsSIMDValue(scalars[i]));
Aart Bik8de59162017-04-21 09:42:01 -0700986 SetRawInputAt(0, scalars[i]);
987 }
988 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700989
990 // Setting scalars needs to stay in place, since SIMD registers are not
991 // kept alive across vector loop boundaries (yet).
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100992 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700993
Aart Bik8de59162017-04-21 09:42:01 -0700994 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700995
Artem Serovcced8ba2017-07-19 18:18:09 +0100996 protected:
997 DEFAULT_COPY_CONSTRUCTOR(VecSetScalars);
Aart Bik8de59162017-04-21 09:42:01 -0700998};
999
Aart Bikdbbac8f2017-09-01 13:06:08 -07001000// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
1001// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Hans Boehm94344872018-07-13 09:57:50 -07001002// For floating point types, Java rounding behavior must be preserved; the products are rounded to
1003// the proper precision before being added. "Fused" multiply-add operations available on several
1004// architectures are not usable since they would violate Java language rules.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001005class HVecMultiplyAccumulate final : public HVecOperation {
Artem Serovf34dd202017-04-10 17:41:46 +01001006 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001007 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +01001008 InstructionKind op,
1009 HInstruction* accumulator,
1010 HInstruction* mul_left,
1011 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001012 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +01001013 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001014 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301015 : HVecOperation(kVecMultiplyAccumulate,
1016 allocator,
Artem Serovf34dd202017-04-10 17:41:46 +01001017 packed_type,
1018 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -08001019 /* number_of_inputs= */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +01001020 vector_length,
1021 dex_pc),
1022 op_kind_(op) {
1023 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -07001024 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1025 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
1026 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Hans Boehm94344872018-07-13 09:57:50 -07001027 // Remove the following if we add an architecture that supports floating point multiply-add
1028 // with Java-compatible rounding.
1029 DCHECK(DataType::IsIntegralType(packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -07001030 SetRawInputAt(0, accumulator);
1031 SetRawInputAt(1, mul_left);
1032 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +01001033 }
1034
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001035 bool CanBeMoved() const override { return true; }
Nicolas Geoffray9858bf72017-07-08 12:34:55 +00001036
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001037 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -07001038 DCHECK(other->IsVecMultiplyAccumulate());
1039 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
1040 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +01001041 }
1042
1043 InstructionKind GetOpKind() const { return op_kind_; }
1044
1045 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
1046
Artem Serovcced8ba2017-07-19 18:18:09 +01001047 protected:
1048 DEFAULT_COPY_CONSTRUCTOR(VecMultiplyAccumulate);
1049
Artem Serovf34dd202017-04-10 17:41:46 +01001050 private:
1051 // Indicates if this is a MADD or MSUB.
1052 const InstructionKind op_kind_;
Artem Serovf34dd202017-04-10 17:41:46 +01001053};
1054
Aart Bikdbbac8f2017-09-01 13:06:08 -07001055// Takes the absolute difference of two vectors, and adds the results to
1056// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001057// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -07001058// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -07001059// for m <= n, non-overlapping sums, and signed operands x, y.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001060class HVecSADAccumulate final : public HVecOperation {
Aart Bikdbbac8f2017-09-01 13:06:08 -07001061 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001062 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001063 HInstruction* accumulator,
1064 HInstruction* sad_left,
1065 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001066 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001067 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001068 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301069 : HVecOperation(kVecSADAccumulate,
1070 allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001071 packed_type,
1072 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -08001073 /* number_of_inputs= */ 3,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001074 vector_length,
1075 dex_pc) {
1076 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1077 DCHECK(sad_left->IsVecOperation());
1078 DCHECK(sad_right->IsVecOperation());
Vladimir Marko61b92282017-10-11 13:23:17 +01001079 DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
1080 ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
Aart Bikdbbac8f2017-09-01 13:06:08 -07001081 SetRawInputAt(0, accumulator);
1082 SetRawInputAt(1, sad_left);
1083 SetRawInputAt(2, sad_right);
1084 }
1085
1086 DECLARE_INSTRUCTION(VecSADAccumulate);
1087
Artem Serovcced8ba2017-07-19 18:18:09 +01001088 protected:
1089 DEFAULT_COPY_CONSTRUCTOR(VecSADAccumulate);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001090};
1091
Artem Serovaaac0e32018-08-07 00:52:22 +01001092// Performs dot product of two vectors and adds the result to wider precision components in
1093// the accumulator.
1094//
1095// viz. DOT_PRODUCT([ a1, .. , am], [ x1, .. , xn ], [ y1, .. , yn ]) =
1096// [ a1 + sum(xi * yi), .. , am + sum(xj * yj) ],
1097// for m <= n, non-overlapping sums,
1098// for either both signed or both unsigned operands x, y.
1099//
1100// Notes:
1101// - packed type reflects the type of sum reduction, not the type of the operands.
1102// - IsZeroExtending() is used to determine the kind of signed/zero extension to be
1103// performed for the operands.
1104//
1105// TODO: Support types other than kInt32 for packed type.
1106class HVecDotProd final : public HVecOperation {
1107 public:
1108 HVecDotProd(ArenaAllocator* allocator,
1109 HInstruction* accumulator,
1110 HInstruction* left,
1111 HInstruction* right,
1112 DataType::Type packed_type,
1113 bool is_zero_extending,
1114 size_t vector_length,
1115 uint32_t dex_pc)
1116 : HVecOperation(kVecDotProd,
1117 allocator,
1118 packed_type,
1119 SideEffects::None(),
Andreas Gampe3db70682018-12-26 15:12:03 -08001120 /* number_of_inputs= */ 3,
Artem Serovaaac0e32018-08-07 00:52:22 +01001121 vector_length,
1122 dex_pc) {
1123 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1124 DCHECK(DataType::IsIntegralType(packed_type));
1125 DCHECK(left->IsVecOperation());
1126 DCHECK(right->IsVecOperation());
1127 DCHECK_EQ(ToSignedType(left->AsVecOperation()->GetPackedType()),
1128 ToSignedType(right->AsVecOperation()->GetPackedType()));
1129 SetRawInputAt(0, accumulator);
1130 SetRawInputAt(1, left);
1131 SetRawInputAt(2, right);
1132 SetPackedFlag<kFieldHDotProdIsZeroExtending>(is_zero_extending);
1133 }
1134
1135 bool IsZeroExtending() const { return GetPackedFlag<kFieldHDotProdIsZeroExtending>(); }
1136
1137 bool CanBeMoved() const override { return true; }
1138
1139 DECLARE_INSTRUCTION(VecDotProd);
1140
1141 protected:
1142 DEFAULT_COPY_CONSTRUCTOR(VecDotProd);
1143
1144 private:
1145 // Additional packed bits.
1146 static constexpr size_t kFieldHDotProdIsZeroExtending =
1147 HVecOperation::kNumberOfVectorOpPackedBits;
1148 static constexpr size_t kNumberOfHDotProdPackedBits = kFieldHDotProdIsZeroExtending + 1;
1149 static_assert(kNumberOfHDotProdPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
1150};
1151
Aart Bikf8f5a162017-02-06 15:35:29 -08001152// Loads a vector from memory, viz. load(mem, 1)
1153// yield the vector [ mem(1), .. , mem(n) ].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001154class HVecLoad final : public HVecMemoryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -08001155 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001156 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001157 HInstruction* base,
1158 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001159 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001160 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001161 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -07001162 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001163 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301164 : HVecMemoryOperation(kVecLoad,
1165 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001166 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001167 side_effects,
Andreas Gampe3db70682018-12-26 15:12:03 -08001168 /* number_of_inputs= */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -08001169 vector_length,
1170 dex_pc) {
1171 SetRawInputAt(0, base);
1172 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -07001173 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -08001174 }
Aart Bikdb14fcf2017-04-25 15:53:58 -07001175
1176 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
1177
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001178 bool CanBeMoved() const override { return true; }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001179
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001180 bool InstructionDataEquals(const HInstruction* other) const override {
Aart Bikb79f4ac2017-07-10 10:10:37 -07001181 DCHECK(other->IsVecLoad());
1182 const HVecLoad* o = other->AsVecLoad();
1183 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
1184 }
1185
1186 DECLARE_INSTRUCTION(VecLoad);
1187
Artem Serovcced8ba2017-07-19 18:18:09 +01001188 protected:
1189 DEFAULT_COPY_CONSTRUCTOR(VecLoad);
1190
Aart Bikf8f5a162017-02-06 15:35:29 -08001191 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -07001192 // Additional packed bits.
1193 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
1194 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
1195 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf8f5a162017-02-06 15:35:29 -08001196};
1197
1198// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1199// sets mem(1) = x1, .. , mem(n) = xn.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001200class HVecStore final : public HVecMemoryOperation {
Aart Bikf8f5a162017-02-06 15:35:29 -08001201 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001202 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001203 HInstruction* base,
1204 HInstruction* index,
1205 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001206 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001207 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001208 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001209 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301210 : HVecMemoryOperation(kVecStore,
1211 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001212 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001213 side_effects,
Andreas Gampe3db70682018-12-26 15:12:03 -08001214 /* number_of_inputs= */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001215 vector_length,
1216 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001217 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001218 SetRawInputAt(0, base);
1219 SetRawInputAt(1, index);
1220 SetRawInputAt(2, value);
1221 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001222
1223 // A store needs to stay in place.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001224 bool CanBeMoved() const override { return false; }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001225
xueliang.zhongd71f1dc2018-01-24 17:24:16 +00001226 HInstruction* GetValue() const { return InputAt(2); }
1227
Aart Bikf8f5a162017-02-06 15:35:29 -08001228 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001229
Artem Serovcced8ba2017-07-19 18:18:09 +01001230 protected:
1231 DEFAULT_COPY_CONSTRUCTOR(VecStore)
Aart Bikf8f5a162017-02-06 15:35:29 -08001232};
1233
Artem Serov07718842020-02-24 18:51:42 +00001234//
1235// 'Predicate-setting' instructions.
1236//
1237
1238// An abstract class for instructions for which the output value is a vector predicate -
1239// a special kind of vector value:
1240//
1241// viz. [ p1, .. , pn ], where p_i is from { 0, 1 }.
1242//
1243// A VecOperation OP executes the same operation (e.g. ADD) on multiple elements of the vector.
1244// It can be either unpredicated (operation is done on ALL of the elements) or predicated (only
1245// on SOME elements, determined by a special extra input - vector predicate).
1246// Implementations can vary depending on the ISA; the general idea is that for each element of the
1247// regular vector a vector predicate has a corresponding element with either 0 or 1.
1248// The value determines whether a vector element will be involved in OP calculations or not
1249// (active or inactive). A vector predicate is referred as governing one if it is used to
1250// control the execution of a predicated instruction.
1251//
1252// Note: vector predicate value type is introduced alongside existing vectors of booleans and
1253// vectors of bytes to reflect their special semantics.
1254//
1255// TODO: we could introduce SIMD types in HIR.
1256class HVecPredSetOperation : public HVecOperation {
1257 public:
1258 // A vector predicate-setting operation looks like a Int64 location.
1259 // TODO: we could introduce vector types in HIR.
1260 static constexpr DataType::Type kSIMDPredType = DataType::Type::kInt64;
1261
1262 HVecPredSetOperation(InstructionKind kind,
1263 ArenaAllocator* allocator,
1264 DataType::Type packed_type,
1265 SideEffects side_effects,
1266 size_t number_of_inputs,
1267 size_t vector_length,
1268 uint32_t dex_pc)
1269 : HVecOperation(kind,
1270 allocator,
1271 packed_type,
1272 side_effects,
1273 number_of_inputs,
1274 vector_length,
1275 dex_pc) {
1276 // Overrides the kSIMDType set by the VecOperation constructor.
1277 SetPackedField<TypeField>(kSIMDPredType);
1278 }
1279
1280 bool CanBeMoved() const override { return true; }
1281
1282 DECLARE_ABSTRACT_INSTRUCTION(VecPredSetOperation);
1283
1284 protected:
1285 DEFAULT_COPY_CONSTRUCTOR(VecPredSetOperation);
1286};
1287
1288// Sets all the vector predicate elements as active or inactive.
1289//
1290// viz. [ p1, .. , pn ] = [ val, .. , val ] where val is from { 1, 0 }.
1291class HVecPredSetAll final : public HVecPredSetOperation {
1292 public:
1293 HVecPredSetAll(ArenaAllocator* allocator,
1294 HInstruction* input,
1295 DataType::Type packed_type,
1296 size_t vector_length,
1297 uint32_t dex_pc) :
1298 HVecPredSetOperation(kVecPredSetAll,
1299 allocator,
1300 packed_type,
1301 SideEffects::None(),
1302 /* number_of_inputs= */ 1,
1303 vector_length,
1304 dex_pc) {
1305 DCHECK(input->IsIntConstant());
1306 SetRawInputAt(0, input);
1307 MarkEmittedAtUseSite();
1308 }
1309
1310 // Having governing predicate doesn't make sense for set all TRUE/FALSE instruction.
1311 bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
1312
1313 bool IsSetTrue() const { return InputAt(0)->AsIntConstant()->IsTrue(); }
1314
1315 // Vector predicates are not kept alive across vector loop boundaries.
1316 bool CanBeMoved() const override { return false; }
1317
1318 DECLARE_INSTRUCTION(VecPredSetAll);
1319
1320 protected:
1321 DEFAULT_COPY_CONSTRUCTOR(VecPredSetAll);
1322};
1323
1324//
1325// Arm64 SVE-specific instructions.
1326//
1327// Classes of instructions which are specific to Arm64 SVE (though could be adopted
1328// by other targets, possibly being lowered to a number of ISA instructions) and
1329// implement SIMD loop predicated execution idiom.
1330//
1331
1332// Takes two scalar values x and y, creates a vector S: s(n) = x + n, compares (OP) each s(n)
1333// with y and set the corresponding element of the predicate register to the result of the
1334// comparison.
1335//
1336// viz. [ p1, .. , pn ] = [ x OP y , (x + 1) OP y, .. , (x + n) OP y ] where OP is CondKind
1337// condition.
1338class HVecPredWhile final : public HVecPredSetOperation {
1339 public:
1340 enum class CondKind {
1341 kLE, // signed less than or equal.
1342 kLO, // unsigned lower.
1343 kLS, // unsigned lower or same.
1344 kLT, // signed less.
1345 kLast = kLT,
1346 };
1347
1348 HVecPredWhile(ArenaAllocator* allocator,
1349 HInstruction* left,
1350 HInstruction* right,
1351 CondKind cond,
1352 DataType::Type packed_type,
1353 size_t vector_length,
1354 uint32_t dex_pc) :
1355 HVecPredSetOperation(kVecPredWhile,
1356 allocator,
1357 packed_type,
1358 SideEffects::None(),
1359 /* number_of_inputs= */ 2,
1360 vector_length,
1361 dex_pc) {
1362 DCHECK(!left->IsVecOperation());
1363 DCHECK(!left->IsVecPredSetOperation());
1364 DCHECK(!right->IsVecOperation());
1365 DCHECK(!right->IsVecPredSetOperation());
1366 DCHECK(DataType::IsIntegralType(left->GetType()));
1367 DCHECK(DataType::IsIntegralType(right->GetType()));
1368 SetRawInputAt(0, left);
1369 SetRawInputAt(1, right);
1370 SetPackedField<CondKindField>(cond);
1371 }
1372
1373 // This is a special loop control instruction which must not be predicated.
1374 bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
1375
1376 CondKind GetCondKind() const {
1377 return GetPackedField<CondKindField>();
1378 }
1379
1380 DECLARE_INSTRUCTION(VecPredWhile);
1381
1382 protected:
1383 // Additional packed bits.
1384 static constexpr size_t kCondKind = HVecOperation::kNumberOfVectorOpPackedBits;
1385 static constexpr size_t kCondKindSize =
1386 MinimumBitsToStore(static_cast<size_t>(CondKind::kLast));
1387 static constexpr size_t kNumberOfVecPredConditionPackedBits = kCondKind + kCondKindSize;
1388 static_assert(kNumberOfVecPredConditionPackedBits <= kMaxNumberOfPackedBits,
1389 "Too many packed fields.");
1390 using CondKindField = BitField<CondKind, kCondKind, kCondKindSize>;
1391
1392 DEFAULT_COPY_CONSTRUCTOR(VecPredWhile);
1393};
1394
1395// Evaluates the predicate condition (PCondKind) for a vector predicate; outputs
1396// a scalar boolean value result.
1397//
1398// Note: as VecPredCondition can be also predicated, only active elements (determined by the
1399// instruction's governing predicate) of the input vector predicate are used for condition
1400// evaluation.
1401//
1402// Note: this instruction is currently used as a workaround for the fact that IR instructions
1403// can't have more than one output.
1404class HVecPredCondition final : public HVecOperation {
1405 public:
1406 // To get more info on the condition kinds please see "2.2 Process state, PSTATE" section of
1407 // "ARM Architecture Reference Manual Supplement. The Scalable Vector Extension (SVE),
1408 // for ARMv8-A".
1409 enum class PCondKind {
1410 kNone, // No active elements were TRUE.
1411 kAny, // An active element was TRUE.
1412 kNLast, // The last active element was not TRUE.
1413 kLast, // The last active element was TRUE.
1414 kFirst, // The first active element was TRUE.
1415 kNFirst, // The first active element was not TRUE.
1416 kPMore, // An active element was TRUE but not the last active element.
1417 kPLast, // The last active element was TRUE or no active elements were TRUE.
1418 kEnumLast = kPLast
1419 };
1420
1421 HVecPredCondition(ArenaAllocator* allocator,
1422 HInstruction* input,
1423 PCondKind pred_cond,
1424 DataType::Type packed_type,
1425 size_t vector_length,
1426 uint32_t dex_pc)
1427 : HVecOperation(kVecPredCondition,
1428 allocator,
1429 packed_type,
1430 SideEffects::None(),
1431 /* number_of_inputs */ 1,
1432 vector_length,
1433 dex_pc) {
1434 DCHECK(input->IsVecPredSetOperation());
1435 SetRawInputAt(0, input);
1436 // Overrides the kSIMDType set by the VecOperation constructor.
1437 SetPackedField<TypeField>(DataType::Type::kBool);
1438 SetPackedField<CondKindField>(pred_cond);
1439 }
1440
1441 // This instruction is currently used only as a special loop control instruction
1442 // which must not be predicated.
1443 // TODO: Remove the constraint.
1444 bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
1445
1446 PCondKind GetPCondKind() const {
1447 return GetPackedField<CondKindField>();
1448 }
1449
1450 DECLARE_INSTRUCTION(VecPredCondition);
1451
1452 protected:
1453 // Additional packed bits.
1454 static constexpr size_t kCondKind = HVecOperation::kNumberOfVectorOpPackedBits;
1455 static constexpr size_t kCondKindSize =
1456 MinimumBitsToStore(static_cast<size_t>(PCondKind::kEnumLast));
1457 static constexpr size_t kNumberOfVecPredConditionPackedBits = kCondKind + kCondKindSize;
1458 static_assert(kNumberOfVecPredConditionPackedBits <= kMaxNumberOfPackedBits,
1459 "Too many packed fields.");
1460 using CondKindField = BitField<PCondKind, kCondKind, kCondKindSize>;
1461
1462 DEFAULT_COPY_CONSTRUCTOR(VecPredCondition);
1463};
1464
Aart Bikf8f5a162017-02-06 15:35:29 -08001465} // namespace art
1466
1467#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_