blob: 9b114eb1f7550adf091b02023c6bc51b3cce83da [file] [log] [blame]
Aart Bikf8f5a162017-02-06 15:35:29 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_
18#define ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_
19
20// This #include should never be used by compilation, because this header file (nodes_vector.h)
21// is included in the header file nodes.h itself. However it gives editing tools better context.
22#include "nodes.h"
23
24namespace art {
25
26// Memory alignment, represented as an offset relative to a base, where 0 <= offset < base,
27// and base is a power of two. For example, the value Alignment(16, 0) means memory is
28// perfectly aligned at a 16-byte boundary, whereas the value Alignment(16, 4) means
29// memory is always exactly 4 bytes above such a boundary.
30class Alignment {
31 public:
32 Alignment(size_t base, size_t offset) : base_(base), offset_(offset) {
33 DCHECK_LT(offset, base);
34 DCHECK(IsPowerOfTwo(base));
35 }
36
Aart Bik46b6dbc2017-10-03 11:37:37 -070037 // Returns true if memory is at least aligned at the given boundary.
Aart Bikf8f5a162017-02-06 15:35:29 -080038 // Assumes requested base is power of two.
39 bool IsAlignedAt(size_t base) const {
40 DCHECK_NE(0u, base);
41 DCHECK(IsPowerOfTwo(base));
42 return ((offset_ | base_) & (base - 1u)) == 0;
43 }
44
Aart Bik46b6dbc2017-10-03 11:37:37 -070045 size_t Base() const { return base_; }
46
47 size_t Offset() const { return offset_; }
48
Aart Bikf8f5a162017-02-06 15:35:29 -080049 std::string ToString() const {
50 return "ALIGN(" + std::to_string(base_) + "," + std::to_string(offset_) + ")";
51 }
52
Aart Bikb79f4ac2017-07-10 10:10:37 -070053 bool operator==(const Alignment& other) const {
54 return base_ == other.base_ && offset_ == other.offset_;
55 }
56
Aart Bikf8f5a162017-02-06 15:35:29 -080057 private:
58 size_t base_;
59 size_t offset_;
60};
61
62//
63// Definitions of abstract vector operations in HIR.
64//
65
66// Abstraction of a vector operation, i.e., an operation that performs
67// GetVectorLength() x GetPackedType() operations simultaneously.
68class HVecOperation : public HVariableInputSizeInstruction {
69 public:
Aart Bik0148de42017-09-05 09:25:01 -070070 // A SIMD operation looks like a FPU location.
71 // TODO: we could introduce SIMD types in HIR.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010072 static constexpr DataType::Type kSIMDType = DataType::Type::kFloat64;
Aart Bik0148de42017-09-05 09:25:01 -070073
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,
82 side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -080083 dex_pc,
Vladimir Markoe764d2e2017-10-05 14:35:55 +010084 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -080085 number_of_inputs,
86 kArenaAllocVectorNode),
87 vector_length_(vector_length) {
88 SetPackedField<TypeField>(packed_type);
89 DCHECK_LT(1u, vector_length);
90 }
91
92 // Returns the number of elements packed in a vector.
93 size_t GetVectorLength() const {
94 return vector_length_;
95 }
96
97 // Returns the number of bytes in a full vector.
98 size_t GetVectorNumberOfBytes() const {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010099 return vector_length_ * DataType::Size(GetPackedType());
Aart Bikf8f5a162017-02-06 15:35:29 -0800100 }
101
Aart Bik0148de42017-09-05 09:25:01 -0700102 // Returns the type of the vector operation.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100103 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700104 return kSIMDType;
Aart Bikf8f5a162017-02-06 15:35:29 -0800105 }
106
107 // Returns the true component type packed in a vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100108 DataType::Type GetPackedType() const {
Aart Bikf8f5a162017-02-06 15:35:29 -0800109 return GetPackedField<TypeField>();
110 }
111
Aart Bikb79f4ac2017-07-10 10:10:37 -0700112 // Assumes vector nodes cannot be moved by default. Each concrete implementation
113 // that can be moved should override this method and return true.
Artem Serov89ff8b22017-11-20 11:51:05 +0000114 //
115 // Note: similar approach is used for instruction scheduling (if it is turned on for the target):
116 // by default HScheduler::IsSchedulable returns false for a particular HVecOperation.
117 // HScheduler${ARCH}::IsSchedulable can be overridden to return true for an instruction (see
118 // scheduler_arm64.h for example) if it is safe to schedule it; in this case one *must* also
119 // look at/update HScheduler${ARCH}::IsSchedulingBarrier for this instruction.
120 //
121 // Note: For newly introduced vector instructions HScheduler${ARCH}::IsSchedulingBarrier must be
122 // altered to return true if the instruction might reside outside the SIMD loop body since SIMD
123 // registers are not kept alive across vector loop boundaries (yet).
Aart Bikb79f4ac2017-07-10 10:10:37 -0700124 bool CanBeMoved() const OVERRIDE { return false; }
125
126 // Tests if all data of a vector node (vector length and packed type) is equal.
127 // Each concrete implementation that adds more fields should test equality of
128 // those fields in its own method *and* call all super methods.
129 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
130 DCHECK(other->IsVecOperation());
131 const HVecOperation* o = other->AsVecOperation();
132 return GetVectorLength() == o->GetVectorLength() && GetPackedType() == o->GetPackedType();
133 }
134
Aart Bik46b6dbc2017-10-03 11:37:37 -0700135 // Maps an integral type to the same-size signed type and leaves other types alone.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700136 static DataType::Type ToSignedType(DataType::Type type) {
137 switch (type) {
138 case DataType::Type::kBool: // 1-byte storage unit
139 case DataType::Type::kUint8:
140 return DataType::Type::kInt8;
141 case DataType::Type::kUint16:
142 return DataType::Type::kInt16;
143 default:
144 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
145 return type;
146 }
147 }
148
Aart Bik4d1a9d42017-10-19 14:40:55 -0700149 // Maps an integral type to the same-size unsigned type and leaves other types alone.
150 static DataType::Type ToUnsignedType(DataType::Type type) {
151 switch (type) {
152 case DataType::Type::kBool: // 1-byte storage unit
153 case DataType::Type::kInt8:
154 return DataType::Type::kUint8;
155 case DataType::Type::kInt16:
156 return DataType::Type::kUint16;
157 default:
158 DCHECK(type != DataType::Type::kVoid && type != DataType::Type::kReference) << type;
159 return type;
160 }
161 }
162
Aart Bik66c158e2018-01-31 12:55:04 -0800163 // Maps an integral type to the same-size (un)signed type. Leaves other types alone.
164 static DataType::Type ToProperType(DataType::Type type, bool is_unsigned) {
165 return is_unsigned ? ToUnsignedType(type) : ToSignedType(type);
166 }
167
Aart Bik2dd7b672017-12-07 11:11:22 -0800168 // Helper method to determine if an instruction returns a SIMD value.
169 // TODO: This method is needed until we introduce SIMD as proper type.
170 static bool ReturnsSIMDValue(HInstruction* instruction) {
171 if (instruction->IsVecOperation()) {
172 return !instruction->IsVecExtractScalar(); // only scalar returning vec op
173 } else if (instruction->IsPhi()) {
174 return
175 instruction->GetType() == kSIMDType &&
176 instruction->InputAt(1)->IsVecOperation(); // vectorizer does not go deeper
177 }
178 return false;
179 }
180
Aart Bikf8f5a162017-02-06 15:35:29 -0800181 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
182
Aart Bikdb14fcf2017-04-25 15:53:58 -0700183 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800184 // Additional packed bits.
185 static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits;
186 static constexpr size_t kFieldTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100187 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Aart Bikf8f5a162017-02-06 15:35:29 -0800188 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldType + kFieldTypeSize;
189 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100190 using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800191
Artem Serovcced8ba2017-07-19 18:18:09 +0100192 DEFAULT_COPY_CONSTRUCTOR(VecOperation);
193
Aart Bikdb14fcf2017-04-25 15:53:58 -0700194 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800195 const size_t vector_length_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800196};
197
198// Abstraction of a unary vector operation.
199class HVecUnaryOperation : public HVecOperation {
200 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530201 HVecUnaryOperation(InstructionKind kind,
202 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700203 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100204 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800205 size_t vector_length,
206 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530207 : HVecOperation(kind,
208 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800209 packed_type,
210 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700211 /* number_of_inputs */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800212 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700213 dex_pc) {
214 SetRawInputAt(0, input);
215 }
216
217 HInstruction* GetInput() const { return InputAt(0); }
218
Aart Bikf8f5a162017-02-06 15:35:29 -0800219 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700220
Artem Serovcced8ba2017-07-19 18:18:09 +0100221 protected:
222 DEFAULT_COPY_CONSTRUCTOR(VecUnaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800223};
224
225// Abstraction of a binary vector operation.
226class HVecBinaryOperation : public HVecOperation {
227 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530228 HVecBinaryOperation(InstructionKind kind,
229 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700230 HInstruction* left,
231 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100232 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800233 size_t vector_length,
234 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530235 : HVecOperation(kind,
236 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800237 packed_type,
238 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700239 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800240 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700241 dex_pc) {
242 SetRawInputAt(0, left);
243 SetRawInputAt(1, right);
244 }
Artem Serovf34dd202017-04-10 17:41:46 +0100245
246 HInstruction* GetLeft() const { return InputAt(0); }
247 HInstruction* GetRight() const { return InputAt(1); }
248
Aart Bikf8f5a162017-02-06 15:35:29 -0800249 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700250
Artem Serovcced8ba2017-07-19 18:18:09 +0100251 protected:
252 DEFAULT_COPY_CONSTRUCTOR(VecBinaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800253};
254
255// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700256// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800257class HVecMemoryOperation : public HVecOperation {
258 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530259 HVecMemoryOperation(InstructionKind kind,
260 ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100261 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800262 SideEffects side_effects,
263 size_t number_of_inputs,
264 size_t vector_length,
265 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530266 : HVecOperation(kind,
267 allocator,
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100268 packed_type,
269 side_effects,
270 number_of_inputs,
271 vector_length,
272 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100273 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100274 DCHECK_GE(number_of_inputs, 2u);
275 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800276
277 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
278
279 Alignment GetAlignment() const { return alignment_; }
280
Artem Serove1811ed2017-04-27 16:50:47 +0100281 HInstruction* GetArray() const { return InputAt(0); }
282 HInstruction* GetIndex() const { return InputAt(1); }
283
Aart Bikb79f4ac2017-07-10 10:10:37 -0700284 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
285 DCHECK(other->IsVecMemoryOperation());
286 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
287 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
288 }
289
Aart Bikf8f5a162017-02-06 15:35:29 -0800290 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
291
Artem Serovcced8ba2017-07-19 18:18:09 +0100292 protected:
293 DEFAULT_COPY_CONSTRUCTOR(VecMemoryOperation);
294
Aart Bikf8f5a162017-02-06 15:35:29 -0800295 private:
296 Alignment alignment_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800297};
298
Aart Bik0148de42017-09-05 09:25:01 -0700299// Packed type consistency checker ("same vector length" integral types may mix freely).
Aart Bik66c158e2018-01-31 12:55:04 -0800300// Tests relaxed type consistency in which packed same-size integral types can co-exist,
301// but other type mixes are an error.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100302inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700303 if (input->IsPhi()) {
304 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
305 }
Aart Bikd58bc322017-05-01 14:49:18 -0700306 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100307 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik4d1a9d42017-10-19 14:40:55 -0700308 DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
309 HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
Aart Bik46b6dbc2017-10-03 11:37:37 -0700310 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700311}
312
Aart Bikf8f5a162017-02-06 15:35:29 -0800313//
Aart Bik8de59162017-04-21 09:42:01 -0700314// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800315//
316
317// Replicates the given scalar into a vector,
318// viz. replicate(x) = [ x, .. , x ].
319class HVecReplicateScalar FINAL : public HVecUnaryOperation {
320 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100321 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800322 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100323 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800324 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700325 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530326 : HVecUnaryOperation(
327 kVecReplicateScalar, allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik5a0eb0c2018-03-16 15:00:19 -0700328 DCHECK(!ReturnsSIMDValue(scalar));
Aart Bikf8f5a162017-02-06 15:35:29 -0800329 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700330
331 // A replicate needs to stay in place, since SIMD registers are not
332 // kept alive across vector loop boundaries (yet).
333 bool CanBeMoved() const OVERRIDE { return false; }
334
Aart Bikf8f5a162017-02-06 15:35:29 -0800335 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700336
Artem Serovcced8ba2017-07-19 18:18:09 +0100337 protected:
338 DEFAULT_COPY_CONSTRUCTOR(VecReplicateScalar);
Aart Bikf8f5a162017-02-06 15:35:29 -0800339};
340
Aart Bik0148de42017-09-05 09:25:01 -0700341// Extracts a particular scalar from the given vector,
342// viz. extract[ x1, .. , xn ] = x_i.
343//
344// TODO: for now only i == 1 case supported.
345class HVecExtractScalar FINAL : public HVecUnaryOperation {
346 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100347 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700348 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100349 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700350 size_t vector_length,
351 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700352 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530353 : HVecUnaryOperation(
354 kVecExtractScalar, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700355 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700356 DCHECK_LT(index, vector_length);
357 DCHECK_EQ(index, 0u);
358 }
359
360 // Yields a single component in the vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100361 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700362 return GetPackedType();
363 }
364
365 // An extract needs to stay in place, since SIMD registers are not
366 // kept alive across vector loop boundaries (yet).
367 bool CanBeMoved() const OVERRIDE { return false; }
368
369 DECLARE_INSTRUCTION(VecExtractScalar);
370
Artem Serovcced8ba2017-07-19 18:18:09 +0100371 protected:
372 DEFAULT_COPY_CONSTRUCTOR(VecExtractScalar);
Aart Bik0148de42017-09-05 09:25:01 -0700373};
374
375// Reduces the given vector into the first element as sum/min/max,
376// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
377// and the "-" denotes "don't care" (implementation dependent).
378class HVecReduce FINAL : public HVecUnaryOperation {
379 public:
380 enum ReductionKind {
381 kSum = 1,
382 kMin = 2,
383 kMax = 3
384 };
385
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100386 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700387 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100388 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700389 size_t vector_length,
390 ReductionKind kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700391 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530392 : HVecUnaryOperation(kVecReduce, allocator, input, packed_type, vector_length, dex_pc),
Aart Bik0148de42017-09-05 09:25:01 -0700393 kind_(kind) {
394 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700395 }
396
Aart Bik0148de42017-09-05 09:25:01 -0700397 ReductionKind GetKind() const { return kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800398
Aart Bikb79f4ac2017-07-10 10:10:37 -0700399 bool CanBeMoved() const OVERRIDE { return true; }
400
Aart Bik0148de42017-09-05 09:25:01 -0700401 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
402 DCHECK(other->IsVecReduce());
403 const HVecReduce* o = other->AsVecReduce();
404 return HVecOperation::InstructionDataEquals(o) && GetKind() == o->GetKind();
405 }
406
407 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700408
Artem Serovcced8ba2017-07-19 18:18:09 +0100409 protected:
410 DEFAULT_COPY_CONSTRUCTOR(VecReduce);
411
Aart Bikf8f5a162017-02-06 15:35:29 -0800412 private:
Aart Bik0148de42017-09-05 09:25:01 -0700413 const ReductionKind kind_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800414};
415
416// Converts every component in the vector,
417// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
418class HVecCnv FINAL : public HVecUnaryOperation {
419 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100420 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800421 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100422 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800423 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700424 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530425 : HVecUnaryOperation(kVecCnv, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800426 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700427 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800428 }
429
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100430 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
431 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800432
Aart Bikb79f4ac2017-07-10 10:10:37 -0700433 bool CanBeMoved() const OVERRIDE { return true; }
434
Aart Bikf8f5a162017-02-06 15:35:29 -0800435 DECLARE_INSTRUCTION(VecCnv);
436
Artem Serovcced8ba2017-07-19 18:18:09 +0100437 protected:
438 DEFAULT_COPY_CONSTRUCTOR(VecCnv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800439};
440
441// Negates every component in the vector,
442// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
443class HVecNeg FINAL : public HVecUnaryOperation {
444 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100445 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800446 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100447 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800448 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700449 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530450 : HVecUnaryOperation(kVecNeg, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700451 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800452 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700453
454 bool CanBeMoved() const OVERRIDE { return true; }
455
Aart Bikf8f5a162017-02-06 15:35:29 -0800456 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700457
Artem Serovcced8ba2017-07-19 18:18:09 +0100458 protected:
459 DEFAULT_COPY_CONSTRUCTOR(VecNeg);
Aart Bikf8f5a162017-02-06 15:35:29 -0800460};
461
Aart Bik6daebeb2017-04-03 14:35:41 -0700462// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700463// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
464// for signed operand x.
Aart Bik6daebeb2017-04-03 14:35:41 -0700465class HVecAbs FINAL : public HVecUnaryOperation {
466 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100467 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700468 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100469 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700470 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700471 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530472 : HVecUnaryOperation(kVecAbs, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700473 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700474 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700475
476 bool CanBeMoved() const OVERRIDE { return true; }
477
Aart Bik6daebeb2017-04-03 14:35:41 -0700478 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700479
Artem Serovcced8ba2017-07-19 18:18:09 +0100480 protected:
481 DEFAULT_COPY_CONSTRUCTOR(VecAbs);
Aart Bik6daebeb2017-04-03 14:35:41 -0700482};
483
Aart Bikf8f5a162017-02-06 15:35:29 -0800484// Bitwise- or boolean-nots every component in the vector,
485// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
486// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
487class HVecNot FINAL : public HVecUnaryOperation {
488 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100489 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800490 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100491 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800492 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700493 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530494 : HVecUnaryOperation(kVecNot, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800495 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800496 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700497
498 bool CanBeMoved() const OVERRIDE { return true; }
499
Aart Bikf8f5a162017-02-06 15:35:29 -0800500 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700501
Artem Serovcced8ba2017-07-19 18:18:09 +0100502 protected:
503 DEFAULT_COPY_CONSTRUCTOR(VecNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800504};
505
Aart Bik8de59162017-04-21 09:42:01 -0700506//
507// Definitions of concrete binary vector operations in HIR.
508//
509
Aart Bikf8f5a162017-02-06 15:35:29 -0800510// Adds every component in the two vectors,
511// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
512class HVecAdd FINAL : public HVecBinaryOperation {
513 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100514 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800515 HInstruction* left,
516 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100517 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800518 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700519 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530520 : HVecBinaryOperation(kVecAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700521 DCHECK(HasConsistentPackedTypes(left, packed_type));
522 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800523 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700524
525 bool CanBeMoved() const OVERRIDE { return true; }
526
Aart Bikf8f5a162017-02-06 15:35:29 -0800527 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700528
Artem Serovcced8ba2017-07-19 18:18:09 +0100529 protected:
530 DEFAULT_COPY_CONSTRUCTOR(VecAdd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800531};
532
Aart Bik29aa0822018-03-08 11:28:00 -0800533// Adds every component in the two vectors using saturation arithmetic,
534// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 +_sat y1, .. , xn +_sat yn ]
535// for either both signed or both unsigned operands x, y (reflected in packed_type).
536class HVecSaturationAdd FINAL : public HVecBinaryOperation {
537 public:
538 HVecSaturationAdd(ArenaAllocator* allocator,
539 HInstruction* left,
540 HInstruction* right,
541 DataType::Type packed_type,
542 size_t vector_length,
543 uint32_t dex_pc)
544 : HVecBinaryOperation(
545 kVecSaturationAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
546 DCHECK(HasConsistentPackedTypes(left, packed_type));
547 DCHECK(HasConsistentPackedTypes(right, packed_type));
548 }
549
550 bool CanBeMoved() const OVERRIDE { return true; }
551
552 DECLARE_INSTRUCTION(VecSaturationAdd);
553
554 protected:
555 DEFAULT_COPY_CONSTRUCTOR(VecSaturationAdd);
556};
557
Aart Bikf3e61ee2017-04-12 17:09:20 -0700558// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700559// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
560// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik66c158e2018-01-31 12:55:04 -0800561// for either both signed or both unsigned operands x, y (reflected in packed_type).
Aart Bikf3e61ee2017-04-12 17:09:20 -0700562class HVecHalvingAdd FINAL : public HVecBinaryOperation {
563 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100564 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700565 HInstruction* left,
566 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100567 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700568 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700569 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700570 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530571 : HVecBinaryOperation(
572 kVecHalvingAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700573 DCHECK(HasConsistentPackedTypes(left, packed_type));
574 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700575 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700576 }
577
Aart Bikdb14fcf2017-04-25 15:53:58 -0700578 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700579
Aart Bikb79f4ac2017-07-10 10:10:37 -0700580 bool CanBeMoved() const OVERRIDE { return true; }
581
582 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
583 DCHECK(other->IsVecHalvingAdd());
584 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
Aart Bik66c158e2018-01-31 12:55:04 -0800585 return HVecOperation::InstructionDataEquals(o) && IsRounded() == o->IsRounded();
Aart Bikb79f4ac2017-07-10 10:10:37 -0700586 }
587
Aart Bikf3e61ee2017-04-12 17:09:20 -0700588 DECLARE_INSTRUCTION(VecHalvingAdd);
589
Artem Serovcced8ba2017-07-19 18:18:09 +0100590 protected:
591 DEFAULT_COPY_CONSTRUCTOR(VecHalvingAdd);
592
Aart Bikf3e61ee2017-04-12 17:09:20 -0700593 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700594 // Additional packed bits.
Aart Bik66c158e2018-01-31 12:55:04 -0800595 static constexpr size_t kFieldHAddIsRounded = HVecOperation::kNumberOfVectorOpPackedBits;
Aart Bikdb14fcf2017-04-25 15:53:58 -0700596 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
597 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700598};
599
Aart Bikf8f5a162017-02-06 15:35:29 -0800600// Subtracts every component in the two vectors,
601// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
602class HVecSub FINAL : public HVecBinaryOperation {
603 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100604 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800605 HInstruction* left,
606 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100607 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800608 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700609 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530610 : HVecBinaryOperation(kVecSub, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700611 DCHECK(HasConsistentPackedTypes(left, packed_type));
612 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800613 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700614
615 bool CanBeMoved() const OVERRIDE { return true; }
616
Aart Bikf8f5a162017-02-06 15:35:29 -0800617 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700618
Artem Serovcced8ba2017-07-19 18:18:09 +0100619 protected:
620 DEFAULT_COPY_CONSTRUCTOR(VecSub);
Aart Bikf8f5a162017-02-06 15:35:29 -0800621};
622
Aart Bik29aa0822018-03-08 11:28:00 -0800623// Subtracts every component in the two vectors using saturation arithmetic,
624// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 -_sat y1, .. , xn -_sat yn ]
625// for either both signed or both unsigned operands x, y (reflected in packed_type).
626class HVecSaturationSub FINAL : public HVecBinaryOperation {
627 public:
628 HVecSaturationSub(ArenaAllocator* allocator,
629 HInstruction* left,
630 HInstruction* right,
631 DataType::Type packed_type,
632 size_t vector_length,
633 uint32_t dex_pc)
634 : HVecBinaryOperation(
635 kVecSaturationSub, allocator, left, right, packed_type, vector_length, dex_pc) {
636 DCHECK(HasConsistentPackedTypes(left, packed_type));
637 DCHECK(HasConsistentPackedTypes(right, packed_type));
638 }
639
640 bool CanBeMoved() const OVERRIDE { return true; }
641
642 DECLARE_INSTRUCTION(VecSaturationSub);
643
644 protected:
645 DEFAULT_COPY_CONSTRUCTOR(VecSaturationSub);
646};
647
Aart Bikf8f5a162017-02-06 15:35:29 -0800648// Multiplies every component in the two vectors,
649// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
650class HVecMul FINAL : public HVecBinaryOperation {
651 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100652 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800653 HInstruction* left,
654 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100655 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800656 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700657 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530658 : HVecBinaryOperation(kVecMul, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700659 DCHECK(HasConsistentPackedTypes(left, packed_type));
660 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800661 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700662
663 bool CanBeMoved() const OVERRIDE { return true; }
664
Aart Bikf8f5a162017-02-06 15:35:29 -0800665 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700666
Artem Serovcced8ba2017-07-19 18:18:09 +0100667 protected:
668 DEFAULT_COPY_CONSTRUCTOR(VecMul);
Aart Bikf8f5a162017-02-06 15:35:29 -0800669};
670
671// Divides every component in the two vectors,
672// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
673class HVecDiv FINAL : public HVecBinaryOperation {
674 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100675 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800676 HInstruction* left,
677 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100678 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800679 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700680 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530681 : HVecBinaryOperation(kVecDiv, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700682 DCHECK(HasConsistentPackedTypes(left, packed_type));
683 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800684 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700685
686 bool CanBeMoved() const OVERRIDE { return true; }
687
Aart Bikf8f5a162017-02-06 15:35:29 -0800688 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700689
Artem Serovcced8ba2017-07-19 18:18:09 +0100690 protected:
691 DEFAULT_COPY_CONSTRUCTOR(VecDiv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800692};
693
Aart Bikf3e61ee2017-04-12 17:09:20 -0700694// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700695// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800696// for either both signed or both unsigned operands x, y (reflected in packed_type).
Aart Bikf3e61ee2017-04-12 17:09:20 -0700697class HVecMin FINAL : public HVecBinaryOperation {
698 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100699 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700700 HInstruction* left,
701 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100702 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700703 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700704 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530705 : HVecBinaryOperation(kVecMin, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700706 DCHECK(HasConsistentPackedTypes(left, packed_type));
707 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700708 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700709
Aart Bikb79f4ac2017-07-10 10:10:37 -0700710 bool CanBeMoved() const OVERRIDE { return true; }
711
Aart Bikf3e61ee2017-04-12 17:09:20 -0700712 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700713
Artem Serovcced8ba2017-07-19 18:18:09 +0100714 protected:
715 DEFAULT_COPY_CONSTRUCTOR(VecMin);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700716};
717
718// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700719// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800720// for either both signed or both unsigned operands x, y (reflected in packed_type).
Aart Bikf3e61ee2017-04-12 17:09:20 -0700721class HVecMax FINAL : public HVecBinaryOperation {
722 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100723 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700724 HInstruction* left,
725 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100726 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700727 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700728 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530729 : HVecBinaryOperation(kVecMax, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700730 DCHECK(HasConsistentPackedTypes(left, packed_type));
731 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700732 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700733
Aart Bikb79f4ac2017-07-10 10:10:37 -0700734 bool CanBeMoved() const OVERRIDE { return true; }
735
Aart Bikf3e61ee2017-04-12 17:09:20 -0700736 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700737
Artem Serovcced8ba2017-07-19 18:18:09 +0100738 protected:
739 DEFAULT_COPY_CONSTRUCTOR(VecMax);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700740};
741
Aart Bikf8f5a162017-02-06 15:35:29 -0800742// Bitwise-ands every component in the two vectors,
743// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
744class HVecAnd FINAL : public HVecBinaryOperation {
745 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100746 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800747 HInstruction* left,
748 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100749 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800750 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700751 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530752 : HVecBinaryOperation(kVecAnd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800753 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800754 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700755
756 bool CanBeMoved() const OVERRIDE { return true; }
757
Aart Bikf8f5a162017-02-06 15:35:29 -0800758 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700759
Artem Serovcced8ba2017-07-19 18:18:09 +0100760 protected:
761 DEFAULT_COPY_CONSTRUCTOR(VecAnd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800762};
763
764// Bitwise-and-nots every component in the two vectors,
765// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
766class HVecAndNot FINAL : public HVecBinaryOperation {
767 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100768 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800769 HInstruction* left,
770 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100771 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800772 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700773 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530774 : HVecBinaryOperation(
775 kVecAndNot, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800776 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800777 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700778
779 bool CanBeMoved() const OVERRIDE { return true; }
780
Aart Bikf8f5a162017-02-06 15:35:29 -0800781 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700782
Artem Serovcced8ba2017-07-19 18:18:09 +0100783 protected:
784 DEFAULT_COPY_CONSTRUCTOR(VecAndNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800785};
786
787// Bitwise-ors every component in the two vectors,
788// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
789class HVecOr FINAL : public HVecBinaryOperation {
790 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100791 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800792 HInstruction* left,
793 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100794 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800795 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700796 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530797 : HVecBinaryOperation(kVecOr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800798 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800799 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700800
801 bool CanBeMoved() const OVERRIDE { return true; }
802
Aart Bikf8f5a162017-02-06 15:35:29 -0800803 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700804
Artem Serovcced8ba2017-07-19 18:18:09 +0100805 protected:
806 DEFAULT_COPY_CONSTRUCTOR(VecOr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800807};
808
809// Bitwise-xors every component in the two vectors,
810// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
811class HVecXor FINAL : public HVecBinaryOperation {
812 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100813 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800814 HInstruction* left,
815 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100816 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800817 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700818 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530819 : HVecBinaryOperation(kVecXor, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800820 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800821 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700822
823 bool CanBeMoved() const OVERRIDE { return true; }
824
Aart Bikf8f5a162017-02-06 15:35:29 -0800825 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700826
Artem Serovcced8ba2017-07-19 18:18:09 +0100827 protected:
828 DEFAULT_COPY_CONSTRUCTOR(VecXor);
Aart Bikf8f5a162017-02-06 15:35:29 -0800829};
830
831// Logically shifts every component in the vector left by the given distance,
832// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
833class HVecShl FINAL : public HVecBinaryOperation {
834 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100835 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800836 HInstruction* left,
837 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100838 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800839 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700840 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530841 : HVecBinaryOperation(kVecShl, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700842 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800843 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700844
845 bool CanBeMoved() const OVERRIDE { return true; }
846
Aart Bikf8f5a162017-02-06 15:35:29 -0800847 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700848
Artem Serovcced8ba2017-07-19 18:18:09 +0100849 protected:
850 DEFAULT_COPY_CONSTRUCTOR(VecShl);
Aart Bikf8f5a162017-02-06 15:35:29 -0800851};
852
853// Arithmetically shifts every component in the vector right by the given distance,
854// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
855class HVecShr FINAL : public HVecBinaryOperation {
856 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100857 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800858 HInstruction* left,
859 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100860 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800861 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700862 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530863 : HVecBinaryOperation(kVecShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700864 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800865 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700866
867 bool CanBeMoved() const OVERRIDE { return true; }
868
Aart Bikf8f5a162017-02-06 15:35:29 -0800869 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700870
Artem Serovcced8ba2017-07-19 18:18:09 +0100871 protected:
872 DEFAULT_COPY_CONSTRUCTOR(VecShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800873};
874
875// Logically shifts every component in the vector right by the given distance,
876// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
877class HVecUShr FINAL : public HVecBinaryOperation {
878 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100879 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800880 HInstruction* left,
881 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100882 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800883 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700884 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530885 : HVecBinaryOperation(kVecUShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700886 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800887 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700888
889 bool CanBeMoved() const OVERRIDE { return true; }
890
Aart Bikf8f5a162017-02-06 15:35:29 -0800891 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700892
Artem Serovcced8ba2017-07-19 18:18:09 +0100893 protected:
894 DEFAULT_COPY_CONSTRUCTOR(VecUShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800895};
896
Aart Bik8de59162017-04-21 09:42:01 -0700897//
898// Definitions of concrete miscellaneous vector operations in HIR.
899//
900
901// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700902// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
903// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Aart Bik8de59162017-04-21 09:42:01 -0700904class HVecSetScalars FINAL : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700905 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100906 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700907 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100908 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700909 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700910 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700911 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530912 : HVecOperation(kVecSetScalars,
913 allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700914 packed_type,
915 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700916 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700917 vector_length,
918 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700919 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik2dd7b672017-12-07 11:11:22 -0800920 DCHECK(!ReturnsSIMDValue(scalars[i]));
Aart Bik8de59162017-04-21 09:42:01 -0700921 SetRawInputAt(0, scalars[i]);
922 }
923 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700924
925 // Setting scalars needs to stay in place, since SIMD registers are not
926 // kept alive across vector loop boundaries (yet).
927 bool CanBeMoved() const OVERRIDE { return false; }
928
Aart Bik8de59162017-04-21 09:42:01 -0700929 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700930
Artem Serovcced8ba2017-07-19 18:18:09 +0100931 protected:
932 DEFAULT_COPY_CONSTRUCTOR(VecSetScalars);
Aart Bik8de59162017-04-21 09:42:01 -0700933};
934
Aart Bikdbbac8f2017-09-01 13:06:08 -0700935// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
936// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Artem Serovf34dd202017-04-10 17:41:46 +0100937class HVecMultiplyAccumulate FINAL : public HVecOperation {
938 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100939 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100940 InstructionKind op,
941 HInstruction* accumulator,
942 HInstruction* mul_left,
943 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100944 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +0100945 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700946 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530947 : HVecOperation(kVecMultiplyAccumulate,
948 allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100949 packed_type,
950 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700951 /* number_of_inputs */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +0100952 vector_length,
953 dex_pc),
954 op_kind_(op) {
955 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -0700956 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
957 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
958 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700959 SetRawInputAt(0, accumulator);
960 SetRawInputAt(1, mul_left);
961 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +0100962 }
963
Nicolas Geoffray9858bf72017-07-08 12:34:55 +0000964 bool CanBeMoved() const OVERRIDE { return true; }
965
Artem Serovf34dd202017-04-10 17:41:46 +0100966 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700967 DCHECK(other->IsVecMultiplyAccumulate());
968 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
969 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +0100970 }
971
972 InstructionKind GetOpKind() const { return op_kind_; }
973
974 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
975
Artem Serovcced8ba2017-07-19 18:18:09 +0100976 protected:
977 DEFAULT_COPY_CONSTRUCTOR(VecMultiplyAccumulate);
978
Artem Serovf34dd202017-04-10 17:41:46 +0100979 private:
980 // Indicates if this is a MADD or MSUB.
981 const InstructionKind op_kind_;
Artem Serovf34dd202017-04-10 17:41:46 +0100982};
983
Aart Bikdbbac8f2017-09-01 13:06:08 -0700984// Takes the absolute difference of two vectors, and adds the results to
985// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700986// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -0700987// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -0700988// for m <= n, non-overlapping sums, and signed operands x, y.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700989class HVecSADAccumulate FINAL : public HVecOperation {
990 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100991 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700992 HInstruction* accumulator,
993 HInstruction* sad_left,
994 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100995 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700996 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700997 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530998 : HVecOperation(kVecSADAccumulate,
999 allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001000 packed_type,
1001 SideEffects::None(),
1002 /* number_of_inputs */ 3,
1003 vector_length,
1004 dex_pc) {
1005 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1006 DCHECK(sad_left->IsVecOperation());
1007 DCHECK(sad_right->IsVecOperation());
Vladimir Marko61b92282017-10-11 13:23:17 +01001008 DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
1009 ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
Aart Bikdbbac8f2017-09-01 13:06:08 -07001010 SetRawInputAt(0, accumulator);
1011 SetRawInputAt(1, sad_left);
1012 SetRawInputAt(2, sad_right);
1013 }
1014
1015 DECLARE_INSTRUCTION(VecSADAccumulate);
1016
Artem Serovcced8ba2017-07-19 18:18:09 +01001017 protected:
1018 DEFAULT_COPY_CONSTRUCTOR(VecSADAccumulate);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001019};
1020
Aart Bikf8f5a162017-02-06 15:35:29 -08001021// Loads a vector from memory, viz. load(mem, 1)
1022// yield the vector [ mem(1), .. , mem(n) ].
1023class HVecLoad FINAL : public HVecMemoryOperation {
1024 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001025 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001026 HInstruction* base,
1027 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001028 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001029 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001030 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -07001031 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001032 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301033 : HVecMemoryOperation(kVecLoad,
1034 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001035 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001036 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001037 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -08001038 vector_length,
1039 dex_pc) {
1040 SetRawInputAt(0, base);
1041 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -07001042 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -08001043 }
Aart Bikdb14fcf2017-04-25 15:53:58 -07001044
1045 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
1046
Aart Bikb79f4ac2017-07-10 10:10:37 -07001047 bool CanBeMoved() const OVERRIDE { return true; }
1048
1049 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
1050 DCHECK(other->IsVecLoad());
1051 const HVecLoad* o = other->AsVecLoad();
1052 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
1053 }
1054
1055 DECLARE_INSTRUCTION(VecLoad);
1056
Artem Serovcced8ba2017-07-19 18:18:09 +01001057 protected:
1058 DEFAULT_COPY_CONSTRUCTOR(VecLoad);
1059
Aart Bikf8f5a162017-02-06 15:35:29 -08001060 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -07001061 // Additional packed bits.
1062 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
1063 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
1064 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf8f5a162017-02-06 15:35:29 -08001065};
1066
1067// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1068// sets mem(1) = x1, .. , mem(n) = xn.
1069class HVecStore FINAL : public HVecMemoryOperation {
1070 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001071 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001072 HInstruction* base,
1073 HInstruction* index,
1074 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001075 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001076 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001077 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001078 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301079 : HVecMemoryOperation(kVecStore,
1080 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001081 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001082 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001083 /* number_of_inputs */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001084 vector_length,
1085 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001086 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001087 SetRawInputAt(0, base);
1088 SetRawInputAt(1, index);
1089 SetRawInputAt(2, value);
1090 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001091
1092 // A store needs to stay in place.
1093 bool CanBeMoved() const OVERRIDE { return false; }
1094
Aart Bikf8f5a162017-02-06 15:35:29 -08001095 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001096
Artem Serovcced8ba2017-07-19 18:18:09 +01001097 protected:
1098 DEFAULT_COPY_CONSTRUCTOR(VecStore)
Aart Bikf8f5a162017-02-06 15:35:29 -08001099};
1100
1101} // namespace art
1102
1103#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_