blob: 2d69533f21e3d6440899e498005eb17de35461c2 [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#include "code_generator_mips64.h"
Goran Jakovljevic19680d32017-05-11 10:38:36 +020018#include "mirror/array-inl.h"
Aart Bikf8f5a162017-02-06 15:35:29 -080019
20namespace art {
21namespace mips64 {
22
23// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
24#define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT
25
Goran Jakovljevic19680d32017-05-11 10:38:36 +020026VectorRegister VectorRegisterFrom(Location location) {
27 DCHECK(location.IsFpuRegister());
28 return static_cast<VectorRegister>(location.AsFpuRegister<FpuRegister>());
29}
30
Aart Bikf8f5a162017-02-06 15:35:29 -080031void LocationsBuilderMIPS64::VisitVecReplicateScalar(HVecReplicateScalar* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +010032 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevic19680d32017-05-11 10:38:36 +020033 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010034 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010035 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010036 case DataType::Type::kInt8:
37 case DataType::Type::kUint16:
38 case DataType::Type::kInt16:
39 case DataType::Type::kInt32:
40 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020041 locations->SetInAt(0, Location::RequiresRegister());
42 locations->SetOut(Location::RequiresFpuRegister());
43 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010044 case DataType::Type::kFloat32:
45 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020046 locations->SetInAt(0, Location::RequiresFpuRegister());
47 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
48 break;
49 default:
50 LOG(FATAL) << "Unsupported SIMD type";
51 UNREACHABLE();
52 }
Aart Bikf8f5a162017-02-06 15:35:29 -080053}
54
55void InstructionCodeGeneratorMIPS64::VisitVecReplicateScalar(HVecReplicateScalar* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +020056 LocationSummary* locations = instruction->GetLocations();
57 VectorRegister dst = VectorRegisterFrom(locations->Out());
58 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010059 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010060 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010061 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020062 DCHECK_EQ(16u, instruction->GetVectorLength());
63 __ FillB(dst, locations->InAt(0).AsRegister<GpuRegister>());
64 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010065 case DataType::Type::kUint16:
66 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020067 DCHECK_EQ(8u, instruction->GetVectorLength());
68 __ FillH(dst, locations->InAt(0).AsRegister<GpuRegister>());
69 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010070 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020071 DCHECK_EQ(4u, instruction->GetVectorLength());
72 __ FillW(dst, locations->InAt(0).AsRegister<GpuRegister>());
73 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010074 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020075 DCHECK_EQ(2u, instruction->GetVectorLength());
76 __ FillD(dst, locations->InAt(0).AsRegister<GpuRegister>());
77 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010078 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020079 DCHECK_EQ(4u, instruction->GetVectorLength());
80 __ ReplicateFPToVectorRegister(dst,
81 locations->InAt(0).AsFpuRegister<FpuRegister>(),
82 /* is_double */ false);
83 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010084 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +020085 DCHECK_EQ(2u, instruction->GetVectorLength());
86 __ ReplicateFPToVectorRegister(dst,
87 locations->InAt(0).AsFpuRegister<FpuRegister>(),
88 /* is_double */ true);
89 break;
90 default:
91 LOG(FATAL) << "Unsupported SIMD type";
92 UNREACHABLE();
93 }
Aart Bikf8f5a162017-02-06 15:35:29 -080094}
95
Aart Bik0148de42017-09-05 09:25:01 -070096void LocationsBuilderMIPS64::VisitVecExtractScalar(HVecExtractScalar* instruction) {
Lena Djokice434c4f2017-10-23 16:40:22 +020097 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
98 switch (instruction->GetPackedType()) {
99 case DataType::Type::kBool:
100 case DataType::Type::kUint8:
101 case DataType::Type::kInt8:
102 case DataType::Type::kUint16:
103 case DataType::Type::kInt16:
104 case DataType::Type::kInt32:
105 case DataType::Type::kInt64:
106 locations->SetInAt(0, Location::RequiresFpuRegister());
107 locations->SetOut(Location::RequiresRegister());
108 break;
109 case DataType::Type::kFloat32:
110 case DataType::Type::kFloat64:
111 locations->SetInAt(0, Location::RequiresFpuRegister());
112 locations->SetOut(Location::SameAsFirstInput());
113 break;
114 default:
115 LOG(FATAL) << "Unsupported SIMD type";
116 UNREACHABLE();
117 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800118}
119
Aart Bik0148de42017-09-05 09:25:01 -0700120void InstructionCodeGeneratorMIPS64::VisitVecExtractScalar(HVecExtractScalar* instruction) {
Lena Djokice434c4f2017-10-23 16:40:22 +0200121 LocationSummary* locations = instruction->GetLocations();
122 VectorRegister src = VectorRegisterFrom(locations->InAt(0));
123 switch (instruction->GetPackedType()) {
124 case DataType::Type::kInt32:
125 DCHECK_EQ(4u, instruction->GetVectorLength());
126 __ Copy_sW(locations->Out().AsRegister<GpuRegister>(), src, 0);
127 break;
128 case DataType::Type::kInt64:
129 DCHECK_EQ(2u, instruction->GetVectorLength());
130 __ Copy_sD(locations->Out().AsRegister<GpuRegister>(), src, 0);
131 break;
132 case DataType::Type::kFloat32:
133 case DataType::Type::kFloat64:
134 DCHECK_LE(2u, instruction->GetVectorLength());
135 DCHECK_LE(instruction->GetVectorLength(), 4u);
136 DCHECK(locations->InAt(0).Equals(locations->Out())); // no code required
137 break;
138 default:
139 LOG(FATAL) << "Unsupported SIMD type";
140 UNREACHABLE();
141 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800142}
143
144// Helper to set up locations for vector unary operations.
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100145static void CreateVecUnOpLocations(ArenaAllocator* allocator, HVecUnaryOperation* instruction) {
146 LocationSummary* locations = new (allocator) LocationSummary(instruction);
Lena Djokice434c4f2017-10-23 16:40:22 +0200147 DataType::Type type = instruction->GetPackedType();
148 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100149 case DataType::Type::kBool:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200150 locations->SetInAt(0, Location::RequiresFpuRegister());
151 locations->SetOut(Location::RequiresFpuRegister(),
152 instruction->IsVecNot() ? Location::kOutputOverlap
153 : Location::kNoOutputOverlap);
154 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100155 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100156 case DataType::Type::kInt8:
157 case DataType::Type::kUint16:
158 case DataType::Type::kInt16:
159 case DataType::Type::kInt32:
160 case DataType::Type::kInt64:
161 case DataType::Type::kFloat32:
162 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200163 locations->SetInAt(0, Location::RequiresFpuRegister());
164 locations->SetOut(Location::RequiresFpuRegister(),
Lena Djokice434c4f2017-10-23 16:40:22 +0200165 (instruction->IsVecNeg() || instruction->IsVecAbs() ||
166 (instruction->IsVecReduce() && type == DataType::Type::kInt64))
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200167 ? Location::kOutputOverlap
168 : Location::kNoOutputOverlap);
Aart Bikf8f5a162017-02-06 15:35:29 -0800169 break;
170 default:
171 LOG(FATAL) << "Unsupported SIMD type";
172 UNREACHABLE();
173 }
174}
175
Aart Bik0148de42017-09-05 09:25:01 -0700176void LocationsBuilderMIPS64::VisitVecReduce(HVecReduce* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100177 CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bik0148de42017-09-05 09:25:01 -0700178}
179
180void InstructionCodeGeneratorMIPS64::VisitVecReduce(HVecReduce* instruction) {
Lena Djokice434c4f2017-10-23 16:40:22 +0200181 LocationSummary* locations = instruction->GetLocations();
182 VectorRegister src = VectorRegisterFrom(locations->InAt(0));
183 VectorRegister dst = VectorRegisterFrom(locations->Out());
184 VectorRegister tmp = static_cast<VectorRegister>(FTMP);
185 switch (instruction->GetPackedType()) {
186 case DataType::Type::kInt32:
187 DCHECK_EQ(4u, instruction->GetVectorLength());
188 switch (instruction->GetKind()) {
189 case HVecReduce::kSum:
190 __ Hadd_sD(tmp, src, src);
191 __ IlvlD(dst, tmp, tmp);
192 __ AddvW(dst, dst, tmp);
193 break;
194 case HVecReduce::kMin:
195 __ IlvodW(tmp, src, src);
196 __ Min_sW(tmp, src, tmp);
197 __ IlvlW(dst, tmp, tmp);
198 __ Min_sW(dst, dst, tmp);
199 break;
200 case HVecReduce::kMax:
201 __ IlvodW(tmp, src, src);
202 __ Max_sW(tmp, src, tmp);
203 __ IlvlW(dst, tmp, tmp);
204 __ Max_sW(dst, dst, tmp);
205 break;
206 }
207 break;
208 case DataType::Type::kInt64:
209 DCHECK_EQ(2u, instruction->GetVectorLength());
210 switch (instruction->GetKind()) {
211 case HVecReduce::kSum:
212 __ IlvlD(dst, src, src);
213 __ AddvD(dst, dst, src);
214 break;
215 case HVecReduce::kMin:
216 __ IlvlD(dst, src, src);
217 __ Min_sD(dst, dst, src);
218 break;
219 case HVecReduce::kMax:
220 __ IlvlD(dst, src, src);
221 __ Max_sD(dst, dst, src);
222 break;
223 }
224 break;
225 default:
226 LOG(FATAL) << "Unsupported SIMD type";
227 UNREACHABLE();
228 }
Aart Bik0148de42017-09-05 09:25:01 -0700229}
230
Aart Bikf8f5a162017-02-06 15:35:29 -0800231void LocationsBuilderMIPS64::VisitVecCnv(HVecCnv* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100232 CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800233}
234
235void InstructionCodeGeneratorMIPS64::VisitVecCnv(HVecCnv* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200236 LocationSummary* locations = instruction->GetLocations();
237 VectorRegister src = VectorRegisterFrom(locations->InAt(0));
238 VectorRegister dst = VectorRegisterFrom(locations->Out());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100239 DataType::Type from = instruction->GetInputType();
240 DataType::Type to = instruction->GetResultType();
241 if (from == DataType::Type::kInt32 && to == DataType::Type::kFloat32) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200242 DCHECK_EQ(4u, instruction->GetVectorLength());
243 __ Ffint_sW(dst, src);
244 } else {
245 LOG(FATAL) << "Unsupported SIMD type";
246 UNREACHABLE();
247 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800248}
249
250void LocationsBuilderMIPS64::VisitVecNeg(HVecNeg* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100251 CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800252}
253
254void InstructionCodeGeneratorMIPS64::VisitVecNeg(HVecNeg* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200255 LocationSummary* locations = instruction->GetLocations();
256 VectorRegister src = VectorRegisterFrom(locations->InAt(0));
257 VectorRegister dst = VectorRegisterFrom(locations->Out());
258 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100259 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100260 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200261 DCHECK_EQ(16u, instruction->GetVectorLength());
262 __ FillB(dst, ZERO);
263 __ SubvB(dst, dst, src);
264 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100265 case DataType::Type::kUint16:
266 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200267 DCHECK_EQ(8u, instruction->GetVectorLength());
268 __ FillH(dst, ZERO);
269 __ SubvH(dst, dst, src);
270 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100271 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200272 DCHECK_EQ(4u, instruction->GetVectorLength());
273 __ FillW(dst, ZERO);
274 __ SubvW(dst, dst, src);
275 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100276 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200277 DCHECK_EQ(2u, instruction->GetVectorLength());
278 __ FillD(dst, ZERO);
279 __ SubvD(dst, dst, src);
280 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100281 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200282 DCHECK_EQ(4u, instruction->GetVectorLength());
283 __ FillW(dst, ZERO);
284 __ FsubW(dst, dst, src);
285 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100286 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200287 DCHECK_EQ(2u, instruction->GetVectorLength());
288 __ FillD(dst, ZERO);
289 __ FsubD(dst, dst, src);
290 break;
291 default:
292 LOG(FATAL) << "Unsupported SIMD type";
293 UNREACHABLE();
294 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800295}
296
Aart Bik6daebeb2017-04-03 14:35:41 -0700297void LocationsBuilderMIPS64::VisitVecAbs(HVecAbs* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100298 CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bik6daebeb2017-04-03 14:35:41 -0700299}
300
301void InstructionCodeGeneratorMIPS64::VisitVecAbs(HVecAbs* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200302 LocationSummary* locations = instruction->GetLocations();
303 VectorRegister src = VectorRegisterFrom(locations->InAt(0));
304 VectorRegister dst = VectorRegisterFrom(locations->Out());
305 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100306 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200307 DCHECK_EQ(16u, instruction->GetVectorLength());
308 __ FillB(dst, ZERO); // all zeroes
309 __ Add_aB(dst, dst, src); // dst = abs(0) + abs(src)
310 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100311 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200312 DCHECK_EQ(8u, instruction->GetVectorLength());
313 __ FillH(dst, ZERO); // all zeroes
314 __ Add_aH(dst, dst, src); // dst = abs(0) + abs(src)
315 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100316 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200317 DCHECK_EQ(4u, instruction->GetVectorLength());
318 __ FillW(dst, ZERO); // all zeroes
319 __ Add_aW(dst, dst, src); // dst = abs(0) + abs(src)
320 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100321 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200322 DCHECK_EQ(2u, instruction->GetVectorLength());
323 __ FillD(dst, ZERO); // all zeroes
324 __ Add_aD(dst, dst, src); // dst = abs(0) + abs(src)
325 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100326 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200327 DCHECK_EQ(4u, instruction->GetVectorLength());
328 __ LdiW(dst, -1); // all ones
329 __ SrliW(dst, dst, 1);
330 __ AndV(dst, dst, src);
331 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100332 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200333 DCHECK_EQ(2u, instruction->GetVectorLength());
334 __ LdiD(dst, -1); // all ones
335 __ SrliD(dst, dst, 1);
336 __ AndV(dst, dst, src);
337 break;
338 default:
339 LOG(FATAL) << "Unsupported SIMD type";
340 UNREACHABLE();
341 }
Aart Bik6daebeb2017-04-03 14:35:41 -0700342}
343
Aart Bikf8f5a162017-02-06 15:35:29 -0800344void LocationsBuilderMIPS64::VisitVecNot(HVecNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100345 CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800346}
347
348void InstructionCodeGeneratorMIPS64::VisitVecNot(HVecNot* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200349 LocationSummary* locations = instruction->GetLocations();
350 VectorRegister src = VectorRegisterFrom(locations->InAt(0));
351 VectorRegister dst = VectorRegisterFrom(locations->Out());
352 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100353 case DataType::Type::kBool: // special case boolean-not
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200354 DCHECK_EQ(16u, instruction->GetVectorLength());
355 __ LdiB(dst, 1);
356 __ XorV(dst, dst, src);
357 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100358 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100359 case DataType::Type::kInt8:
360 case DataType::Type::kUint16:
361 case DataType::Type::kInt16:
362 case DataType::Type::kInt32:
363 case DataType::Type::kInt64:
364 case DataType::Type::kFloat32:
365 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200366 DCHECK_LE(2u, instruction->GetVectorLength());
367 DCHECK_LE(instruction->GetVectorLength(), 16u);
368 __ NorV(dst, src, src); // lanes do not matter
369 break;
370 default:
371 LOG(FATAL) << "Unsupported SIMD type";
372 UNREACHABLE();
373 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800374}
375
376// Helper to set up locations for vector binary operations.
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100377static void CreateVecBinOpLocations(ArenaAllocator* allocator, HVecBinaryOperation* instruction) {
378 LocationSummary* locations = new (allocator) LocationSummary(instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800379 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100380 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100381 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100382 case DataType::Type::kInt8:
383 case DataType::Type::kUint16:
384 case DataType::Type::kInt16:
385 case DataType::Type::kInt32:
386 case DataType::Type::kInt64:
387 case DataType::Type::kFloat32:
388 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200389 locations->SetInAt(0, Location::RequiresFpuRegister());
390 locations->SetInAt(1, Location::RequiresFpuRegister());
391 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Aart Bikf8f5a162017-02-06 15:35:29 -0800392 break;
393 default:
394 LOG(FATAL) << "Unsupported SIMD type";
395 UNREACHABLE();
396 }
397}
398
399void LocationsBuilderMIPS64::VisitVecAdd(HVecAdd* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100400 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800401}
402
403void InstructionCodeGeneratorMIPS64::VisitVecAdd(HVecAdd* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200404 LocationSummary* locations = instruction->GetLocations();
405 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
406 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
407 VectorRegister dst = VectorRegisterFrom(locations->Out());
408 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100409 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100410 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200411 DCHECK_EQ(16u, instruction->GetVectorLength());
412 __ AddvB(dst, lhs, rhs);
413 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100414 case DataType::Type::kUint16:
415 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200416 DCHECK_EQ(8u, instruction->GetVectorLength());
417 __ AddvH(dst, lhs, rhs);
418 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100419 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200420 DCHECK_EQ(4u, instruction->GetVectorLength());
421 __ AddvW(dst, lhs, rhs);
422 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100423 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200424 DCHECK_EQ(2u, instruction->GetVectorLength());
425 __ AddvD(dst, lhs, rhs);
426 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100427 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200428 DCHECK_EQ(4u, instruction->GetVectorLength());
429 __ FaddW(dst, lhs, rhs);
430 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100431 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200432 DCHECK_EQ(2u, instruction->GetVectorLength());
433 __ FaddD(dst, lhs, rhs);
434 break;
435 default:
436 LOG(FATAL) << "Unsupported SIMD type";
437 UNREACHABLE();
438 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800439}
440
Aart Bikf3e61ee2017-04-12 17:09:20 -0700441void LocationsBuilderMIPS64::VisitVecHalvingAdd(HVecHalvingAdd* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100442 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700443}
444
445void InstructionCodeGeneratorMIPS64::VisitVecHalvingAdd(HVecHalvingAdd* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200446 LocationSummary* locations = instruction->GetLocations();
447 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
448 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
449 VectorRegister dst = VectorRegisterFrom(locations->Out());
450 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100451 case DataType::Type::kUint8:
452 DCHECK_EQ(16u, instruction->GetVectorLength());
453 instruction->IsRounded()
454 ? __ Aver_uB(dst, lhs, rhs)
455 : __ Ave_uB(dst, lhs, rhs);
456 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100457 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200458 DCHECK_EQ(16u, instruction->GetVectorLength());
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100459 instruction->IsRounded()
460 ? __ Aver_sB(dst, lhs, rhs)
461 : __ Ave_sB(dst, lhs, rhs);
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200462 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100463 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100464 DCHECK_EQ(8u, instruction->GetVectorLength());
465 instruction->IsRounded()
466 ? __ Aver_uH(dst, lhs, rhs)
467 : __ Ave_uH(dst, lhs, rhs);
468 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100469 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200470 DCHECK_EQ(8u, instruction->GetVectorLength());
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100471 instruction->IsRounded()
472 ? __ Aver_sH(dst, lhs, rhs)
473 : __ Ave_sH(dst, lhs, rhs);
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200474 break;
475 default:
476 LOG(FATAL) << "Unsupported SIMD type";
477 UNREACHABLE();
478 }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700479}
480
Aart Bikf8f5a162017-02-06 15:35:29 -0800481void LocationsBuilderMIPS64::VisitVecSub(HVecSub* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100482 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800483}
484
485void InstructionCodeGeneratorMIPS64::VisitVecSub(HVecSub* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200486 LocationSummary* locations = instruction->GetLocations();
487 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
488 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
489 VectorRegister dst = VectorRegisterFrom(locations->Out());
490 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100491 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100492 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200493 DCHECK_EQ(16u, instruction->GetVectorLength());
494 __ SubvB(dst, lhs, rhs);
495 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100496 case DataType::Type::kUint16:
497 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200498 DCHECK_EQ(8u, instruction->GetVectorLength());
499 __ SubvH(dst, lhs, rhs);
500 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100501 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200502 DCHECK_EQ(4u, instruction->GetVectorLength());
503 __ SubvW(dst, lhs, rhs);
504 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100505 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200506 DCHECK_EQ(2u, instruction->GetVectorLength());
507 __ SubvD(dst, lhs, rhs);
508 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100509 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200510 DCHECK_EQ(4u, instruction->GetVectorLength());
511 __ FsubW(dst, lhs, rhs);
512 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100513 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200514 DCHECK_EQ(2u, instruction->GetVectorLength());
515 __ FsubD(dst, lhs, rhs);
516 break;
517 default:
518 LOG(FATAL) << "Unsupported SIMD type";
519 UNREACHABLE();
520 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800521}
522
523void LocationsBuilderMIPS64::VisitVecMul(HVecMul* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100524 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800525}
526
527void InstructionCodeGeneratorMIPS64::VisitVecMul(HVecMul* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200528 LocationSummary* locations = instruction->GetLocations();
529 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
530 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
531 VectorRegister dst = VectorRegisterFrom(locations->Out());
532 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100533 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100534 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200535 DCHECK_EQ(16u, instruction->GetVectorLength());
536 __ MulvB(dst, lhs, rhs);
537 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100538 case DataType::Type::kUint16:
539 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200540 DCHECK_EQ(8u, instruction->GetVectorLength());
541 __ MulvH(dst, lhs, rhs);
542 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100543 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200544 DCHECK_EQ(4u, instruction->GetVectorLength());
545 __ MulvW(dst, lhs, rhs);
546 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100547 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200548 DCHECK_EQ(2u, instruction->GetVectorLength());
549 __ MulvD(dst, lhs, rhs);
550 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100551 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200552 DCHECK_EQ(4u, instruction->GetVectorLength());
553 __ FmulW(dst, lhs, rhs);
554 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100555 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200556 DCHECK_EQ(2u, instruction->GetVectorLength());
557 __ FmulD(dst, lhs, rhs);
558 break;
559 default:
560 LOG(FATAL) << "Unsupported SIMD type";
561 UNREACHABLE();
562 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800563}
564
565void LocationsBuilderMIPS64::VisitVecDiv(HVecDiv* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100566 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800567}
568
569void InstructionCodeGeneratorMIPS64::VisitVecDiv(HVecDiv* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200570 LocationSummary* locations = instruction->GetLocations();
571 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
572 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
573 VectorRegister dst = VectorRegisterFrom(locations->Out());
574 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100575 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200576 DCHECK_EQ(4u, instruction->GetVectorLength());
577 __ FdivW(dst, lhs, rhs);
578 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100579 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200580 DCHECK_EQ(2u, instruction->GetVectorLength());
581 __ FdivD(dst, lhs, rhs);
582 break;
583 default:
584 LOG(FATAL) << "Unsupported SIMD type";
585 UNREACHABLE();
586 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800587}
588
Aart Bikf3e61ee2017-04-12 17:09:20 -0700589void LocationsBuilderMIPS64::VisitVecMin(HVecMin* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100590 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700591}
592
593void InstructionCodeGeneratorMIPS64::VisitVecMin(HVecMin* instruction) {
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200594 LocationSummary* locations = instruction->GetLocations();
595 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
596 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
597 VectorRegister dst = VectorRegisterFrom(locations->Out());
598 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100599 case DataType::Type::kUint8:
600 DCHECK_EQ(16u, instruction->GetVectorLength());
601 __ Min_uB(dst, lhs, rhs);
602 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100603 case DataType::Type::kInt8:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200604 DCHECK_EQ(16u, instruction->GetVectorLength());
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100605 __ Min_sB(dst, lhs, rhs);
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200606 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100607 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100608 DCHECK_EQ(8u, instruction->GetVectorLength());
609 __ Min_uH(dst, lhs, rhs);
610 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100611 case DataType::Type::kInt16:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200612 DCHECK_EQ(8u, instruction->GetVectorLength());
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100613 __ Min_sH(dst, lhs, rhs);
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200614 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100615 case DataType::Type::kInt32:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200616 DCHECK_EQ(4u, instruction->GetVectorLength());
617 if (instruction->IsUnsigned()) {
618 __ Min_uW(dst, lhs, rhs);
619 } else {
620 __ Min_sW(dst, lhs, rhs);
621 }
622 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100623 case DataType::Type::kInt64:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200624 DCHECK_EQ(2u, instruction->GetVectorLength());
625 if (instruction->IsUnsigned()) {
626 __ Min_uD(dst, lhs, rhs);
627 } else {
628 __ Min_sD(dst, lhs, rhs);
629 }
630 break;
631 // When one of arguments is NaN, fmin.df returns other argument, but Java expects a NaN value.
632 // TODO: Fix min(x, NaN) cases for float and double.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100633 case DataType::Type::kFloat32:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200634 DCHECK_EQ(4u, instruction->GetVectorLength());
635 DCHECK(!instruction->IsUnsigned());
636 __ FminW(dst, lhs, rhs);
637 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100638 case DataType::Type::kFloat64:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200639 DCHECK_EQ(2u, instruction->GetVectorLength());
640 DCHECK(!instruction->IsUnsigned());
641 __ FminD(dst, lhs, rhs);
642 break;
643 default:
644 LOG(FATAL) << "Unsupported SIMD type";
645 UNREACHABLE();
646 }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700647}
648
649void LocationsBuilderMIPS64::VisitVecMax(HVecMax* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100650 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700651}
652
653void InstructionCodeGeneratorMIPS64::VisitVecMax(HVecMax* instruction) {
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200654 LocationSummary* locations = instruction->GetLocations();
655 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
656 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
657 VectorRegister dst = VectorRegisterFrom(locations->Out());
658 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100659 case DataType::Type::kUint8:
660 DCHECK_EQ(16u, instruction->GetVectorLength());
661 __ Max_uB(dst, lhs, rhs);
662 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100663 case DataType::Type::kInt8:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200664 DCHECK_EQ(16u, instruction->GetVectorLength());
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100665 __ Max_sB(dst, lhs, rhs);
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200666 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100667 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100668 DCHECK_EQ(8u, instruction->GetVectorLength());
669 __ Max_uH(dst, lhs, rhs);
670 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100671 case DataType::Type::kInt16:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200672 DCHECK_EQ(8u, instruction->GetVectorLength());
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100673 __ Max_sH(dst, lhs, rhs);
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200674 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100675 case DataType::Type::kInt32:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200676 DCHECK_EQ(4u, instruction->GetVectorLength());
677 if (instruction->IsUnsigned()) {
678 __ Max_uW(dst, lhs, rhs);
679 } else {
680 __ Max_sW(dst, lhs, rhs);
681 }
682 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100683 case DataType::Type::kInt64:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200684 DCHECK_EQ(2u, instruction->GetVectorLength());
685 if (instruction->IsUnsigned()) {
686 __ Max_uD(dst, lhs, rhs);
687 } else {
688 __ Max_sD(dst, lhs, rhs);
689 }
690 break;
691 // When one of arguments is NaN, fmax.df returns other argument, but Java expects a NaN value.
692 // TODO: Fix max(x, NaN) cases for float and double.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100693 case DataType::Type::kFloat32:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200694 DCHECK_EQ(4u, instruction->GetVectorLength());
695 DCHECK(!instruction->IsUnsigned());
696 __ FmaxW(dst, lhs, rhs);
697 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100698 case DataType::Type::kFloat64:
Goran Jakovljevic8fea1e12017-06-06 13:28:42 +0200699 DCHECK_EQ(2u, instruction->GetVectorLength());
700 DCHECK(!instruction->IsUnsigned());
701 __ FmaxD(dst, lhs, rhs);
702 break;
703 default:
704 LOG(FATAL) << "Unsupported SIMD type";
705 UNREACHABLE();
706 }
Aart Bikf3e61ee2017-04-12 17:09:20 -0700707}
708
Aart Bikf8f5a162017-02-06 15:35:29 -0800709void LocationsBuilderMIPS64::VisitVecAnd(HVecAnd* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100710 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800711}
712
713void InstructionCodeGeneratorMIPS64::VisitVecAnd(HVecAnd* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200714 LocationSummary* locations = instruction->GetLocations();
715 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
716 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
717 VectorRegister dst = VectorRegisterFrom(locations->Out());
718 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100719 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100720 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100721 case DataType::Type::kInt8:
722 case DataType::Type::kUint16:
723 case DataType::Type::kInt16:
724 case DataType::Type::kInt32:
725 case DataType::Type::kInt64:
726 case DataType::Type::kFloat32:
727 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200728 DCHECK_LE(2u, instruction->GetVectorLength());
729 DCHECK_LE(instruction->GetVectorLength(), 16u);
730 __ AndV(dst, lhs, rhs); // lanes do not matter
731 break;
732 default:
733 LOG(FATAL) << "Unsupported SIMD type";
734 UNREACHABLE();
735 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800736}
737
738void LocationsBuilderMIPS64::VisitVecAndNot(HVecAndNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100739 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800740}
741
742void InstructionCodeGeneratorMIPS64::VisitVecAndNot(HVecAndNot* instruction) {
743 LOG(FATAL) << "No SIMD for " << instruction->GetId();
744}
745
746void LocationsBuilderMIPS64::VisitVecOr(HVecOr* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100747 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800748}
749
750void InstructionCodeGeneratorMIPS64::VisitVecOr(HVecOr* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200751 LocationSummary* locations = instruction->GetLocations();
752 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
753 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
754 VectorRegister dst = VectorRegisterFrom(locations->Out());
755 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100756 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100757 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100758 case DataType::Type::kInt8:
759 case DataType::Type::kUint16:
760 case DataType::Type::kInt16:
761 case DataType::Type::kInt32:
762 case DataType::Type::kInt64:
763 case DataType::Type::kFloat32:
764 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200765 DCHECK_LE(2u, instruction->GetVectorLength());
766 DCHECK_LE(instruction->GetVectorLength(), 16u);
767 __ OrV(dst, lhs, rhs); // lanes do not matter
768 break;
769 default:
770 LOG(FATAL) << "Unsupported SIMD type";
771 UNREACHABLE();
772 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800773}
774
775void LocationsBuilderMIPS64::VisitVecXor(HVecXor* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100776 CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800777}
778
779void InstructionCodeGeneratorMIPS64::VisitVecXor(HVecXor* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200780 LocationSummary* locations = instruction->GetLocations();
781 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
782 VectorRegister rhs = VectorRegisterFrom(locations->InAt(1));
783 VectorRegister dst = VectorRegisterFrom(locations->Out());
784 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100785 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100786 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100787 case DataType::Type::kInt8:
788 case DataType::Type::kUint16:
789 case DataType::Type::kInt16:
790 case DataType::Type::kInt32:
791 case DataType::Type::kInt64:
792 case DataType::Type::kFloat32:
793 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200794 DCHECK_LE(2u, instruction->GetVectorLength());
795 DCHECK_LE(instruction->GetVectorLength(), 16u);
796 __ XorV(dst, lhs, rhs); // lanes do not matter
797 break;
798 default:
799 LOG(FATAL) << "Unsupported SIMD type";
800 UNREACHABLE();
801 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800802}
803
804// Helper to set up locations for vector shift operations.
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100805static void CreateVecShiftLocations(ArenaAllocator* allocator, HVecBinaryOperation* instruction) {
806 LocationSummary* locations = new (allocator) LocationSummary(instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800807 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100808 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100809 case DataType::Type::kInt8:
810 case DataType::Type::kUint16:
811 case DataType::Type::kInt16:
812 case DataType::Type::kInt32:
813 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200814 locations->SetInAt(0, Location::RequiresFpuRegister());
815 locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant()));
816 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Aart Bikf8f5a162017-02-06 15:35:29 -0800817 break;
818 default:
819 LOG(FATAL) << "Unsupported SIMD type";
820 UNREACHABLE();
821 }
822}
823
824void LocationsBuilderMIPS64::VisitVecShl(HVecShl* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100825 CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800826}
827
828void InstructionCodeGeneratorMIPS64::VisitVecShl(HVecShl* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200829 LocationSummary* locations = instruction->GetLocations();
830 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
831 VectorRegister dst = VectorRegisterFrom(locations->Out());
832 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
833 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100834 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100835 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200836 DCHECK_EQ(16u, instruction->GetVectorLength());
837 __ SlliB(dst, lhs, value);
838 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100839 case DataType::Type::kUint16:
840 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200841 DCHECK_EQ(8u, instruction->GetVectorLength());
842 __ SlliH(dst, lhs, value);
843 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100844 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200845 DCHECK_EQ(4u, instruction->GetVectorLength());
846 __ SlliW(dst, lhs, value);
847 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100848 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200849 DCHECK_EQ(2u, instruction->GetVectorLength());
850 __ SlliD(dst, lhs, value);
851 break;
852 default:
853 LOG(FATAL) << "Unsupported SIMD type";
854 UNREACHABLE();
855 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800856}
857
858void LocationsBuilderMIPS64::VisitVecShr(HVecShr* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100859 CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800860}
861
862void InstructionCodeGeneratorMIPS64::VisitVecShr(HVecShr* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200863 LocationSummary* locations = instruction->GetLocations();
864 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
865 VectorRegister dst = VectorRegisterFrom(locations->Out());
866 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
867 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100868 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100869 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200870 DCHECK_EQ(16u, instruction->GetVectorLength());
871 __ SraiB(dst, lhs, value);
872 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100873 case DataType::Type::kUint16:
874 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200875 DCHECK_EQ(8u, instruction->GetVectorLength());
876 __ SraiH(dst, lhs, value);
877 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100878 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200879 DCHECK_EQ(4u, instruction->GetVectorLength());
880 __ SraiW(dst, lhs, value);
881 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100882 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200883 DCHECK_EQ(2u, instruction->GetVectorLength());
884 __ SraiD(dst, lhs, value);
885 break;
886 default:
887 LOG(FATAL) << "Unsupported SIMD type";
888 UNREACHABLE();
889 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800890}
891
892void LocationsBuilderMIPS64::VisitVecUShr(HVecUShr* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100893 CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikf8f5a162017-02-06 15:35:29 -0800894}
895
896void InstructionCodeGeneratorMIPS64::VisitVecUShr(HVecUShr* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200897 LocationSummary* locations = instruction->GetLocations();
898 VectorRegister lhs = VectorRegisterFrom(locations->InAt(0));
899 VectorRegister dst = VectorRegisterFrom(locations->Out());
900 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
901 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100902 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100903 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200904 DCHECK_EQ(16u, instruction->GetVectorLength());
905 __ SrliB(dst, lhs, value);
906 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100907 case DataType::Type::kUint16:
908 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200909 DCHECK_EQ(8u, instruction->GetVectorLength());
910 __ SrliH(dst, lhs, value);
911 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100912 case DataType::Type::kInt32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200913 DCHECK_EQ(4u, instruction->GetVectorLength());
914 __ SrliW(dst, lhs, value);
915 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100916 case DataType::Type::kInt64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200917 DCHECK_EQ(2u, instruction->GetVectorLength());
918 __ SrliD(dst, lhs, value);
919 break;
920 default:
921 LOG(FATAL) << "Unsupported SIMD type";
922 UNREACHABLE();
923 }
Aart Bikf8f5a162017-02-06 15:35:29 -0800924}
925
Aart Bik0148de42017-09-05 09:25:01 -0700926void LocationsBuilderMIPS64::VisitVecSetScalars(HVecSetScalars* instruction) {
Lena Djokice434c4f2017-10-23 16:40:22 +0200927 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
928
929 DCHECK_EQ(1u, instruction->InputCount()); // only one input currently implemented
930
931 HInstruction* input = instruction->InputAt(0);
932 bool is_zero = IsZeroBitPattern(input);
933
934 switch (instruction->GetPackedType()) {
935 case DataType::Type::kBool:
936 case DataType::Type::kUint8:
937 case DataType::Type::kInt8:
938 case DataType::Type::kUint16:
939 case DataType::Type::kInt16:
940 case DataType::Type::kInt32:
941 case DataType::Type::kInt64:
942 locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant())
943 : Location::RequiresRegister());
944 locations->SetOut(Location::RequiresFpuRegister());
945 break;
946 case DataType::Type::kFloat32:
947 case DataType::Type::kFloat64:
948 locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant())
949 : Location::RequiresFpuRegister());
950 locations->SetOut(Location::RequiresFpuRegister());
951 break;
952 default:
953 LOG(FATAL) << "Unsupported SIMD type";
954 UNREACHABLE();
955 }
Aart Bik0148de42017-09-05 09:25:01 -0700956}
957
958void InstructionCodeGeneratorMIPS64::VisitVecSetScalars(HVecSetScalars* instruction) {
Lena Djokice434c4f2017-10-23 16:40:22 +0200959 LocationSummary* locations = instruction->GetLocations();
960 VectorRegister dst = VectorRegisterFrom(locations->Out());
961
962 DCHECK_EQ(1u, instruction->InputCount()); // only one input currently implemented
963
964 // Zero out all other elements first.
965 __ FillW(dst, ZERO);
966
967 // Shorthand for any type of zero.
968 if (IsZeroBitPattern(instruction->InputAt(0))) {
969 return;
970 }
971
972 // Set required elements.
973 switch (instruction->GetPackedType()) {
974 case DataType::Type::kBool:
975 case DataType::Type::kUint8:
976 case DataType::Type::kInt8:
977 DCHECK_EQ(16u, instruction->GetVectorLength());
978 __ InsertB(dst, locations->InAt(0).AsRegister<GpuRegister>(), 0);
979 break;
980 case DataType::Type::kUint16:
981 case DataType::Type::kInt16:
982 DCHECK_EQ(8u, instruction->GetVectorLength());
983 __ InsertH(dst, locations->InAt(0).AsRegister<GpuRegister>(), 0);
984 break;
985 case DataType::Type::kInt32:
986 DCHECK_EQ(4u, instruction->GetVectorLength());
987 __ InsertW(dst, locations->InAt(0).AsRegister<GpuRegister>(), 0);
988 break;
989 case DataType::Type::kInt64:
990 DCHECK_EQ(2u, instruction->GetVectorLength());
991 __ InsertD(dst, locations->InAt(0).AsRegister<GpuRegister>(), 0);
992 break;
993 default:
994 LOG(FATAL) << "Unsupported SIMD type";
995 UNREACHABLE();
996 }
Aart Bik0148de42017-09-05 09:25:01 -0700997}
998
Aart Bikdbbac8f2017-09-01 13:06:08 -0700999// Helper to set up locations for vector accumulations.
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001000static void CreateVecAccumLocations(ArenaAllocator* allocator, HVecOperation* instruction) {
1001 LocationSummary* locations = new (allocator) LocationSummary(instruction);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001002 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001003 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001004 case DataType::Type::kInt8:
1005 case DataType::Type::kUint16:
1006 case DataType::Type::kInt16:
1007 case DataType::Type::kInt32:
1008 case DataType::Type::kInt64:
Aart Bikdbbac8f2017-09-01 13:06:08 -07001009 locations->SetInAt(0, Location::RequiresFpuRegister());
1010 locations->SetInAt(1, Location::RequiresFpuRegister());
1011 locations->SetInAt(2, Location::RequiresFpuRegister());
Lena Djokicbc5460b2017-07-20 16:07:36 +02001012 locations->SetOut(Location::SameAsFirstInput());
1013 break;
1014 default:
1015 LOG(FATAL) << "Unsupported SIMD type";
1016 UNREACHABLE();
1017 }
Artem Serovf34dd202017-04-10 17:41:46 +01001018}
1019
Aart Bikdbbac8f2017-09-01 13:06:08 -07001020void LocationsBuilderMIPS64::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01001021 CreateVecAccumLocations(GetGraph()->GetAllocator(), instruction);
Aart Bikdbbac8f2017-09-01 13:06:08 -07001022}
1023
1024void InstructionCodeGeneratorMIPS64::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) {
1025 LocationSummary* locations = instruction->GetLocations();
1026 VectorRegister acc = VectorRegisterFrom(locations->InAt(0));
1027 VectorRegister left = VectorRegisterFrom(locations->InAt(1));
1028 VectorRegister right = VectorRegisterFrom(locations->InAt(2));
1029 switch (instruction->GetPackedType()) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001030 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001031 case DataType::Type::kInt8:
Aart Bikdbbac8f2017-09-01 13:06:08 -07001032 DCHECK_EQ(16u, instruction->GetVectorLength());
1033 if (instruction->GetOpKind() == HInstruction::kAdd) {
Lena Djokicbc5460b2017-07-20 16:07:36 +02001034 __ MaddvB(acc, left, right);
1035 } else {
1036 __ MsubvB(acc, left, right);
1037 }
1038 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001039 case DataType::Type::kUint16:
1040 case DataType::Type::kInt16:
Aart Bikdbbac8f2017-09-01 13:06:08 -07001041 DCHECK_EQ(8u, instruction->GetVectorLength());
1042 if (instruction->GetOpKind() == HInstruction::kAdd) {
Lena Djokicbc5460b2017-07-20 16:07:36 +02001043 __ MaddvH(acc, left, right);
1044 } else {
1045 __ MsubvH(acc, left, right);
1046 }
1047 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001048 case DataType::Type::kInt32:
Aart Bikdbbac8f2017-09-01 13:06:08 -07001049 DCHECK_EQ(4u, instruction->GetVectorLength());
1050 if (instruction->GetOpKind() == HInstruction::kAdd) {
Lena Djokicbc5460b2017-07-20 16:07:36 +02001051 __ MaddvW(acc, left, right);
1052 } else {
1053 __ MsubvW(acc, left, right);
1054 }
1055 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001056 case DataType::Type::kInt64:
Aart Bikdbbac8f2017-09-01 13:06:08 -07001057 DCHECK_EQ(2u, instruction->GetVectorLength());
1058 if (instruction->GetOpKind() == HInstruction::kAdd) {
Lena Djokicbc5460b2017-07-20 16:07:36 +02001059 __ MaddvD(acc, left, right);
1060 } else {
1061 __ MsubvD(acc, left, right);
1062 }
1063 break;
1064 default:
1065 LOG(FATAL) << "Unsupported SIMD type";
1066 UNREACHABLE();
1067 }
Artem Serovf34dd202017-04-10 17:41:46 +01001068}
1069
Aart Bikdbbac8f2017-09-01 13:06:08 -07001070void LocationsBuilderMIPS64::VisitVecSADAccumulate(HVecSADAccumulate* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01001071 CreateVecAccumLocations(GetGraph()->GetAllocator(), instruction);
Lena Djokic38e380b2017-10-30 16:17:10 +01001072 LocationSummary* locations = instruction->GetLocations();
1073 // All conversions require at least one temporary register.
1074 locations->AddTemp(Location::RequiresFpuRegister());
1075 // Some conversions require a second temporary register.
1076 HVecOperation* a = instruction->InputAt(1)->AsVecOperation();
1077 HVecOperation* b = instruction->InputAt(2)->AsVecOperation();
1078 DCHECK_EQ(HVecOperation::ToSignedType(a->GetPackedType()),
1079 HVecOperation::ToSignedType(b->GetPackedType()));
1080 switch (a->GetPackedType()) {
1081 case DataType::Type::kInt32:
1082 if (instruction->GetPackedType() == DataType::Type::kInt32) {
1083 break;
1084 }
1085 FALLTHROUGH_INTENDED;
1086 case DataType::Type::kUint8:
1087 case DataType::Type::kInt8:
1088 case DataType::Type::kUint16:
1089 case DataType::Type::kInt16:
1090 locations->AddTemp(Location::RequiresFpuRegister());
1091 break;
1092 default:
1093 break;
1094 }
Aart Bikdbbac8f2017-09-01 13:06:08 -07001095}
1096
1097void InstructionCodeGeneratorMIPS64::VisitVecSADAccumulate(HVecSADAccumulate* instruction) {
Lena Djokic38e380b2017-10-30 16:17:10 +01001098 LocationSummary* locations = instruction->GetLocations();
1099 VectorRegister acc = VectorRegisterFrom(locations->InAt(0));
1100 VectorRegister left = VectorRegisterFrom(locations->InAt(1));
1101 VectorRegister right = VectorRegisterFrom(locations->InAt(2));
1102 VectorRegister tmp = static_cast<VectorRegister>(FTMP);
1103 VectorRegister tmp1 = VectorRegisterFrom(locations->GetTemp(0));
1104
1105 DCHECK(locations->InAt(0).Equals(locations->Out()));
1106
1107 // Handle all feasible acc_T += sad(a_S, b_S) type combinations (T x S).
1108 HVecOperation* a = instruction->InputAt(1)->AsVecOperation();
1109 HVecOperation* b = instruction->InputAt(2)->AsVecOperation();
1110 DCHECK_EQ(HVecOperation::ToSignedType(a->GetPackedType()),
1111 HVecOperation::ToSignedType(b->GetPackedType()));
1112 switch (a->GetPackedType()) {
1113 case DataType::Type::kUint8:
1114 case DataType::Type::kInt8:
1115 DCHECK_EQ(16u, a->GetVectorLength());
1116 switch (instruction->GetPackedType()) {
1117 case DataType::Type::kUint16:
1118 case DataType::Type::kInt16: {
1119 DCHECK_EQ(8u, instruction->GetVectorLength());
1120 VectorRegister tmp2 = VectorRegisterFrom(locations->GetTemp(1));
1121 __ FillB(tmp, ZERO);
1122 __ Hadd_sH(tmp1, left, tmp);
1123 __ Hadd_sH(tmp2, right, tmp);
1124 __ Asub_sH(tmp1, tmp1, tmp2);
1125 __ AddvH(acc, acc, tmp1);
1126 __ Hadd_sH(tmp1, tmp, left);
1127 __ Hadd_sH(tmp2, tmp, right);
1128 __ Asub_sH(tmp1, tmp1, tmp2);
1129 __ AddvH(acc, acc, tmp1);
1130 break;
1131 }
1132 case DataType::Type::kInt32: {
1133 DCHECK_EQ(4u, instruction->GetVectorLength());
1134 VectorRegister tmp2 = VectorRegisterFrom(locations->GetTemp(1));
1135 __ FillB(tmp, ZERO);
1136 __ Hadd_sH(tmp1, left, tmp);
1137 __ Hadd_sH(tmp2, right, tmp);
1138 __ Asub_sH(tmp1, tmp1, tmp2);
1139 __ Hadd_sW(tmp1, tmp1, tmp1);
1140 __ AddvW(acc, acc, tmp1);
1141 __ Hadd_sH(tmp1, tmp, left);
1142 __ Hadd_sH(tmp2, tmp, right);
1143 __ Asub_sH(tmp1, tmp1, tmp2);
1144 __ Hadd_sW(tmp1, tmp1, tmp1);
1145 __ AddvW(acc, acc, tmp1);
1146 break;
1147 }
1148 case DataType::Type::kInt64: {
1149 DCHECK_EQ(2u, instruction->GetVectorLength());
1150 VectorRegister tmp2 = VectorRegisterFrom(locations->GetTemp(1));
1151 __ FillB(tmp, ZERO);
1152 __ Hadd_sH(tmp1, left, tmp);
1153 __ Hadd_sH(tmp2, right, tmp);
1154 __ Asub_sH(tmp1, tmp1, tmp2);
1155 __ Hadd_sW(tmp1, tmp1, tmp1);
1156 __ Hadd_sD(tmp1, tmp1, tmp1);
1157 __ AddvD(acc, acc, tmp1);
1158 __ Hadd_sH(tmp1, tmp, left);
1159 __ Hadd_sH(tmp2, tmp, right);
1160 __ Asub_sH(tmp1, tmp1, tmp2);
1161 __ Hadd_sW(tmp1, tmp1, tmp1);
1162 __ Hadd_sD(tmp1, tmp1, tmp1);
1163 __ AddvD(acc, acc, tmp1);
1164 break;
1165 }
1166 default:
1167 LOG(FATAL) << "Unsupported SIMD type";
1168 UNREACHABLE();
1169 }
1170 break;
1171 case DataType::Type::kUint16:
1172 case DataType::Type::kInt16:
1173 DCHECK_EQ(8u, a->GetVectorLength());
1174 switch (instruction->GetPackedType()) {
1175 case DataType::Type::kInt32: {
1176 DCHECK_EQ(4u, instruction->GetVectorLength());
1177 VectorRegister tmp2 = VectorRegisterFrom(locations->GetTemp(1));
1178 __ FillH(tmp, ZERO);
1179 __ Hadd_sW(tmp1, left, tmp);
1180 __ Hadd_sW(tmp2, right, tmp);
1181 __ Asub_sW(tmp1, tmp1, tmp2);
1182 __ AddvW(acc, acc, tmp1);
1183 __ Hadd_sW(tmp1, tmp, left);
1184 __ Hadd_sW(tmp2, tmp, right);
1185 __ Asub_sW(tmp1, tmp1, tmp2);
1186 __ AddvW(acc, acc, tmp1);
1187 break;
1188 }
1189 case DataType::Type::kInt64: {
1190 DCHECK_EQ(2u, instruction->GetVectorLength());
1191 VectorRegister tmp2 = VectorRegisterFrom(locations->GetTemp(1));
1192 __ FillH(tmp, ZERO);
1193 __ Hadd_sW(tmp1, left, tmp);
1194 __ Hadd_sW(tmp2, right, tmp);
1195 __ Asub_sW(tmp1, tmp1, tmp2);
1196 __ Hadd_sD(tmp1, tmp1, tmp1);
1197 __ AddvD(acc, acc, tmp1);
1198 __ Hadd_sW(tmp1, tmp, left);
1199 __ Hadd_sW(tmp2, tmp, right);
1200 __ Asub_sW(tmp1, tmp1, tmp2);
1201 __ Hadd_sD(tmp1, tmp1, tmp1);
1202 __ AddvD(acc, acc, tmp1);
1203 break;
1204 }
1205 default:
1206 LOG(FATAL) << "Unsupported SIMD type";
1207 UNREACHABLE();
1208 }
1209 break;
1210 case DataType::Type::kInt32:
1211 DCHECK_EQ(4u, a->GetVectorLength());
1212 switch (instruction->GetPackedType()) {
1213 case DataType::Type::kInt32: {
1214 DCHECK_EQ(4u, instruction->GetVectorLength());
1215 __ FillW(tmp, ZERO);
1216 __ SubvW(tmp1, left, right);
1217 __ Add_aW(tmp1, tmp1, tmp);
1218 __ AddvW(acc, acc, tmp1);
1219 break;
1220 }
1221 case DataType::Type::kInt64: {
1222 DCHECK_EQ(2u, instruction->GetVectorLength());
1223 VectorRegister tmp2 = VectorRegisterFrom(locations->GetTemp(1));
1224 __ FillW(tmp, ZERO);
1225 __ Hadd_sD(tmp1, left, tmp);
1226 __ Hadd_sD(tmp2, right, tmp);
1227 __ Asub_sD(tmp1, tmp1, tmp2);
1228 __ AddvD(acc, acc, tmp1);
1229 __ Hadd_sD(tmp1, tmp, left);
1230 __ Hadd_sD(tmp2, tmp, right);
1231 __ Asub_sD(tmp1, tmp1, tmp2);
1232 __ AddvD(acc, acc, tmp1);
1233 break;
1234 }
1235 default:
1236 LOG(FATAL) << "Unsupported SIMD type";
1237 UNREACHABLE();
1238 }
1239 break;
1240 case DataType::Type::kInt64: {
1241 DCHECK_EQ(2u, a->GetVectorLength());
1242 switch (instruction->GetPackedType()) {
1243 case DataType::Type::kInt64: {
1244 DCHECK_EQ(2u, instruction->GetVectorLength());
1245 __ FillD(tmp, ZERO);
1246 __ SubvD(tmp1, left, right);
1247 __ Add_aD(tmp1, tmp1, tmp);
1248 __ AddvD(acc, acc, tmp1);
1249 break;
1250 }
1251 default:
1252 LOG(FATAL) << "Unsupported SIMD type";
1253 UNREACHABLE();
1254 }
1255 break;
1256 }
1257 default:
1258 LOG(FATAL) << "Unsupported SIMD type";
1259 UNREACHABLE();
1260 }
Aart Bikdbbac8f2017-09-01 13:06:08 -07001261}
1262
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001263// Helper to set up locations for vector memory operations.
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001264static void CreateVecMemLocations(ArenaAllocator* allocator,
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001265 HVecMemoryOperation* instruction,
1266 bool is_load) {
Vladimir Markoe764d2e2017-10-05 14:35:55 +01001267 LocationSummary* locations = new (allocator) LocationSummary(instruction);
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001268 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001269 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001270 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001271 case DataType::Type::kInt8:
1272 case DataType::Type::kUint16:
1273 case DataType::Type::kInt16:
1274 case DataType::Type::kInt32:
1275 case DataType::Type::kInt64:
1276 case DataType::Type::kFloat32:
1277 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001278 locations->SetInAt(0, Location::RequiresRegister());
1279 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1280 if (is_load) {
1281 locations->SetOut(Location::RequiresFpuRegister());
1282 } else {
1283 locations->SetInAt(2, Location::RequiresFpuRegister());
1284 }
1285 break;
1286 default:
1287 LOG(FATAL) << "Unsupported SIMD type";
1288 UNREACHABLE();
1289 }
1290}
1291
1292// Helper to prepare register and offset for vector memory operations. Returns the offset and sets
1293// the output parameter adjusted_base to the original base or to a reserved temporary register (AT).
1294int32_t InstructionCodeGeneratorMIPS64::VecAddress(LocationSummary* locations,
1295 size_t size,
1296 /* out */ GpuRegister* adjusted_base) {
1297 GpuRegister base = locations->InAt(0).AsRegister<GpuRegister>();
1298 Location index = locations->InAt(1);
1299 int scale = TIMES_1;
1300 switch (size) {
1301 case 2: scale = TIMES_2; break;
1302 case 4: scale = TIMES_4; break;
1303 case 8: scale = TIMES_8; break;
1304 default: break;
1305 }
1306 int32_t offset = mirror::Array::DataOffset(size).Int32Value();
1307
1308 if (index.IsConstant()) {
1309 offset += index.GetConstant()->AsIntConstant()->GetValue() << scale;
1310 __ AdjustBaseOffsetAndElementSizeShift(base, offset, scale);
1311 *adjusted_base = base;
1312 } else {
1313 GpuRegister index_reg = index.AsRegister<GpuRegister>();
1314 if (scale != TIMES_1) {
1315 __ Dlsa(AT, index_reg, base, scale);
1316 } else {
1317 __ Daddu(AT, base, index_reg);
1318 }
1319 *adjusted_base = AT;
1320 }
1321 return offset;
1322}
1323
Aart Bikf8f5a162017-02-06 15:35:29 -08001324void LocationsBuilderMIPS64::VisitVecLoad(HVecLoad* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01001325 CreateVecMemLocations(GetGraph()->GetAllocator(), instruction, /* is_load */ true);
Aart Bikf8f5a162017-02-06 15:35:29 -08001326}
1327
1328void InstructionCodeGeneratorMIPS64::VisitVecLoad(HVecLoad* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001329 LocationSummary* locations = instruction->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001330 size_t size = DataType::Size(instruction->GetPackedType());
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001331 VectorRegister reg = VectorRegisterFrom(locations->Out());
1332 GpuRegister base;
1333 int32_t offset = VecAddress(locations, size, &base);
1334 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001335 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001336 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001337 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001338 DCHECK_EQ(16u, instruction->GetVectorLength());
1339 __ LdB(reg, base, offset);
1340 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001341 case DataType::Type::kUint16:
1342 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001343 // Loading 8-bytes (needed if dealing with compressed strings in StringCharAt) from unaligned
1344 // memory address may cause a trap to the kernel if the CPU doesn't directly support unaligned
1345 // loads and stores.
1346 // TODO: Implement support for StringCharAt.
1347 DCHECK(!instruction->IsStringCharAt());
1348 DCHECK_EQ(8u, instruction->GetVectorLength());
1349 __ LdH(reg, base, offset);
1350 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001351 case DataType::Type::kInt32:
1352 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001353 DCHECK_EQ(4u, instruction->GetVectorLength());
1354 __ LdW(reg, base, offset);
1355 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001356 case DataType::Type::kInt64:
1357 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001358 DCHECK_EQ(2u, instruction->GetVectorLength());
1359 __ LdD(reg, base, offset);
1360 break;
1361 default:
1362 LOG(FATAL) << "Unsupported SIMD type";
1363 UNREACHABLE();
1364 }
Aart Bikf8f5a162017-02-06 15:35:29 -08001365}
1366
1367void LocationsBuilderMIPS64::VisitVecStore(HVecStore* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01001368 CreateVecMemLocations(GetGraph()->GetAllocator(), instruction, /* is_load */ false);
Aart Bikf8f5a162017-02-06 15:35:29 -08001369}
1370
1371void InstructionCodeGeneratorMIPS64::VisitVecStore(HVecStore* instruction) {
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001372 LocationSummary* locations = instruction->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001373 size_t size = DataType::Size(instruction->GetPackedType());
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001374 VectorRegister reg = VectorRegisterFrom(locations->InAt(2));
1375 GpuRegister base;
1376 int32_t offset = VecAddress(locations, size, &base);
1377 switch (instruction->GetPackedType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001378 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01001379 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001380 case DataType::Type::kInt8:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001381 DCHECK_EQ(16u, instruction->GetVectorLength());
1382 __ StB(reg, base, offset);
1383 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001384 case DataType::Type::kUint16:
1385 case DataType::Type::kInt16:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001386 DCHECK_EQ(8u, instruction->GetVectorLength());
1387 __ StH(reg, base, offset);
1388 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001389 case DataType::Type::kInt32:
1390 case DataType::Type::kFloat32:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001391 DCHECK_EQ(4u, instruction->GetVectorLength());
1392 __ StW(reg, base, offset);
1393 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001394 case DataType::Type::kInt64:
1395 case DataType::Type::kFloat64:
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001396 DCHECK_EQ(2u, instruction->GetVectorLength());
1397 __ StD(reg, base, offset);
1398 break;
1399 default:
1400 LOG(FATAL) << "Unsupported SIMD type";
1401 UNREACHABLE();
1402 }
Aart Bikf8f5a162017-02-06 15:35:29 -08001403}
1404
1405#undef __
1406
1407} // namespace mips64
1408} // namespace art