blob: 1a484e1944f7133c9b4f26081c7b35b05e63d2dc [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()) {
Aart Bik3f8e02c2018-04-10 11:55:00 -0700174 // Vectorizer only uses Phis in reductions, so checking for a 2-way phi
175 // with a direct vector operand as second argument suffices.
Aart Bik2dd7b672017-12-07 11:11:22 -0800176 return
177 instruction->GetType() == kSIMDType &&
Aart Bik3f8e02c2018-04-10 11:55:00 -0700178 instruction->InputCount() == 2 &&
179 instruction->InputAt(1)->IsVecOperation();
Aart Bik2dd7b672017-12-07 11:11:22 -0800180 }
181 return false;
182 }
183
Aart Bikf8f5a162017-02-06 15:35:29 -0800184 DECLARE_ABSTRACT_INSTRUCTION(VecOperation);
185
Aart Bikdb14fcf2017-04-25 15:53:58 -0700186 protected:
Aart Bikf8f5a162017-02-06 15:35:29 -0800187 // Additional packed bits.
188 static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits;
189 static constexpr size_t kFieldTypeSize =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100190 MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast));
Aart Bikf8f5a162017-02-06 15:35:29 -0800191 static constexpr size_t kNumberOfVectorOpPackedBits = kFieldType + kFieldTypeSize;
192 static_assert(kNumberOfVectorOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100193 using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>;
Aart Bikf8f5a162017-02-06 15:35:29 -0800194
Artem Serovcced8ba2017-07-19 18:18:09 +0100195 DEFAULT_COPY_CONSTRUCTOR(VecOperation);
196
Aart Bikdb14fcf2017-04-25 15:53:58 -0700197 private:
Aart Bikf8f5a162017-02-06 15:35:29 -0800198 const size_t vector_length_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800199};
200
201// Abstraction of a unary vector operation.
202class HVecUnaryOperation : public HVecOperation {
203 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530204 HVecUnaryOperation(InstructionKind kind,
205 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700206 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100207 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800208 size_t vector_length,
209 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530210 : HVecOperation(kind,
211 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800212 packed_type,
213 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700214 /* number_of_inputs */ 1,
Aart Bikf8f5a162017-02-06 15:35:29 -0800215 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700216 dex_pc) {
217 SetRawInputAt(0, input);
218 }
219
220 HInstruction* GetInput() const { return InputAt(0); }
221
Aart Bikf8f5a162017-02-06 15:35:29 -0800222 DECLARE_ABSTRACT_INSTRUCTION(VecUnaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700223
Artem Serovcced8ba2017-07-19 18:18:09 +0100224 protected:
225 DEFAULT_COPY_CONSTRUCTOR(VecUnaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800226};
227
228// Abstraction of a binary vector operation.
229class HVecBinaryOperation : public HVecOperation {
230 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530231 HVecBinaryOperation(InstructionKind kind,
232 ArenaAllocator* allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700233 HInstruction* left,
234 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100235 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800236 size_t vector_length,
237 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530238 : HVecOperation(kind,
239 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800240 packed_type,
241 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700242 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -0800243 vector_length,
Aart Bik8de59162017-04-21 09:42:01 -0700244 dex_pc) {
245 SetRawInputAt(0, left);
246 SetRawInputAt(1, right);
247 }
Artem Serovf34dd202017-04-10 17:41:46 +0100248
249 HInstruction* GetLeft() const { return InputAt(0); }
250 HInstruction* GetRight() const { return InputAt(1); }
251
Aart Bikf8f5a162017-02-06 15:35:29 -0800252 DECLARE_ABSTRACT_INSTRUCTION(VecBinaryOperation);
Aart Bik8de59162017-04-21 09:42:01 -0700253
Artem Serovcced8ba2017-07-19 18:18:09 +0100254 protected:
255 DEFAULT_COPY_CONSTRUCTOR(VecBinaryOperation);
Aart Bikf8f5a162017-02-06 15:35:29 -0800256};
257
258// Abstraction of a vector operation that references memory, with an alignment.
Aart Bik46b6dbc2017-10-03 11:37:37 -0700259// The Android runtime guarantees elements have at least natural alignment.
Aart Bikf8f5a162017-02-06 15:35:29 -0800260class HVecMemoryOperation : public HVecOperation {
261 public:
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530262 HVecMemoryOperation(InstructionKind kind,
263 ArenaAllocator* allocator,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100264 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800265 SideEffects side_effects,
266 size_t number_of_inputs,
267 size_t vector_length,
268 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530269 : HVecOperation(kind,
270 allocator,
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100271 packed_type,
272 side_effects,
273 number_of_inputs,
274 vector_length,
275 dex_pc),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100276 alignment_(DataType::Size(packed_type), 0) {
Artem Serove1811ed2017-04-27 16:50:47 +0100277 DCHECK_GE(number_of_inputs, 2u);
278 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800279
280 void SetAlignment(Alignment alignment) { alignment_ = alignment; }
281
282 Alignment GetAlignment() const { return alignment_; }
283
Artem Serove1811ed2017-04-27 16:50:47 +0100284 HInstruction* GetArray() const { return InputAt(0); }
285 HInstruction* GetIndex() const { return InputAt(1); }
286
Aart Bikb79f4ac2017-07-10 10:10:37 -0700287 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
288 DCHECK(other->IsVecMemoryOperation());
289 const HVecMemoryOperation* o = other->AsVecMemoryOperation();
290 return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
291 }
292
Aart Bikf8f5a162017-02-06 15:35:29 -0800293 DECLARE_ABSTRACT_INSTRUCTION(VecMemoryOperation);
294
Artem Serovcced8ba2017-07-19 18:18:09 +0100295 protected:
296 DEFAULT_COPY_CONSTRUCTOR(VecMemoryOperation);
297
Aart Bikf8f5a162017-02-06 15:35:29 -0800298 private:
299 Alignment alignment_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800300};
301
Aart Bik0148de42017-09-05 09:25:01 -0700302// Packed type consistency checker ("same vector length" integral types may mix freely).
Aart Bik66c158e2018-01-31 12:55:04 -0800303// Tests relaxed type consistency in which packed same-size integral types can co-exist,
304// but other type mixes are an error.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100305inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) {
Aart Bik0148de42017-09-05 09:25:01 -0700306 if (input->IsPhi()) {
307 return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
308 }
Aart Bikd58bc322017-05-01 14:49:18 -0700309 DCHECK(input->IsVecOperation());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100310 DataType::Type input_type = input->AsVecOperation()->GetPackedType();
Aart Bik4d1a9d42017-10-19 14:40:55 -0700311 DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
312 HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
Aart Bik46b6dbc2017-10-03 11:37:37 -0700313 return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
Aart Bikd58bc322017-05-01 14:49:18 -0700314}
315
Aart Bikf8f5a162017-02-06 15:35:29 -0800316//
Aart Bik8de59162017-04-21 09:42:01 -0700317// Definitions of concrete unary vector operations in HIR.
Aart Bikf8f5a162017-02-06 15:35:29 -0800318//
319
320// Replicates the given scalar into a vector,
321// viz. replicate(x) = [ x, .. , x ].
322class HVecReplicateScalar FINAL : public HVecUnaryOperation {
323 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100324 HVecReplicateScalar(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800325 HInstruction* scalar,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100326 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800327 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700328 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530329 : HVecUnaryOperation(
330 kVecReplicateScalar, allocator, scalar, packed_type, vector_length, dex_pc) {
Aart Bik5a0eb0c2018-03-16 15:00:19 -0700331 DCHECK(!ReturnsSIMDValue(scalar));
Aart Bikf8f5a162017-02-06 15:35:29 -0800332 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700333
334 // A replicate needs to stay in place, since SIMD registers are not
335 // kept alive across vector loop boundaries (yet).
336 bool CanBeMoved() const OVERRIDE { return false; }
337
Aart Bikf8f5a162017-02-06 15:35:29 -0800338 DECLARE_INSTRUCTION(VecReplicateScalar);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700339
Artem Serovcced8ba2017-07-19 18:18:09 +0100340 protected:
341 DEFAULT_COPY_CONSTRUCTOR(VecReplicateScalar);
Aart Bikf8f5a162017-02-06 15:35:29 -0800342};
343
Aart Bik0148de42017-09-05 09:25:01 -0700344// Extracts a particular scalar from the given vector,
345// viz. extract[ x1, .. , xn ] = x_i.
346//
347// TODO: for now only i == 1 case supported.
348class HVecExtractScalar FINAL : public HVecUnaryOperation {
349 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100350 HVecExtractScalar(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700351 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100352 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700353 size_t vector_length,
354 size_t index,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700355 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530356 : HVecUnaryOperation(
357 kVecExtractScalar, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700358 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik0148de42017-09-05 09:25:01 -0700359 DCHECK_LT(index, vector_length);
360 DCHECK_EQ(index, 0u);
361 }
362
363 // Yields a single component in the vector.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100364 DataType::Type GetType() const OVERRIDE {
Aart Bik0148de42017-09-05 09:25:01 -0700365 return GetPackedType();
366 }
367
368 // An extract needs to stay in place, since SIMD registers are not
369 // kept alive across vector loop boundaries (yet).
370 bool CanBeMoved() const OVERRIDE { return false; }
371
372 DECLARE_INSTRUCTION(VecExtractScalar);
373
Artem Serovcced8ba2017-07-19 18:18:09 +0100374 protected:
375 DEFAULT_COPY_CONSTRUCTOR(VecExtractScalar);
Aart Bik0148de42017-09-05 09:25:01 -0700376};
377
378// Reduces the given vector into the first element as sum/min/max,
379// viz. sum-reduce[ x1, .. , xn ] = [ y, ---- ], where y = sum xi
380// and the "-" denotes "don't care" (implementation dependent).
381class HVecReduce FINAL : public HVecUnaryOperation {
382 public:
383 enum ReductionKind {
384 kSum = 1,
385 kMin = 2,
386 kMax = 3
387 };
388
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100389 HVecReduce(ArenaAllocator* allocator,
Aart Bik0148de42017-09-05 09:25:01 -0700390 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100391 DataType::Type packed_type,
Aart Bik0148de42017-09-05 09:25:01 -0700392 size_t vector_length,
393 ReductionKind kind,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700394 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530395 : HVecUnaryOperation(kVecReduce, allocator, input, packed_type, vector_length, dex_pc),
Aart Bik0148de42017-09-05 09:25:01 -0700396 kind_(kind) {
397 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikcfa59b42017-08-31 09:08:13 -0700398 }
399
Aart Bik0148de42017-09-05 09:25:01 -0700400 ReductionKind GetKind() const { return kind_; }
Aart Bikf8f5a162017-02-06 15:35:29 -0800401
Aart Bikb79f4ac2017-07-10 10:10:37 -0700402 bool CanBeMoved() const OVERRIDE { return true; }
403
Aart Bik0148de42017-09-05 09:25:01 -0700404 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
405 DCHECK(other->IsVecReduce());
406 const HVecReduce* o = other->AsVecReduce();
407 return HVecOperation::InstructionDataEquals(o) && GetKind() == o->GetKind();
408 }
409
410 DECLARE_INSTRUCTION(VecReduce);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700411
Artem Serovcced8ba2017-07-19 18:18:09 +0100412 protected:
413 DEFAULT_COPY_CONSTRUCTOR(VecReduce);
414
Aart Bikf8f5a162017-02-06 15:35:29 -0800415 private:
Aart Bik0148de42017-09-05 09:25:01 -0700416 const ReductionKind kind_;
Aart Bikf8f5a162017-02-06 15:35:29 -0800417};
418
419// Converts every component in the vector,
420// viz. cnv[ x1, .. , xn ] = [ cnv(x1), .. , cnv(xn) ].
421class HVecCnv FINAL : public HVecUnaryOperation {
422 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100423 HVecCnv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800424 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100425 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800426 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700427 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530428 : HVecUnaryOperation(kVecCnv, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800429 DCHECK(input->IsVecOperation());
Aart Bikd58bc322017-05-01 14:49:18 -0700430 DCHECK_NE(GetInputType(), GetResultType()); // actual convert
Aart Bikf8f5a162017-02-06 15:35:29 -0800431 }
432
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100433 DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
434 DataType::Type GetResultType() const { return GetPackedType(); }
Aart Bikf8f5a162017-02-06 15:35:29 -0800435
Aart Bikb79f4ac2017-07-10 10:10:37 -0700436 bool CanBeMoved() const OVERRIDE { return true; }
437
Aart Bikf8f5a162017-02-06 15:35:29 -0800438 DECLARE_INSTRUCTION(VecCnv);
439
Artem Serovcced8ba2017-07-19 18:18:09 +0100440 protected:
441 DEFAULT_COPY_CONSTRUCTOR(VecCnv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800442};
443
444// Negates every component in the vector,
445// viz. neg[ x1, .. , xn ] = [ -x1, .. , -xn ].
446class HVecNeg FINAL : public HVecUnaryOperation {
447 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100448 HVecNeg(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800449 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100450 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800451 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700452 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530453 : HVecUnaryOperation(kVecNeg, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700454 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800455 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700456
457 bool CanBeMoved() const OVERRIDE { return true; }
458
Aart Bikf8f5a162017-02-06 15:35:29 -0800459 DECLARE_INSTRUCTION(VecNeg);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700460
Artem Serovcced8ba2017-07-19 18:18:09 +0100461 protected:
462 DEFAULT_COPY_CONSTRUCTOR(VecNeg);
Aart Bikf8f5a162017-02-06 15:35:29 -0800463};
464
Aart Bik6daebeb2017-04-03 14:35:41 -0700465// Takes absolute value of every component in the vector,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700466// viz. abs[ x1, .. , xn ] = [ |x1|, .. , |xn| ]
467// for signed operand x.
Aart Bik6daebeb2017-04-03 14:35:41 -0700468class HVecAbs FINAL : public HVecUnaryOperation {
469 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100470 HVecAbs(ArenaAllocator* allocator,
Aart Bik6daebeb2017-04-03 14:35:41 -0700471 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100472 DataType::Type packed_type,
Aart Bik6daebeb2017-04-03 14:35:41 -0700473 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700474 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530475 : HVecUnaryOperation(kVecAbs, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700476 DCHECK(HasConsistentPackedTypes(input, packed_type));
Aart Bik6daebeb2017-04-03 14:35:41 -0700477 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700478
479 bool CanBeMoved() const OVERRIDE { return true; }
480
Aart Bik6daebeb2017-04-03 14:35:41 -0700481 DECLARE_INSTRUCTION(VecAbs);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700482
Artem Serovcced8ba2017-07-19 18:18:09 +0100483 protected:
484 DEFAULT_COPY_CONSTRUCTOR(VecAbs);
Aart Bik6daebeb2017-04-03 14:35:41 -0700485};
486
Aart Bikf8f5a162017-02-06 15:35:29 -0800487// Bitwise- or boolean-nots every component in the vector,
488// viz. not[ x1, .. , xn ] = [ ~x1, .. , ~xn ], or
489// not[ x1, .. , xn ] = [ !x1, .. , !xn ] for boolean.
490class HVecNot FINAL : public HVecUnaryOperation {
491 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100492 HVecNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800493 HInstruction* input,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100494 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800495 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700496 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530497 : HVecUnaryOperation(kVecNot, allocator, input, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800498 DCHECK(input->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800499 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700500
501 bool CanBeMoved() const OVERRIDE { return true; }
502
Aart Bikf8f5a162017-02-06 15:35:29 -0800503 DECLARE_INSTRUCTION(VecNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700504
Artem Serovcced8ba2017-07-19 18:18:09 +0100505 protected:
506 DEFAULT_COPY_CONSTRUCTOR(VecNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800507};
508
Aart Bik8de59162017-04-21 09:42:01 -0700509//
510// Definitions of concrete binary vector operations in HIR.
511//
512
Aart Bikf8f5a162017-02-06 15:35:29 -0800513// Adds every component in the two vectors,
514// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 + y1, .. , xn + yn ].
515class HVecAdd FINAL : public HVecBinaryOperation {
516 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100517 HVecAdd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800518 HInstruction* left,
519 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100520 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800521 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700522 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530523 : HVecBinaryOperation(kVecAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700524 DCHECK(HasConsistentPackedTypes(left, packed_type));
525 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800526 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700527
528 bool CanBeMoved() const OVERRIDE { return true; }
529
Aart Bikf8f5a162017-02-06 15:35:29 -0800530 DECLARE_INSTRUCTION(VecAdd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700531
Artem Serovcced8ba2017-07-19 18:18:09 +0100532 protected:
533 DEFAULT_COPY_CONSTRUCTOR(VecAdd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800534};
535
Aart Bik29aa0822018-03-08 11:28:00 -0800536// Adds every component in the two vectors using saturation arithmetic,
537// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 +_sat y1, .. , xn +_sat yn ]
538// for either both signed or both unsigned operands x, y (reflected in packed_type).
539class HVecSaturationAdd FINAL : public HVecBinaryOperation {
540 public:
541 HVecSaturationAdd(ArenaAllocator* allocator,
542 HInstruction* left,
543 HInstruction* right,
544 DataType::Type packed_type,
545 size_t vector_length,
546 uint32_t dex_pc)
547 : HVecBinaryOperation(
548 kVecSaturationAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
549 DCHECK(HasConsistentPackedTypes(left, packed_type));
550 DCHECK(HasConsistentPackedTypes(right, packed_type));
551 }
552
553 bool CanBeMoved() const OVERRIDE { return true; }
554
555 DECLARE_INSTRUCTION(VecSaturationAdd);
556
557 protected:
558 DEFAULT_COPY_CONSTRUCTOR(VecSaturationAdd);
559};
560
Aart Bikf3e61ee2017-04-12 17:09:20 -0700561// Performs halving add on every component in the two vectors, viz.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700562// rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ]
563// truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ]
Aart Bik66c158e2018-01-31 12:55:04 -0800564// for either both signed or both unsigned operands x, y (reflected in packed_type).
Aart Bikf3e61ee2017-04-12 17:09:20 -0700565class HVecHalvingAdd FINAL : public HVecBinaryOperation {
566 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100567 HVecHalvingAdd(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700568 HInstruction* left,
569 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100570 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700571 size_t vector_length,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700572 bool is_rounded,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700573 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530574 : HVecBinaryOperation(
575 kVecHalvingAdd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700576 DCHECK(HasConsistentPackedTypes(left, packed_type));
577 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikdb14fcf2017-04-25 15:53:58 -0700578 SetPackedFlag<kFieldHAddIsRounded>(is_rounded);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700579 }
580
Aart Bikdb14fcf2017-04-25 15:53:58 -0700581 bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700582
Aart Bikb79f4ac2017-07-10 10:10:37 -0700583 bool CanBeMoved() const OVERRIDE { return true; }
584
585 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
586 DCHECK(other->IsVecHalvingAdd());
587 const HVecHalvingAdd* o = other->AsVecHalvingAdd();
Aart Bik66c158e2018-01-31 12:55:04 -0800588 return HVecOperation::InstructionDataEquals(o) && IsRounded() == o->IsRounded();
Aart Bikb79f4ac2017-07-10 10:10:37 -0700589 }
590
Aart Bikf3e61ee2017-04-12 17:09:20 -0700591 DECLARE_INSTRUCTION(VecHalvingAdd);
592
Artem Serovcced8ba2017-07-19 18:18:09 +0100593 protected:
594 DEFAULT_COPY_CONSTRUCTOR(VecHalvingAdd);
595
Aart Bikf3e61ee2017-04-12 17:09:20 -0700596 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -0700597 // Additional packed bits.
Aart Bik66c158e2018-01-31 12:55:04 -0800598 static constexpr size_t kFieldHAddIsRounded = HVecOperation::kNumberOfVectorOpPackedBits;
Aart Bikdb14fcf2017-04-25 15:53:58 -0700599 static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1;
600 static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf3e61ee2017-04-12 17:09:20 -0700601};
602
Aart Bikf8f5a162017-02-06 15:35:29 -0800603// Subtracts every component in the two vectors,
604// viz. [ x1, .. , xn ] - [ y1, .. , yn ] = [ x1 - y1, .. , xn - yn ].
605class HVecSub FINAL : public HVecBinaryOperation {
606 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100607 HVecSub(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800608 HInstruction* left,
609 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100610 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800611 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700612 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530613 : HVecBinaryOperation(kVecSub, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700614 DCHECK(HasConsistentPackedTypes(left, packed_type));
615 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800616 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700617
618 bool CanBeMoved() const OVERRIDE { return true; }
619
Aart Bikf8f5a162017-02-06 15:35:29 -0800620 DECLARE_INSTRUCTION(VecSub);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700621
Artem Serovcced8ba2017-07-19 18:18:09 +0100622 protected:
623 DEFAULT_COPY_CONSTRUCTOR(VecSub);
Aart Bikf8f5a162017-02-06 15:35:29 -0800624};
625
Aart Bik29aa0822018-03-08 11:28:00 -0800626// Subtracts every component in the two vectors using saturation arithmetic,
627// viz. [ x1, .. , xn ] + [ y1, .. , yn ] = [ x1 -_sat y1, .. , xn -_sat yn ]
628// for either both signed or both unsigned operands x, y (reflected in packed_type).
629class HVecSaturationSub FINAL : public HVecBinaryOperation {
630 public:
631 HVecSaturationSub(ArenaAllocator* allocator,
632 HInstruction* left,
633 HInstruction* right,
634 DataType::Type packed_type,
635 size_t vector_length,
636 uint32_t dex_pc)
637 : HVecBinaryOperation(
638 kVecSaturationSub, allocator, left, right, packed_type, vector_length, dex_pc) {
639 DCHECK(HasConsistentPackedTypes(left, packed_type));
640 DCHECK(HasConsistentPackedTypes(right, packed_type));
641 }
642
643 bool CanBeMoved() const OVERRIDE { return true; }
644
645 DECLARE_INSTRUCTION(VecSaturationSub);
646
647 protected:
648 DEFAULT_COPY_CONSTRUCTOR(VecSaturationSub);
649};
650
Aart Bikf8f5a162017-02-06 15:35:29 -0800651// Multiplies every component in the two vectors,
652// viz. [ x1, .. , xn ] * [ y1, .. , yn ] = [ x1 * y1, .. , xn * yn ].
653class HVecMul FINAL : public HVecBinaryOperation {
654 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100655 HVecMul(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800656 HInstruction* left,
657 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100658 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800659 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700660 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530661 : HVecBinaryOperation(kVecMul, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700662 DCHECK(HasConsistentPackedTypes(left, packed_type));
663 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800664 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700665
666 bool CanBeMoved() const OVERRIDE { return true; }
667
Aart Bikf8f5a162017-02-06 15:35:29 -0800668 DECLARE_INSTRUCTION(VecMul);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700669
Artem Serovcced8ba2017-07-19 18:18:09 +0100670 protected:
671 DEFAULT_COPY_CONSTRUCTOR(VecMul);
Aart Bikf8f5a162017-02-06 15:35:29 -0800672};
673
674// Divides every component in the two vectors,
675// viz. [ x1, .. , xn ] / [ y1, .. , yn ] = [ x1 / y1, .. , xn / yn ].
676class HVecDiv FINAL : public HVecBinaryOperation {
677 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100678 HVecDiv(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800679 HInstruction* left,
680 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100681 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800682 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700683 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530684 : HVecBinaryOperation(kVecDiv, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700685 DCHECK(HasConsistentPackedTypes(left, packed_type));
686 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800687 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700688
689 bool CanBeMoved() const OVERRIDE { return true; }
690
Aart Bikf8f5a162017-02-06 15:35:29 -0800691 DECLARE_INSTRUCTION(VecDiv);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700692
Artem Serovcced8ba2017-07-19 18:18:09 +0100693 protected:
694 DEFAULT_COPY_CONSTRUCTOR(VecDiv);
Aart Bikf8f5a162017-02-06 15:35:29 -0800695};
696
Aart Bikf3e61ee2017-04-12 17:09:20 -0700697// Takes minimum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700698// viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800699// for either both signed or both unsigned operands x, y (reflected in packed_type).
Aart Bikf3e61ee2017-04-12 17:09:20 -0700700class HVecMin FINAL : public HVecBinaryOperation {
701 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100702 HVecMin(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700703 HInstruction* left,
704 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100705 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700706 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700707 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530708 : HVecBinaryOperation(kVecMin, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700709 DCHECK(HasConsistentPackedTypes(left, packed_type));
710 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700711 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700712
Aart Bikb79f4ac2017-07-10 10:10:37 -0700713 bool CanBeMoved() const OVERRIDE { return true; }
714
Aart Bikf3e61ee2017-04-12 17:09:20 -0700715 DECLARE_INSTRUCTION(VecMin);
Aart Bikc8e93c72017-05-10 10:49:22 -0700716
Artem Serovcced8ba2017-07-19 18:18:09 +0100717 protected:
718 DEFAULT_COPY_CONSTRUCTOR(VecMin);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700719};
720
721// Takes maximum of every component in the two vectors,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700722// viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ]
Aart Bik66c158e2018-01-31 12:55:04 -0800723// for either both signed or both unsigned operands x, y (reflected in packed_type).
Aart Bikf3e61ee2017-04-12 17:09:20 -0700724class HVecMax FINAL : public HVecBinaryOperation {
725 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100726 HVecMax(ArenaAllocator* allocator,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700727 HInstruction* left,
728 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100729 DataType::Type packed_type,
Aart Bikf3e61ee2017-04-12 17:09:20 -0700730 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700731 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530732 : HVecBinaryOperation(kVecMax, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700733 DCHECK(HasConsistentPackedTypes(left, packed_type));
734 DCHECK(HasConsistentPackedTypes(right, packed_type));
Aart Bikf3e61ee2017-04-12 17:09:20 -0700735 }
Aart Bikc8e93c72017-05-10 10:49:22 -0700736
Aart Bikb79f4ac2017-07-10 10:10:37 -0700737 bool CanBeMoved() const OVERRIDE { return true; }
738
Aart Bikf3e61ee2017-04-12 17:09:20 -0700739 DECLARE_INSTRUCTION(VecMax);
Aart Bikc8e93c72017-05-10 10:49:22 -0700740
Artem Serovcced8ba2017-07-19 18:18:09 +0100741 protected:
742 DEFAULT_COPY_CONSTRUCTOR(VecMax);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700743};
744
Aart Bikf8f5a162017-02-06 15:35:29 -0800745// Bitwise-ands every component in the two vectors,
746// viz. [ x1, .. , xn ] & [ y1, .. , yn ] = [ x1 & y1, .. , xn & yn ].
747class HVecAnd FINAL : public HVecBinaryOperation {
748 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100749 HVecAnd(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800750 HInstruction* left,
751 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100752 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800753 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700754 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530755 : HVecBinaryOperation(kVecAnd, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800756 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800757 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700758
759 bool CanBeMoved() const OVERRIDE { return true; }
760
Aart Bikf8f5a162017-02-06 15:35:29 -0800761 DECLARE_INSTRUCTION(VecAnd);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700762
Artem Serovcced8ba2017-07-19 18:18:09 +0100763 protected:
764 DEFAULT_COPY_CONSTRUCTOR(VecAnd);
Aart Bikf8f5a162017-02-06 15:35:29 -0800765};
766
767// Bitwise-and-nots every component in the two vectors,
768// viz. [ x1, .. , xn ] and-not [ y1, .. , yn ] = [ ~x1 & y1, .. , ~xn & yn ].
769class HVecAndNot FINAL : public HVecBinaryOperation {
770 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100771 HVecAndNot(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800772 HInstruction* left,
773 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100774 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800775 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700776 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530777 : HVecBinaryOperation(
778 kVecAndNot, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800779 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800780 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700781
782 bool CanBeMoved() const OVERRIDE { return true; }
783
Aart Bikf8f5a162017-02-06 15:35:29 -0800784 DECLARE_INSTRUCTION(VecAndNot);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700785
Artem Serovcced8ba2017-07-19 18:18:09 +0100786 protected:
787 DEFAULT_COPY_CONSTRUCTOR(VecAndNot);
Aart Bikf8f5a162017-02-06 15:35:29 -0800788};
789
790// Bitwise-ors every component in the two vectors,
791// viz. [ x1, .. , xn ] | [ y1, .. , yn ] = [ x1 | y1, .. , xn | yn ].
792class HVecOr FINAL : public HVecBinaryOperation {
793 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100794 HVecOr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800795 HInstruction* left,
796 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100797 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800798 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700799 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530800 : HVecBinaryOperation(kVecOr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800801 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800802 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700803
804 bool CanBeMoved() const OVERRIDE { return true; }
805
Aart Bikf8f5a162017-02-06 15:35:29 -0800806 DECLARE_INSTRUCTION(VecOr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700807
Artem Serovcced8ba2017-07-19 18:18:09 +0100808 protected:
809 DEFAULT_COPY_CONSTRUCTOR(VecOr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800810};
811
812// Bitwise-xors every component in the two vectors,
813// viz. [ x1, .. , xn ] ^ [ y1, .. , yn ] = [ x1 ^ y1, .. , xn ^ yn ].
814class HVecXor FINAL : public HVecBinaryOperation {
815 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100816 HVecXor(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800817 HInstruction* left,
818 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100819 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800820 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700821 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530822 : HVecBinaryOperation(kVecXor, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikf8f5a162017-02-06 15:35:29 -0800823 DCHECK(left->IsVecOperation() && right->IsVecOperation());
Aart Bikf8f5a162017-02-06 15:35:29 -0800824 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700825
826 bool CanBeMoved() const OVERRIDE { return true; }
827
Aart Bikf8f5a162017-02-06 15:35:29 -0800828 DECLARE_INSTRUCTION(VecXor);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700829
Artem Serovcced8ba2017-07-19 18:18:09 +0100830 protected:
831 DEFAULT_COPY_CONSTRUCTOR(VecXor);
Aart Bikf8f5a162017-02-06 15:35:29 -0800832};
833
834// Logically shifts every component in the vector left by the given distance,
835// viz. [ x1, .. , xn ] << d = [ x1 << d, .. , xn << d ].
836class HVecShl FINAL : public HVecBinaryOperation {
837 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100838 HVecShl(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800839 HInstruction* left,
840 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100841 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800842 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700843 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530844 : HVecBinaryOperation(kVecShl, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700845 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800846 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700847
848 bool CanBeMoved() const OVERRIDE { return true; }
849
Aart Bikf8f5a162017-02-06 15:35:29 -0800850 DECLARE_INSTRUCTION(VecShl);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700851
Artem Serovcced8ba2017-07-19 18:18:09 +0100852 protected:
853 DEFAULT_COPY_CONSTRUCTOR(VecShl);
Aart Bikf8f5a162017-02-06 15:35:29 -0800854};
855
856// Arithmetically shifts every component in the vector right by the given distance,
857// viz. [ x1, .. , xn ] >> d = [ x1 >> d, .. , xn >> d ].
858class HVecShr FINAL : public HVecBinaryOperation {
859 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100860 HVecShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800861 HInstruction* left,
862 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100863 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800864 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700865 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530866 : HVecBinaryOperation(kVecShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700867 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800868 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700869
870 bool CanBeMoved() const OVERRIDE { return true; }
871
Aart Bikf8f5a162017-02-06 15:35:29 -0800872 DECLARE_INSTRUCTION(VecShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700873
Artem Serovcced8ba2017-07-19 18:18:09 +0100874 protected:
875 DEFAULT_COPY_CONSTRUCTOR(VecShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800876};
877
878// Logically shifts every component in the vector right by the given distance,
879// viz. [ x1, .. , xn ] >>> d = [ x1 >>> d, .. , xn >>> d ].
880class HVecUShr FINAL : public HVecBinaryOperation {
881 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100882 HVecUShr(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -0800883 HInstruction* left,
884 HInstruction* right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100885 DataType::Type packed_type,
Aart Bikf8f5a162017-02-06 15:35:29 -0800886 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700887 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530888 : HVecBinaryOperation(kVecUShr, allocator, left, right, packed_type, vector_length, dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -0700889 DCHECK(HasConsistentPackedTypes(left, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -0800890 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700891
892 bool CanBeMoved() const OVERRIDE { return true; }
893
Aart Bikf8f5a162017-02-06 15:35:29 -0800894 DECLARE_INSTRUCTION(VecUShr);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700895
Artem Serovcced8ba2017-07-19 18:18:09 +0100896 protected:
897 DEFAULT_COPY_CONSTRUCTOR(VecUShr);
Aart Bikf8f5a162017-02-06 15:35:29 -0800898};
899
Aart Bik8de59162017-04-21 09:42:01 -0700900//
901// Definitions of concrete miscellaneous vector operations in HIR.
902//
903
904// Assigns the given scalar elements to a vector,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700905// viz. set( array(x1, .. , xn) ) = [ x1, .. , xn ] if n == m,
906// set( array(x1, .. , xm) ) = [ x1, .. , xm, 0, .. , 0 ] if m < n.
Aart Bik8de59162017-04-21 09:42:01 -0700907class HVecSetScalars FINAL : public HVecOperation {
Aart Bik0148de42017-09-05 09:25:01 -0700908 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100909 HVecSetScalars(ArenaAllocator* allocator,
Aart Bik5e3afa92017-09-20 14:11:11 -0700910 HInstruction* scalars[],
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100911 DataType::Type packed_type,
Aart Bik8de59162017-04-21 09:42:01 -0700912 size_t vector_length,
Aart Bik0148de42017-09-05 09:25:01 -0700913 size_t number_of_scalars,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700914 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530915 : HVecOperation(kVecSetScalars,
916 allocator,
Aart Bik8de59162017-04-21 09:42:01 -0700917 packed_type,
918 SideEffects::None(),
Aart Bik0148de42017-09-05 09:25:01 -0700919 number_of_scalars,
Aart Bik8de59162017-04-21 09:42:01 -0700920 vector_length,
921 dex_pc) {
Aart Bik0148de42017-09-05 09:25:01 -0700922 for (size_t i = 0; i < number_of_scalars; i++) {
Aart Bik2dd7b672017-12-07 11:11:22 -0800923 DCHECK(!ReturnsSIMDValue(scalars[i]));
Aart Bik8de59162017-04-21 09:42:01 -0700924 SetRawInputAt(0, scalars[i]);
925 }
926 }
Aart Bikb79f4ac2017-07-10 10:10:37 -0700927
928 // Setting scalars needs to stay in place, since SIMD registers are not
929 // kept alive across vector loop boundaries (yet).
930 bool CanBeMoved() const OVERRIDE { return false; }
931
Aart Bik8de59162017-04-21 09:42:01 -0700932 DECLARE_INSTRUCTION(VecSetScalars);
Aart Bikb79f4ac2017-07-10 10:10:37 -0700933
Artem Serovcced8ba2017-07-19 18:18:09 +0100934 protected:
935 DEFAULT_COPY_CONSTRUCTOR(VecSetScalars);
Aart Bik8de59162017-04-21 09:42:01 -0700936};
937
Aart Bikdbbac8f2017-09-01 13:06:08 -0700938// Multiplies every component in the two vectors, adds the result vector to the accumulator vector,
939// viz. [ a1, .. , an ] + [ x1, .. , xn ] * [ y1, .. , yn ] = [ a1 + x1 * y1, .. , an + xn * yn ].
Artem Serovf34dd202017-04-10 17:41:46 +0100940class HVecMultiplyAccumulate FINAL : public HVecOperation {
941 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100942 HVecMultiplyAccumulate(ArenaAllocator* allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100943 InstructionKind op,
944 HInstruction* accumulator,
945 HInstruction* mul_left,
946 HInstruction* mul_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100947 DataType::Type packed_type,
Artem Serovf34dd202017-04-10 17:41:46 +0100948 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700949 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +0530950 : HVecOperation(kVecMultiplyAccumulate,
951 allocator,
Artem Serovf34dd202017-04-10 17:41:46 +0100952 packed_type,
953 SideEffects::None(),
Aart Bik8de59162017-04-21 09:42:01 -0700954 /* number_of_inputs */ 3,
Artem Serovf34dd202017-04-10 17:41:46 +0100955 vector_length,
956 dex_pc),
957 op_kind_(op) {
958 DCHECK(op == InstructionKind::kAdd || op == InstructionKind::kSub);
Aart Bikd58bc322017-05-01 14:49:18 -0700959 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
960 DCHECK(HasConsistentPackedTypes(mul_left, packed_type));
961 DCHECK(HasConsistentPackedTypes(mul_right, packed_type));
Aart Bikdbbac8f2017-09-01 13:06:08 -0700962 SetRawInputAt(0, accumulator);
963 SetRawInputAt(1, mul_left);
964 SetRawInputAt(2, mul_right);
Artem Serovf34dd202017-04-10 17:41:46 +0100965 }
966
Nicolas Geoffray9858bf72017-07-08 12:34:55 +0000967 bool CanBeMoved() const OVERRIDE { return true; }
968
Artem Serovf34dd202017-04-10 17:41:46 +0100969 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
Aart Bikb79f4ac2017-07-10 10:10:37 -0700970 DCHECK(other->IsVecMultiplyAccumulate());
971 const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
972 return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
Artem Serovf34dd202017-04-10 17:41:46 +0100973 }
974
975 InstructionKind GetOpKind() const { return op_kind_; }
976
977 DECLARE_INSTRUCTION(VecMultiplyAccumulate);
978
Artem Serovcced8ba2017-07-19 18:18:09 +0100979 protected:
980 DEFAULT_COPY_CONSTRUCTOR(VecMultiplyAccumulate);
981
Artem Serovf34dd202017-04-10 17:41:46 +0100982 private:
983 // Indicates if this is a MADD or MSUB.
984 const InstructionKind op_kind_;
Artem Serovf34dd202017-04-10 17:41:46 +0100985};
986
Aart Bikdbbac8f2017-09-01 13:06:08 -0700987// Takes the absolute difference of two vectors, and adds the results to
988// same-precision or wider-precision components in the accumulator,
Aart Bik46b6dbc2017-10-03 11:37:37 -0700989// viz. SAD([ a1, .. , am ], [ x1, .. , xn ], [ y1, .. , yn ]) =
Aart Bikdbbac8f2017-09-01 13:06:08 -0700990// [ a1 + sum abs(xi-yi), .. , am + sum abs(xj-yj) ],
Aart Bik46b6dbc2017-10-03 11:37:37 -0700991// for m <= n, non-overlapping sums, and signed operands x, y.
Aart Bikdbbac8f2017-09-01 13:06:08 -0700992class HVecSADAccumulate FINAL : public HVecOperation {
993 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100994 HVecSADAccumulate(ArenaAllocator* allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700995 HInstruction* accumulator,
996 HInstruction* sad_left,
997 HInstruction* sad_right,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100998 DataType::Type packed_type,
Aart Bikdbbac8f2017-09-01 13:06:08 -0700999 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001000 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301001 : HVecOperation(kVecSADAccumulate,
1002 allocator,
Aart Bikdbbac8f2017-09-01 13:06:08 -07001003 packed_type,
1004 SideEffects::None(),
1005 /* number_of_inputs */ 3,
1006 vector_length,
1007 dex_pc) {
1008 DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
1009 DCHECK(sad_left->IsVecOperation());
1010 DCHECK(sad_right->IsVecOperation());
Vladimir Marko61b92282017-10-11 13:23:17 +01001011 DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
1012 ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
Aart Bikdbbac8f2017-09-01 13:06:08 -07001013 SetRawInputAt(0, accumulator);
1014 SetRawInputAt(1, sad_left);
1015 SetRawInputAt(2, sad_right);
1016 }
1017
1018 DECLARE_INSTRUCTION(VecSADAccumulate);
1019
Artem Serovcced8ba2017-07-19 18:18:09 +01001020 protected:
1021 DEFAULT_COPY_CONSTRUCTOR(VecSADAccumulate);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001022};
1023
Aart Bikf8f5a162017-02-06 15:35:29 -08001024// Loads a vector from memory, viz. load(mem, 1)
1025// yield the vector [ mem(1), .. , mem(n) ].
1026class HVecLoad FINAL : public HVecMemoryOperation {
1027 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001028 HVecLoad(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001029 HInstruction* base,
1030 HInstruction* index,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001031 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001032 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001033 size_t vector_length,
Aart Bikdb14fcf2017-04-25 15:53:58 -07001034 bool is_string_char_at,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001035 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301036 : HVecMemoryOperation(kVecLoad,
1037 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001038 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001039 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001040 /* number_of_inputs */ 2,
Aart Bikf8f5a162017-02-06 15:35:29 -08001041 vector_length,
1042 dex_pc) {
1043 SetRawInputAt(0, base);
1044 SetRawInputAt(1, index);
Aart Bikdb14fcf2017-04-25 15:53:58 -07001045 SetPackedFlag<kFieldIsStringCharAt>(is_string_char_at);
Aart Bikf8f5a162017-02-06 15:35:29 -08001046 }
Aart Bikdb14fcf2017-04-25 15:53:58 -07001047
1048 bool IsStringCharAt() const { return GetPackedFlag<kFieldIsStringCharAt>(); }
1049
Aart Bikb79f4ac2017-07-10 10:10:37 -07001050 bool CanBeMoved() const OVERRIDE { return true; }
1051
1052 bool InstructionDataEquals(const HInstruction* other) const OVERRIDE {
1053 DCHECK(other->IsVecLoad());
1054 const HVecLoad* o = other->AsVecLoad();
1055 return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
1056 }
1057
1058 DECLARE_INSTRUCTION(VecLoad);
1059
Artem Serovcced8ba2017-07-19 18:18:09 +01001060 protected:
1061 DEFAULT_COPY_CONSTRUCTOR(VecLoad);
1062
Aart Bikf8f5a162017-02-06 15:35:29 -08001063 private:
Aart Bikdb14fcf2017-04-25 15:53:58 -07001064 // Additional packed bits.
1065 static constexpr size_t kFieldIsStringCharAt = HVecOperation::kNumberOfVectorOpPackedBits;
1066 static constexpr size_t kNumberOfVecLoadPackedBits = kFieldIsStringCharAt + 1;
1067 static_assert(kNumberOfVecLoadPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields.");
Aart Bikf8f5a162017-02-06 15:35:29 -08001068};
1069
1070// Stores a vector to memory, viz. store(m, 1, [x1, .. , xn] )
1071// sets mem(1) = x1, .. , mem(n) = xn.
1072class HVecStore FINAL : public HVecMemoryOperation {
1073 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001074 HVecStore(ArenaAllocator* allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001075 HInstruction* base,
1076 HInstruction* index,
1077 HInstruction* value,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001078 DataType::Type packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001079 SideEffects side_effects,
Aart Bikf8f5a162017-02-06 15:35:29 -08001080 size_t vector_length,
Aart Bik46b6dbc2017-10-03 11:37:37 -07001081 uint32_t dex_pc)
Gupta Kumar, Sanjivd9e4d732018-02-05 13:35:03 +05301082 : HVecMemoryOperation(kVecStore,
1083 allocator,
Aart Bikf8f5a162017-02-06 15:35:29 -08001084 packed_type,
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001085 side_effects,
Aart Bik8de59162017-04-21 09:42:01 -07001086 /* number_of_inputs */ 3,
Aart Bikf8f5a162017-02-06 15:35:29 -08001087 vector_length,
1088 dex_pc) {
Aart Bikd58bc322017-05-01 14:49:18 -07001089 DCHECK(HasConsistentPackedTypes(value, packed_type));
Aart Bikf8f5a162017-02-06 15:35:29 -08001090 SetRawInputAt(0, base);
1091 SetRawInputAt(1, index);
1092 SetRawInputAt(2, value);
1093 }
Aart Bikb79f4ac2017-07-10 10:10:37 -07001094
1095 // A store needs to stay in place.
1096 bool CanBeMoved() const OVERRIDE { return false; }
1097
Aart Bikf8f5a162017-02-06 15:35:29 -08001098 DECLARE_INSTRUCTION(VecStore);
Aart Bikb79f4ac2017-07-10 10:10:37 -07001099
Artem Serovcced8ba2017-07-19 18:18:09 +01001100 protected:
1101 DEFAULT_COPY_CONSTRUCTOR(VecStore)
Aart Bikf8f5a162017-02-06 15:35:29 -08001102};
1103
1104} // namespace art
1105
1106#endif // ART_COMPILER_OPTIMIZING_NODES_VECTOR_H_