blob: 87dff8403b6bd9cf6d4265395374c8859e913aa2 [file] [log] [blame]
Aart Bikf8f5a162017-02-06 15:35:29 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_
18#define ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_
19
20// This #include should never be used by compilation, because this header file (nodes_vector.h)
21// is included in the header file nodes.h itself. However it gives editing tools better context.
22#include "nodes.h"
23
24namespace art {
25
26// Memory alignment, represented as an offset relative to a base, where 0 <= offset < base,
27// and base is a power of two. For example, the value Alignment(16, 0) means memory is
28// perfectly aligned at a 16-byte boundary, whereas the value Alignment(16, 4) means
29// memory is always exactly 4 bytes above such a boundary.
30class Alignment {
31 public:
32 Alignment(size_t base, size_t offset) : base_(base), offset_(offset) {
33 DCHECK_LT(offset, base);
34 DCHECK(IsPowerOfTwo(base));
35 }
36
Aart Bik46b6dbc2017-10-03 11:37:37 -070037 // Returns true if memory is at least aligned at the given boundary.
Aart Bikf8f5a162017-02-06 15:35:29 -080038 // Assumes requested base is power of two.
39 bool IsAlignedAt(size_t base) const {
40 DCHECK_NE(0u, base);
41 DCHECK(IsPowerOfTwo(base));
42 return ((offset_ | base_) & (base - 1u)) == 0;
43 }
44
Aart Bik46b6dbc2017-10-03 11:37:37 -070045 size_t Base() const { return base_; }
46
47 size_t Offset() const { return offset_; }
48
Aart Bikf8f5a162017-02-06 15:35:29 -080049 std::string ToString() const {
50 return "ALIGN(" + std::to_string(base_) + "," + std::to_string(offset_) + ")";
51 }
52
Aart Bikb79f4ac2017-07-10 10:10:37 -070053 bool operator==(const Alignment& other) const {
54 return base_ == other.base_ && offset_ == other.offset_;
55 }
56
Aart Bikf8f5a162017-02-06 15:35:29 -080057 private:
58 size_t base_;
59 size_t offset_;
60};
61
62//
63// Definitions of abstract vector operations in HIR.
64//
65
66// Abstraction of a vector operation, i.e., an operation that performs
67// GetVectorLength() x GetPackedType() operations simultaneously.
68class HVecOperation : public HVariableInputSizeInstruction {
69 public:
Aart Bik0148de42017-09-05 09:25:01 -070070 // A SIMD operation looks like a FPU location.
71 // TODO: we could introduce SIMD types in HIR.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010072 static constexpr DataType::Type kSIMDType = DataType::Type::kFloat64;
Aart Bik0148de42017-09-05 09:25:01 -070073
Vladimir Markoe764d2e2017-10-05 14:35:55 +010074 HVecOperation(ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010075 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -080076 SideEffects side_effects,
77 size_t number_of_inputs,
78 size_t vector_length,
79 uint32_t dex_pc)
80 : HVariableInputSizeInstruction(side_effects,
81 dex_pc,
Vladimir Markoe764d2e2017-10-05 14:35:55 +010082 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -080083 number_of_inputs,
84 kArenaAllocVectorNode),
85 vector_length_(vector_length) {
86 SetPackedField<TypeField>(packed_type);
87 DCHECK_LT(1u, vector_length);
88 }
89
90 // Returns the number of elements packed in a vector.
91 size_t GetVectorLength() const {
92 return vector_length_;
93 }
94
95 // Returns the number of bytes in a full vector.
96 size_t GetVectorNumberOfBytes() const {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010097 return vector_length_ * DataType::Size(GetPackedType());
Aart Bikf8f5a162017-02-06 15:35:29 -080098 }
99
Aart Bik0148de42017-09-05 09:25:01 -0700100 // Returns the type of the vector operation.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100101 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700102 return kSIMDType;
Aart Bikf8f5a162017-02-06 15:35:29 -0800103 }
104
105 // Returns the true component type packed in a vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100106 DataType::Type GetPackedType() const {
Aart Bikf8f5a162017-02-06 15:35:29 -0800107 return GetPackedField<TypeField>();
108 }
109
Aart Bikb79f4ac2017-07-10 10:10:37 -0700110 // Assumes vector nodes cannot be moved by default. Each concrete implementation
111 // that can be moved should override this method and return true.
Artem Serov89ff8b22017-11-20 11:51:05 +0000112 //
113 // Note: similar approach is used for instruction scheduling (if it is turned on for the target):
114 // by default HScheduler::IsSchedulable returns false for a particular HVecOperation.
115 // HScheduler${ARCH}::IsSchedulable can be overridden to return true for an instruction (see
116 // scheduler_arm64.h for example) if it is safe to schedule it; in this case one *must* also
117 // look at/update HScheduler${ARCH}::IsSchedulingBarrier for this instruction.
118 //
119 // Note: For newly introduced vector instructions HScheduler${ARCH}::IsSchedulingBarrier must be
120 // altered to return true if the instruction might reside outside the SIMD loop body since SIMD
121 // registers are not kept alive across vector loop boundaries (yet).
Aart Bikb79f4ac2017-07-10 10:10:37 -0700122 bool CanBeMoved() const OVERRIDE { return false; }
123
124 // Tests if all data of a vector node (vector length and packed type) is equal.
125 // Each concrete implementation that adds more fields should test equality of
126 // those fields in its own method *and* call all super methods.
127 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
128 DCHECK(other->IsVecOperation());
129 const HVecOperation* o = other->AsVecOperation();
130 return GetVectorLength() == o->GetVectorLength() && GetPackedType() == o->GetPackedType();
131 }
132
Aart Bik46b6dbc2017-10-03 11:37:37 -0700133 // Maps an integral type to the same-size signed type and leaves other types alone.
134 // Can be used to test relaxed type consistency in which packed same-size integral
135 // types can co-exist, but other type mixes are an error.
136 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 Bik2dd7b672017-12-07 11:11:22 -0800163 // Helper method to determine if an instruction returns a SIMD value.
164 // TODO: This method is needed until we introduce SIMD as proper type.
165 static bool ReturnsSIMDValue(HInstruction* instruction) {
166 if (instruction->IsVecOperation()) {
167 return !instruction->IsVecExtractScalar(); // only scalar returning vec op
168 } else if (instruction->IsPhi()) {
169 return
170 instruction->GetType() == kSIMDType &&
171 instruction->InputAt(1)->IsVecOperation(); // vectorizer does not go deeper
172 }
173 return false;
174 }
175
Aart Bikf8f5a162017-02-06 15:35:29 -0800176 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
177
Aart Bikdb14fcf2017-04-25 15:53:58 -0700178 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800179 // Additional packed bits.
180 static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits;
181 static constexpr size_t kFieldTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100182 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Aart Bikf8f5a162017-02-06 15:35:29 -0800183 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldType + kFieldTypeSize;
184 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100185 using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800186
Artem Serovcced8ba2017-07-19 18:18:09 +0100187 DEFAULT_COPY_CONSTRUCTOR(VecOperation);
188
Aart Bikdb14fcf2017-04-25 15:53:58 -0700189 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800190 const size_t vector_length_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800191};
192
193// Abstraction of a unary vector operation.
194class HVecUnaryOperation : public HVecOperation {
195 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100196 HVecUnaryOperation(ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700197 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100198 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800199 size_t vector_length,
200 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100201 : HVecOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800202 packed_type,
203 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700204 /* number_of_inputs */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800205 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700206 dex_pc) {
207 SetRawInputAt(0, input);
208 }
209
210 HInstruction* GetInput() const { return InputAt(0); }
211
Aart Bikf8f5a162017-02-06 15:35:29 -0800212 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700213
Artem Serovcced8ba2017-07-19 18:18:09 +0100214 protected:
215 DEFAULT_COPY_CONSTRUCTOR(VecUnaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800216};
217
218// Abstraction of a binary vector operation.
219class HVecBinaryOperation : public HVecOperation {
220 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100221 HVecBinaryOperation(ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700222 HInstruction* left,
223 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100224 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800225 size_t vector_length,
226 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100227 : HVecOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800228 packed_type,
229 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700230 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800231 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700232 dex_pc) {
233 SetRawInputAt(0, left);
234 SetRawInputAt(1, right);
235 }
Artem Serovf34dd202017-04-10 17:41:46 +0100236
237 HInstruction* GetLeft() const { return InputAt(0); }
238 HInstruction* GetRight() const { return InputAt(1); }
239
Aart Bikf8f5a162017-02-06 15:35:29 -0800240 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700241
Artem Serovcced8ba2017-07-19 18:18:09 +0100242 protected:
243 DEFAULT_COPY_CONSTRUCTOR(VecBinaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800244};
245
246// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700247// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800248class HVecMemoryOperation : public HVecOperation {
249 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100250 HVecMemoryOperation(ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100251 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800252 SideEffects side_effects,
253 size_t number_of_inputs,
254 size_t vector_length,
255 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100256 : HVecOperation(allocator,
257 packed_type,
258 side_effects,
259 number_of_inputs,
260 vector_length,
261 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100262 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100263 DCHECK_GE(number_of_inputs, 2u);
264 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800265
266 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
267
268 Alignment GetAlignment() const { return alignment_; }
269
Artem Serove1811ed2017-04-27 16:50:47 +0100270 HInstruction* GetArray() const { return InputAt(0); }
271 HInstruction* GetIndex() const { return InputAt(1); }
272
Aart Bikb79f4ac2017-07-10 10:10:37 -0700273 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
274 DCHECK(other->IsVecMemoryOperation());
275 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
276 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
277 }
278
Aart Bikf8f5a162017-02-06 15:35:29 -0800279 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
280
Artem Serovcced8ba2017-07-19 18:18:09 +0100281 protected:
282 DEFAULT_COPY_CONSTRUCTOR(VecMemoryOperation);
283
Aart Bikf8f5a162017-02-06 15:35:29 -0800284 private:
285 Alignment alignment_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800286};
287
Aart Bik0148de42017-09-05 09:25:01 -0700288// Packed type consistency checker ("same vector length" integral types may mix freely).
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100289inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700290 if (input->IsPhi()) {
291 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
292 }
Aart Bikd58bc322017-05-01 14:49:18 -0700293 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100294 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik4d1a9d42017-10-19 14:40:55 -0700295 DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
296 HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
Aart Bik46b6dbc2017-10-03 11:37:37 -0700297 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700298}
299
Aart Bikf8f5a162017-02-06 15:35:29 -0800300//
Aart Bik8de59162017-04-21 09:42:01 -0700301// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800302//
303
304// Replicates the given scalar into a vector,
305// viz. replicate(x) = [ x, .. , x ].
306class HVecReplicateScalar FINAL : public HVecUnaryOperation {
307 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100308 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800309 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100310 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800311 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700312 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100313 : HVecUnaryOperation(allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik8de59162017-04-21 09:42:01 -0700314 DCHECK(!scalar->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800315 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700316
317 // A replicate needs to stay in place, since SIMD registers are not
318 // kept alive across vector loop boundaries (yet).
319 bool CanBeMoved() const OVERRIDE { return false; }
320
Aart Bikf8f5a162017-02-06 15:35:29 -0800321 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700322
Artem Serovcced8ba2017-07-19 18:18:09 +0100323 protected:
324 DEFAULT_COPY_CONSTRUCTOR(VecReplicateScalar);
Aart Bikf8f5a162017-02-06 15:35:29 -0800325};
326
Aart Bik0148de42017-09-05 09:25:01 -0700327// Extracts a particular scalar from the given vector,
328// viz. extract[ x1, .. , xn ] = x_i.
329//
330// TODO: for now only i == 1 case supported.
331class HVecExtractScalar FINAL : public HVecUnaryOperation {
332 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100333 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700334 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100335 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700336 size_t vector_length,
337 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700338 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100339 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700340 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700341 DCHECK_LT(index, vector_length);
342 DCHECK_EQ(index, 0u);
343 }
344
345 // Yields a single component in the vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100346 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700347 return GetPackedType();
348 }
349
350 // An extract needs to stay in place, since SIMD registers are not
351 // kept alive across vector loop boundaries (yet).
352 bool CanBeMoved() const OVERRIDE { return false; }
353
354 DECLARE_INSTRUCTION(VecExtractScalar);
355
Artem Serovcced8ba2017-07-19 18:18:09 +0100356 protected:
357 DEFAULT_COPY_CONSTRUCTOR(VecExtractScalar);
Aart Bik0148de42017-09-05 09:25:01 -0700358};
359
360// Reduces the given vector into the first element as sum/min/max,
361// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
362// and the "-" denotes "don't care" (implementation dependent).
363class HVecReduce FINAL : public HVecUnaryOperation {
364 public:
365 enum ReductionKind {
366 kSum = 1,
367 kMin = 2,
368 kMax = 3
369 };
370
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100371 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700372 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100373 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700374 size_t vector_length,
375 ReductionKind kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700376 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100377 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc),
Aart Bik0148de42017-09-05 09:25:01 -0700378 kind_(kind) {
379 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700380 }
381
Aart Bik0148de42017-09-05 09:25:01 -0700382 ReductionKind GetKind() const { return kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800383
Aart Bikb79f4ac2017-07-10 10:10:37 -0700384 bool CanBeMoved() const OVERRIDE { return true; }
385
Aart Bik0148de42017-09-05 09:25:01 -0700386 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
387 DCHECK(other->IsVecReduce());
388 const HVecReduce* o = other->AsVecReduce();
389 return HVecOperation::InstructionDataEquals(o) && GetKind() == o->GetKind();
390 }
391
392 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700393
Artem Serovcced8ba2017-07-19 18:18:09 +0100394 protected:
395 DEFAULT_COPY_CONSTRUCTOR(VecReduce);
396
Aart Bikf8f5a162017-02-06 15:35:29 -0800397 private:
Aart Bik0148de42017-09-05 09:25:01 -0700398 const ReductionKind kind_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800399};
400
401// Converts every component in the vector,
402// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
403class HVecCnv FINAL : public HVecUnaryOperation {
404 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100405 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800406 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100407 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800408 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700409 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100410 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800411 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700412 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800413 }
414
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100415 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
416 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800417
Aart Bikb79f4ac2017-07-10 10:10:37 -0700418 bool CanBeMoved() const OVERRIDE { return true; }
419
Aart Bikf8f5a162017-02-06 15:35:29 -0800420 DECLARE_INSTRUCTION(VecCnv);
421
Artem Serovcced8ba2017-07-19 18:18:09 +0100422 protected:
423 DEFAULT_COPY_CONSTRUCTOR(VecCnv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800424};
425
426// Negates every component in the vector,
427// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
428class HVecNeg FINAL : public HVecUnaryOperation {
429 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100430 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800431 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100432 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800433 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700434 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100435 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700436 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800437 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700438
439 bool CanBeMoved() const OVERRIDE { return true; }
440
Aart Bikf8f5a162017-02-06 15:35:29 -0800441 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700442
Artem Serovcced8ba2017-07-19 18:18:09 +0100443 protected:
444 DEFAULT_COPY_CONSTRUCTOR(VecNeg);
Aart Bikf8f5a162017-02-06 15:35:29 -0800445};
446
Aart Bik6daebeb2017-04-03 14:35:41 -0700447// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700448// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
449// for signed operand x.
Aart Bik6daebeb2017-04-03 14:35:41 -0700450class HVecAbs FINAL : public HVecUnaryOperation {
451 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100452 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700453 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100454 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700455 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700456 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100457 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700458 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700459 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700460
461 bool CanBeMoved() const OVERRIDE { return true; }
462
Aart Bik6daebeb2017-04-03 14:35:41 -0700463 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700464
Artem Serovcced8ba2017-07-19 18:18:09 +0100465 protected:
466 DEFAULT_COPY_CONSTRUCTOR(VecAbs);
Aart Bik6daebeb2017-04-03 14:35:41 -0700467};
468
Aart Bikf8f5a162017-02-06 15:35:29 -0800469// Bitwise- or boolean-nots every component in the vector,
470// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
471// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
472class HVecNot FINAL : public HVecUnaryOperation {
473 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100474 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800475 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100476 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800477 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700478 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100479 : HVecUnaryOperation(allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800480 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800481 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700482
483 bool CanBeMoved() const OVERRIDE { return true; }
484
Aart Bikf8f5a162017-02-06 15:35:29 -0800485 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700486
Artem Serovcced8ba2017-07-19 18:18:09 +0100487 protected:
488 DEFAULT_COPY_CONSTRUCTOR(VecNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800489};
490
Aart Bik8de59162017-04-21 09:42:01 -0700491//
492// Definitions of concrete binary vector operations in HIR.
493//
494
Aart Bikf8f5a162017-02-06 15:35:29 -0800495// Adds every component in the two vectors,
496// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
497class HVecAdd FINAL : public HVecBinaryOperation {
498 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100499 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800500 HInstruction* left,
501 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100502 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800503 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700504 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100505 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700506 DCHECK(HasConsistentPackedTypes(left, packed_type));
507 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800508 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700509
510 bool CanBeMoved() const OVERRIDE { return true; }
511
Aart Bikf8f5a162017-02-06 15:35:29 -0800512 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700513
Artem Serovcced8ba2017-07-19 18:18:09 +0100514 protected:
515 DEFAULT_COPY_CONSTRUCTOR(VecAdd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800516};
517
Aart Bikf3e61ee2017-04-12 17:09:20 -0700518// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700519// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
520// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik46b6dbc2017-10-03 11:37:37 -0700521// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700522class HVecHalvingAdd FINAL : public HVecBinaryOperation {
523 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100524 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700525 HInstruction* left,
526 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100527 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700528 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700529 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700530 bool is_unsigned,
531 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100532 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100533 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
534 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
535 DCHECK(!is_unsigned ||
536 packed_type == DataType::Type::kInt32 ||
537 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700538 DCHECK(HasConsistentPackedTypes(left, packed_type));
539 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700540 SetPackedFlag<kFieldHAddIsUnsigned>(is_unsigned);
541 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700542 }
543
Aart Bikdb14fcf2017-04-25 15:53:58 -0700544 bool IsUnsigned() const { return GetPackedFlag<kFieldHAddIsUnsigned>(); }
545 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700546
Aart Bikb79f4ac2017-07-10 10:10:37 -0700547 bool CanBeMoved() const OVERRIDE { return true; }
548
549 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
550 DCHECK(other->IsVecHalvingAdd());
551 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
552 return HVecOperation::InstructionDataEquals(o) &&
553 IsUnsigned() == o->IsUnsigned() &&
554 IsRounded() == o->IsRounded();
555 }
556
Aart Bikf3e61ee2017-04-12 17:09:20 -0700557 DECLARE_INSTRUCTION(VecHalvingAdd);
558
Artem Serovcced8ba2017-07-19 18:18:09 +0100559 protected:
560 DEFAULT_COPY_CONSTRUCTOR(VecHalvingAdd);
561
Aart Bikf3e61ee2017-04-12 17:09:20 -0700562 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700563 // Additional packed bits.
564 static constexpr size_t kFieldHAddIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
565 static constexpr size_t kFieldHAddIsRounded = kFieldHAddIsUnsigned + 1;
566 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
567 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700568};
569
Aart Bikf8f5a162017-02-06 15:35:29 -0800570// Subtracts every component in the two vectors,
571// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
572class HVecSub FINAL : public HVecBinaryOperation {
573 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100574 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800575 HInstruction* left,
576 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100577 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800578 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700579 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100580 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700581 DCHECK(HasConsistentPackedTypes(left, packed_type));
582 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800583 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700584
585 bool CanBeMoved() const OVERRIDE { return true; }
586
Aart Bikf8f5a162017-02-06 15:35:29 -0800587 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700588
Artem Serovcced8ba2017-07-19 18:18:09 +0100589 protected:
590 DEFAULT_COPY_CONSTRUCTOR(VecSub);
Aart Bikf8f5a162017-02-06 15:35:29 -0800591};
592
593// Multiplies every component in the two vectors,
594// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
595class HVecMul FINAL : public HVecBinaryOperation {
596 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100597 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800598 HInstruction* left,
599 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100600 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800601 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700602 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100603 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700604 DCHECK(HasConsistentPackedTypes(left, packed_type));
605 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800606 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700607
608 bool CanBeMoved() const OVERRIDE { return true; }
609
Aart Bikf8f5a162017-02-06 15:35:29 -0800610 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700611
Artem Serovcced8ba2017-07-19 18:18:09 +0100612 protected:
613 DEFAULT_COPY_CONSTRUCTOR(VecMul);
Aart Bikf8f5a162017-02-06 15:35:29 -0800614};
615
616// Divides every component in the two vectors,
617// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
618class HVecDiv FINAL : public HVecBinaryOperation {
619 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100620 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800621 HInstruction* left,
622 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100623 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800624 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700625 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100626 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700627 DCHECK(HasConsistentPackedTypes(left, packed_type));
628 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800629 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700630
631 bool CanBeMoved() const OVERRIDE { return true; }
632
Aart Bikf8f5a162017-02-06 15:35:29 -0800633 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700634
Artem Serovcced8ba2017-07-19 18:18:09 +0100635 protected:
636 DEFAULT_COPY_CONSTRUCTOR(VecDiv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800637};
638
Aart Bikf3e61ee2017-04-12 17:09:20 -0700639// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700640// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
641// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700642class HVecMin FINAL : public HVecBinaryOperation {
643 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100644 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700645 HInstruction* left,
646 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100647 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700648 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700649 bool is_unsigned,
650 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100651 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100652 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
653 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
654 DCHECK(!is_unsigned ||
655 packed_type == DataType::Type::kInt32 ||
656 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700657 DCHECK(HasConsistentPackedTypes(left, packed_type));
658 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikc8e93c72017-05-10 10:49:22 -0700659 SetPackedFlag<kFieldMinOpIsUnsigned>(is_unsigned);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700660 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700661
662 bool IsUnsigned() const { return GetPackedFlag<kFieldMinOpIsUnsigned>(); }
663
Aart Bikb79f4ac2017-07-10 10:10:37 -0700664 bool CanBeMoved() const OVERRIDE { return true; }
665
666 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
667 DCHECK(other->IsVecMin());
668 const HVecMin* o = other->AsVecMin();
669 return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned();
670 }
671
Aart Bikf3e61ee2017-04-12 17:09:20 -0700672 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700673
Artem Serovcced8ba2017-07-19 18:18:09 +0100674 protected:
675 DEFAULT_COPY_CONSTRUCTOR(VecMin);
676
Aart Bikf3e61ee2017-04-12 17:09:20 -0700677 private:
Aart Bikc8e93c72017-05-10 10:49:22 -0700678 // Additional packed bits.
679 static constexpr size_t kFieldMinOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
680 static constexpr size_t kNumberOfMinOpPackedBits = kFieldMinOpIsUnsigned + 1;
681 static_assert(kNumberOfMinOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700682};
683
684// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700685// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
686// for either both signed or both unsigned operands x, y.
Aart Bikf3e61ee2017-04-12 17:09:20 -0700687class HVecMax FINAL : public HVecBinaryOperation {
688 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100689 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700690 HInstruction* left,
691 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100692 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700693 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700694 bool is_unsigned,
695 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100696 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100697 // The `is_unsigned` flag should be used exclusively with the Int32 or Int64.
698 // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types.
699 DCHECK(!is_unsigned ||
700 packed_type == DataType::Type::kInt32 ||
701 packed_type == DataType::Type::kInt64) << packed_type;
Aart Bikd58bc322017-05-01 14:49:18 -0700702 DCHECK(HasConsistentPackedTypes(left, packed_type));
703 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikc8e93c72017-05-10 10:49:22 -0700704 SetPackedFlag<kFieldMaxOpIsUnsigned>(is_unsigned);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700705 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700706
707 bool IsUnsigned() const { return GetPackedFlag<kFieldMaxOpIsUnsigned>(); }
708
Aart Bikb79f4ac2017-07-10 10:10:37 -0700709 bool CanBeMoved() const OVERRIDE { return true; }
710
711 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
712 DCHECK(other->IsVecMax());
713 const HVecMax* o = other->AsVecMax();
714 return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned();
715 }
716
Aart Bikf3e61ee2017-04-12 17:09:20 -0700717 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700718
Artem Serovcced8ba2017-07-19 18:18:09 +0100719 protected:
720 DEFAULT_COPY_CONSTRUCTOR(VecMax);
721
Aart Bikf3e61ee2017-04-12 17:09:20 -0700722 private:
Aart Bikc8e93c72017-05-10 10:49:22 -0700723 // Additional packed bits.
724 static constexpr size_t kFieldMaxOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits;
725 static constexpr size_t kNumberOfMaxOpPackedBits = kFieldMaxOpIsUnsigned + 1;
726 static_assert(kNumberOfMaxOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700727};
728
Aart Bikf8f5a162017-02-06 15:35:29 -0800729// Bitwise-ands every component in the two vectors,
730// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
731class HVecAnd FINAL : public HVecBinaryOperation {
732 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100733 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800734 HInstruction* left,
735 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100736 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800737 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700738 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100739 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800740 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800741 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700742
743 bool CanBeMoved() const OVERRIDE { return true; }
744
Aart Bikf8f5a162017-02-06 15:35:29 -0800745 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700746
Artem Serovcced8ba2017-07-19 18:18:09 +0100747 protected:
748 DEFAULT_COPY_CONSTRUCTOR(VecAnd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800749};
750
751// Bitwise-and-nots every component in the two vectors,
752// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
753class HVecAndNot FINAL : public HVecBinaryOperation {
754 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100755 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800756 HInstruction* left,
757 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100758 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800759 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700760 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100761 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800762 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800763 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700764
765 bool CanBeMoved() const OVERRIDE { return true; }
766
Aart Bikf8f5a162017-02-06 15:35:29 -0800767 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700768
Artem Serovcced8ba2017-07-19 18:18:09 +0100769 protected:
770 DEFAULT_COPY_CONSTRUCTOR(VecAndNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800771};
772
773// Bitwise-ors every component in the two vectors,
774// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
775class HVecOr FINAL : public HVecBinaryOperation {
776 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100777 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800778 HInstruction* left,
779 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100780 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800781 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700782 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100783 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800784 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800785 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700786
787 bool CanBeMoved() const OVERRIDE { return true; }
788
Aart Bikf8f5a162017-02-06 15:35:29 -0800789 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700790
Artem Serovcced8ba2017-07-19 18:18:09 +0100791 protected:
792 DEFAULT_COPY_CONSTRUCTOR(VecOr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800793};
794
795// Bitwise-xors every component in the two vectors,
796// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
797class HVecXor FINAL : public HVecBinaryOperation {
798 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100799 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800800 HInstruction* left,
801 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100802 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800803 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700804 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100805 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800806 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800807 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700808
809 bool CanBeMoved() const OVERRIDE { return true; }
810
Aart Bikf8f5a162017-02-06 15:35:29 -0800811 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700812
Artem Serovcced8ba2017-07-19 18:18:09 +0100813 protected:
814 DEFAULT_COPY_CONSTRUCTOR(VecXor);
Aart Bikf8f5a162017-02-06 15:35:29 -0800815};
816
817// Logically shifts every component in the vector left by the given distance,
818// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
819class HVecShl FINAL : public HVecBinaryOperation {
820 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100821 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800822 HInstruction* left,
823 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100824 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800825 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700826 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100827 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700828 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800829 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700830
831 bool CanBeMoved() const OVERRIDE { return true; }
832
Aart Bikf8f5a162017-02-06 15:35:29 -0800833 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700834
Artem Serovcced8ba2017-07-19 18:18:09 +0100835 protected:
836 DEFAULT_COPY_CONSTRUCTOR(VecShl);
Aart Bikf8f5a162017-02-06 15:35:29 -0800837};
838
839// Arithmetically shifts every component in the vector right by the given distance,
840// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
841class HVecShr FINAL : public HVecBinaryOperation {
842 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100843 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800844 HInstruction* left,
845 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100846 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800847 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700848 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100849 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700850 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800851 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700852
853 bool CanBeMoved() const OVERRIDE { return true; }
854
Aart Bikf8f5a162017-02-06 15:35:29 -0800855 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700856
Artem Serovcced8ba2017-07-19 18:18:09 +0100857 protected:
858 DEFAULT_COPY_CONSTRUCTOR(VecShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800859};
860
861// Logically shifts every component in the vector right by the given distance,
862// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
863class HVecUShr FINAL : public HVecBinaryOperation {
864 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100865 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800866 HInstruction* left,
867 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100868 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800869 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700870 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100871 : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700872 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800873 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700874
875 bool CanBeMoved() const OVERRIDE { return true; }
876
Aart Bikf8f5a162017-02-06 15:35:29 -0800877 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700878
Artem Serovcced8ba2017-07-19 18:18:09 +0100879 protected:
880 DEFAULT_COPY_CONSTRUCTOR(VecUShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800881};
882
Aart Bik8de59162017-04-21 09:42:01 -0700883//
884// Definitions of concrete miscellaneous vector operations in HIR.
885//
886
887// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700888// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
889// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Aart Bik8de59162017-04-21 09:42:01 -0700890class HVecSetScalars FINAL : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700891 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100892 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700893 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100894 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700895 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700896 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700897 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100898 : HVecOperation(allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700899 packed_type,
900 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700901 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700902 vector_length,
903 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700904 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik2dd7b672017-12-07 11:11:22 -0800905 DCHECK(!ReturnsSIMDValue(scalars[i]));
Aart Bik8de59162017-04-21 09:42:01 -0700906 SetRawInputAt(0, scalars[i]);
907 }
908 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700909
910 // Setting scalars needs to stay in place, since SIMD registers are not
911 // kept alive across vector loop boundaries (yet).
912 bool CanBeMoved() const OVERRIDE { return false; }
913
Aart Bik8de59162017-04-21 09:42:01 -0700914 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700915
Artem Serovcced8ba2017-07-19 18:18:09 +0100916 protected:
917 DEFAULT_COPY_CONSTRUCTOR(VecSetScalars);
Aart Bik8de59162017-04-21 09:42:01 -0700918};
919
Aart Bikdbbac8f2017-09-01 13:06:08 -0700920// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
921// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Artem Serovf34dd202017-04-10 17:41:46 +0100922class HVecMultiplyAccumulate FINAL : public HVecOperation {
923 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100924 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100925 InstructionKind op,
926 HInstruction* accumulator,
927 HInstruction* mul_left,
928 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100929 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +0100930 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700931 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100932 : HVecOperation(allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100933 packed_type,
934 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700935 /* number_of_inputs */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +0100936 vector_length,
937 dex_pc),
938 op_kind_(op) {
939 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -0700940 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
941 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
942 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700943 SetRawInputAt(0, accumulator);
944 SetRawInputAt(1, mul_left);
945 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +0100946 }
947
Nicolas Geoffray9858bf72017-07-08 12:34:55 +0000948 bool CanBeMoved() const OVERRIDE { return true; }
949
Artem Serovf34dd202017-04-10 17:41:46 +0100950 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700951 DCHECK(other->IsVecMultiplyAccumulate());
952 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
953 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +0100954 }
955
956 InstructionKind GetOpKind() const { return op_kind_; }
957
958 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
959
Artem Serovcced8ba2017-07-19 18:18:09 +0100960 protected:
961 DEFAULT_COPY_CONSTRUCTOR(VecMultiplyAccumulate);
962
Artem Serovf34dd202017-04-10 17:41:46 +0100963 private:
964 // Indicates if this is a MADD or MSUB.
965 const InstructionKind op_kind_;
Artem Serovf34dd202017-04-10 17:41:46 +0100966};
967
Aart Bikdbbac8f2017-09-01 13:06:08 -0700968// Takes the absolute difference of two vectors, and adds the results to
969// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700970// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -0700971// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -0700972// for m <= n, non-overlapping sums, and signed operands x, y.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700973class HVecSADAccumulate FINAL : public HVecOperation {
974 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100975 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700976 HInstruction* accumulator,
977 HInstruction* sad_left,
978 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100979 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700980 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700981 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100982 : HVecOperation(allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700983 packed_type,
984 SideEffects::None(),
985 /* number_of_inputs */ 3,
986 vector_length,
987 dex_pc) {
988 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
989 DCHECK(sad_left->IsVecOperation());
990 DCHECK(sad_right->IsVecOperation());
Vladimir Marko61b92282017-10-11 13:23:17 +0100991 DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
992 ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700993 SetRawInputAt(0, accumulator);
994 SetRawInputAt(1, sad_left);
995 SetRawInputAt(2, sad_right);
996 }
997
998 DECLARE_INSTRUCTION(VecSADAccumulate);
999
Artem Serovcced8ba2017-07-19 18:18:09 +01001000 protected:
1001 DEFAULT_COPY_CONSTRUCTOR(VecSADAccumulate);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001002};
1003
Aart Bikf8f5a162017-02-06 15:35:29 -08001004// Loads a vector from memory, viz. load(mem, 1)
1005// yield the vector [ mem(1), .. , mem(n) ].
1006class HVecLoad FINAL : public HVecMemoryOperation {
1007 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001008 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001009 HInstruction* base,
1010 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001011 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001012 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001013 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -07001014 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001015 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001016 : HVecMemoryOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001017 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001018 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001019 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -08001020 vector_length,
1021 dex_pc) {
1022 SetRawInputAt(0, base);
1023 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -07001024 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -08001025 }
Aart Bikdb14fcf2017-04-25 15:53:58 -07001026
1027 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
1028
Aart Bikb79f4ac2017-07-10 10:10:37 -07001029 bool CanBeMoved() const OVERRIDE { return true; }
1030
1031 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
1032 DCHECK(other->IsVecLoad());
1033 const HVecLoad* o = other->AsVecLoad();
1034 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
1035 }
1036
1037 DECLARE_INSTRUCTION(VecLoad);
1038
Artem Serovcced8ba2017-07-19 18:18:09 +01001039 protected:
1040 DEFAULT_COPY_CONSTRUCTOR(VecLoad);
1041
Aart Bikf8f5a162017-02-06 15:35:29 -08001042 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -07001043 // Additional packed bits.
1044 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
1045 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
1046 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf8f5a162017-02-06 15:35:29 -08001047};
1048
1049// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1050// sets mem(1) = x1, .. , mem(n) = xn.
1051class HVecStore FINAL : public HVecMemoryOperation {
1052 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001053 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001054 HInstruction* base,
1055 HInstruction* index,
1056 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001057 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001058 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001059 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001060 uint32_t dex_pc)
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001061 : HVecMemoryOperation(allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001062 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001063 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001064 /* number_of_inputs */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001065 vector_length,
1066 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001067 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001068 SetRawInputAt(0, base);
1069 SetRawInputAt(1, index);
1070 SetRawInputAt(2, value);
1071 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001072
1073 // A store needs to stay in place.
1074 bool CanBeMoved() const OVERRIDE { return false; }
1075
Aart Bikf8f5a162017-02-06 15:35:29 -08001076 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001077
Artem Serovcced8ba2017-07-19 18:18:09 +01001078 protected:
1079 DEFAULT_COPY_CONSTRUCTOR(VecStore)
Aart Bikf8f5a162017-02-06 15:35:29 -08001080};
1081
1082} // namespace art
1083
1084#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_