Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1 | /* |
| 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_mips.h" |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 18 | #include "mirror/array-inl.h" |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 19 | |
| 20 | namespace art { |
| 21 | namespace mips { |
| 22 | |
| 23 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 24 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
| 25 | |
| 26 | void LocationsBuilderMIPS::VisitVecReplicateScalar(HVecReplicateScalar* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 27 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 28 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 29 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 30 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 31 | case DataType::Type::kInt8: |
| 32 | case DataType::Type::kUint16: |
| 33 | case DataType::Type::kInt16: |
| 34 | case DataType::Type::kInt32: |
| 35 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 36 | locations->SetInAt(0, Location::RequiresRegister()); |
| 37 | locations->SetOut(Location::RequiresFpuRegister()); |
| 38 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 39 | case DataType::Type::kFloat32: |
| 40 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 41 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 42 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 43 | break; |
| 44 | default: |
| 45 | LOG(FATAL) << "Unsupported SIMD type"; |
| 46 | UNREACHABLE(); |
| 47 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void InstructionCodeGeneratorMIPS::VisitVecReplicateScalar(HVecReplicateScalar* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 51 | LocationSummary* locations = instruction->GetLocations(); |
| 52 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 53 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 54 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 55 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 56 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 57 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 58 | __ FillB(dst, locations->InAt(0).AsRegister<Register>()); |
| 59 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 60 | case DataType::Type::kUint16: |
| 61 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 62 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 63 | __ FillH(dst, locations->InAt(0).AsRegister<Register>()); |
| 64 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 65 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 66 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 67 | __ FillW(dst, locations->InAt(0).AsRegister<Register>()); |
| 68 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 69 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 70 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 71 | __ Mtc1(locations->InAt(0).AsRegisterPairLow<Register>(), FTMP); |
| 72 | __ MoveToFpuHigh(locations->InAt(0).AsRegisterPairHigh<Register>(), FTMP); |
| 73 | __ ReplicateFPToVectorRegister(dst, FTMP, /* is_double */ true); |
| 74 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 75 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 76 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 77 | __ ReplicateFPToVectorRegister(dst, |
| 78 | locations->InAt(0).AsFpuRegister<FRegister>(), |
| 79 | /* is_double */ false); |
| 80 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 81 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 82 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 83 | __ ReplicateFPToVectorRegister(dst, |
| 84 | locations->InAt(0).AsFpuRegister<FRegister>(), |
| 85 | /* is_double */ true); |
| 86 | break; |
| 87 | default: |
| 88 | LOG(FATAL) << "Unsupported SIMD type"; |
| 89 | UNREACHABLE(); |
| 90 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 93 | void LocationsBuilderMIPS::VisitVecExtractScalar(HVecExtractScalar* instruction) { |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 94 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 95 | } |
| 96 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 97 | void InstructionCodeGeneratorMIPS::VisitVecExtractScalar(HVecExtractScalar* instruction) { |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 98 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 99 | } |
| 100 | |
| 101 | // Helper to set up locations for vector unary operations. |
| 102 | static void CreateVecUnOpLocations(ArenaAllocator* arena, HVecUnaryOperation* instruction) { |
| 103 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 104 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 105 | case DataType::Type::kBool: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 106 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 107 | locations->SetOut(Location::RequiresFpuRegister(), |
| 108 | instruction->IsVecNot() ? Location::kOutputOverlap |
| 109 | : Location::kNoOutputOverlap); |
| 110 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 111 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 112 | case DataType::Type::kInt8: |
| 113 | case DataType::Type::kUint16: |
| 114 | case DataType::Type::kInt16: |
| 115 | case DataType::Type::kInt32: |
| 116 | case DataType::Type::kInt64: |
| 117 | case DataType::Type::kFloat32: |
| 118 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 119 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 120 | locations->SetOut(Location::RequiresFpuRegister(), |
| 121 | (instruction->IsVecNeg() || instruction->IsVecAbs()) |
| 122 | ? Location::kOutputOverlap |
| 123 | : Location::kNoOutputOverlap); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 124 | break; |
| 125 | default: |
| 126 | LOG(FATAL) << "Unsupported SIMD type"; |
| 127 | UNREACHABLE(); |
| 128 | } |
| 129 | } |
| 130 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 131 | void LocationsBuilderMIPS::VisitVecReduce(HVecReduce* instruction) { |
| 132 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 133 | } |
| 134 | |
| 135 | void InstructionCodeGeneratorMIPS::VisitVecReduce(HVecReduce* instruction) { |
| 136 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 137 | } |
| 138 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 139 | void LocationsBuilderMIPS::VisitVecCnv(HVecCnv* instruction) { |
| 140 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 141 | } |
| 142 | |
| 143 | void InstructionCodeGeneratorMIPS::VisitVecCnv(HVecCnv* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 144 | LocationSummary* locations = instruction->GetLocations(); |
| 145 | VectorRegister src = VectorRegisterFrom(locations->InAt(0)); |
| 146 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | DataType::Type from = instruction->GetInputType(); |
| 148 | DataType::Type to = instruction->GetResultType(); |
| 149 | if (from == DataType::Type::kInt32 && to == DataType::Type::kFloat32) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 150 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 151 | __ Ffint_sW(dst, src); |
| 152 | } else { |
| 153 | LOG(FATAL) << "Unsupported SIMD type"; |
| 154 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void LocationsBuilderMIPS::VisitVecNeg(HVecNeg* instruction) { |
| 158 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 159 | } |
| 160 | |
| 161 | void InstructionCodeGeneratorMIPS::VisitVecNeg(HVecNeg* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 162 | LocationSummary* locations = instruction->GetLocations(); |
| 163 | VectorRegister src = VectorRegisterFrom(locations->InAt(0)); |
| 164 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 165 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 166 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 167 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 168 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 169 | __ FillB(dst, ZERO); |
| 170 | __ SubvB(dst, dst, src); |
| 171 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 172 | case DataType::Type::kUint16: |
| 173 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 174 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 175 | __ FillH(dst, ZERO); |
| 176 | __ SubvH(dst, dst, src); |
| 177 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 178 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 179 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 180 | __ FillW(dst, ZERO); |
| 181 | __ SubvW(dst, dst, src); |
| 182 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 183 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 184 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 185 | __ FillW(dst, ZERO); |
| 186 | __ SubvD(dst, dst, src); |
| 187 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 188 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 189 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 190 | __ FillW(dst, ZERO); |
| 191 | __ FsubW(dst, dst, src); |
| 192 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 193 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 194 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 195 | __ FillW(dst, ZERO); |
| 196 | __ FsubD(dst, dst, src); |
| 197 | break; |
| 198 | default: |
| 199 | LOG(FATAL) << "Unsupported SIMD type"; |
| 200 | UNREACHABLE(); |
| 201 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 204 | void LocationsBuilderMIPS::VisitVecAbs(HVecAbs* instruction) { |
| 205 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 206 | } |
| 207 | |
| 208 | void InstructionCodeGeneratorMIPS::VisitVecAbs(HVecAbs* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 209 | LocationSummary* locations = instruction->GetLocations(); |
| 210 | VectorRegister src = VectorRegisterFrom(locations->InAt(0)); |
| 211 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 212 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 213 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 214 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 215 | __ FillB(dst, ZERO); // all zeroes |
| 216 | __ Add_aB(dst, dst, src); // dst = abs(0) + abs(src) |
| 217 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 218 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 219 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 220 | __ FillH(dst, ZERO); // all zeroes |
| 221 | __ Add_aH(dst, dst, src); // dst = abs(0) + abs(src) |
| 222 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 223 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 224 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 225 | __ FillW(dst, ZERO); // all zeroes |
| 226 | __ Add_aW(dst, dst, src); // dst = abs(0) + abs(src) |
| 227 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 228 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 229 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 230 | __ FillW(dst, ZERO); // all zeroes |
| 231 | __ Add_aD(dst, dst, src); // dst = abs(0) + abs(src) |
| 232 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 233 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 234 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 235 | __ LdiW(dst, -1); // all ones |
| 236 | __ SrliW(dst, dst, 1); |
| 237 | __ AndV(dst, dst, src); |
| 238 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 239 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 240 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 241 | __ LdiD(dst, -1); // all ones |
| 242 | __ SrliD(dst, dst, 1); |
| 243 | __ AndV(dst, dst, src); |
| 244 | break; |
| 245 | default: |
| 246 | LOG(FATAL) << "Unsupported SIMD type"; |
| 247 | UNREACHABLE(); |
| 248 | } |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 251 | void LocationsBuilderMIPS::VisitVecNot(HVecNot* instruction) { |
| 252 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 253 | } |
| 254 | |
| 255 | void InstructionCodeGeneratorMIPS::VisitVecNot(HVecNot* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 256 | LocationSummary* locations = instruction->GetLocations(); |
| 257 | VectorRegister src = VectorRegisterFrom(locations->InAt(0)); |
| 258 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 259 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 260 | case DataType::Type::kBool: // special case boolean-not |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 261 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 262 | __ LdiB(dst, 1); |
| 263 | __ XorV(dst, dst, src); |
| 264 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 265 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 266 | case DataType::Type::kInt8: |
| 267 | case DataType::Type::kUint16: |
| 268 | case DataType::Type::kInt16: |
| 269 | case DataType::Type::kInt32: |
| 270 | case DataType::Type::kInt64: |
| 271 | case DataType::Type::kFloat32: |
| 272 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 273 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 274 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 275 | __ NorV(dst, src, src); // lanes do not matter |
| 276 | break; |
| 277 | default: |
| 278 | LOG(FATAL) << "Unsupported SIMD type"; |
| 279 | UNREACHABLE(); |
| 280 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | // Helper to set up locations for vector binary operations. |
| 284 | static void CreateVecBinOpLocations(ArenaAllocator* arena, HVecBinaryOperation* instruction) { |
| 285 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 286 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 287 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 288 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 289 | case DataType::Type::kInt8: |
| 290 | case DataType::Type::kUint16: |
| 291 | case DataType::Type::kInt16: |
| 292 | case DataType::Type::kInt32: |
| 293 | case DataType::Type::kInt64: |
| 294 | case DataType::Type::kFloat32: |
| 295 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 296 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 297 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 298 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 299 | break; |
| 300 | default: |
| 301 | LOG(FATAL) << "Unsupported SIMD type"; |
| 302 | UNREACHABLE(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | void LocationsBuilderMIPS::VisitVecAdd(HVecAdd* instruction) { |
| 307 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 308 | } |
| 309 | |
| 310 | void InstructionCodeGeneratorMIPS::VisitVecAdd(HVecAdd* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 311 | LocationSummary* locations = instruction->GetLocations(); |
| 312 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 313 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 314 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 315 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 316 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 317 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 318 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 319 | __ AddvB(dst, lhs, rhs); |
| 320 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 321 | case DataType::Type::kUint16: |
| 322 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 323 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 324 | __ AddvH(dst, lhs, rhs); |
| 325 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 326 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 327 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 328 | __ AddvW(dst, lhs, rhs); |
| 329 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 330 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 331 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 332 | __ AddvD(dst, lhs, rhs); |
| 333 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 334 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 335 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 336 | __ FaddW(dst, lhs, rhs); |
| 337 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 338 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 339 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 340 | __ FaddD(dst, lhs, rhs); |
| 341 | break; |
| 342 | default: |
| 343 | LOG(FATAL) << "Unsupported SIMD type"; |
| 344 | UNREACHABLE(); |
| 345 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 348 | void LocationsBuilderMIPS::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
| 349 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 350 | } |
| 351 | |
| 352 | void InstructionCodeGeneratorMIPS::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 353 | LocationSummary* locations = instruction->GetLocations(); |
| 354 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 355 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 356 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 357 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 358 | case DataType::Type::kUint8: |
| 359 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 360 | instruction->IsRounded() |
| 361 | ? __ Aver_uB(dst, lhs, rhs) |
| 362 | : __ Ave_uB(dst, lhs, rhs); |
| 363 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 364 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 365 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 366 | instruction->IsRounded() |
| 367 | ? __ Aver_sB(dst, lhs, rhs) |
| 368 | : __ Ave_sB(dst, lhs, rhs); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 369 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 370 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 371 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 372 | instruction->IsRounded() |
| 373 | ? __ Aver_uH(dst, lhs, rhs) |
| 374 | : __ Ave_uH(dst, lhs, rhs); |
| 375 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 376 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 377 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 378 | instruction->IsRounded() |
| 379 | ? __ Aver_sH(dst, lhs, rhs) |
| 380 | : __ Ave_sH(dst, lhs, rhs); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 381 | break; |
| 382 | default: |
| 383 | LOG(FATAL) << "Unsupported SIMD type"; |
| 384 | UNREACHABLE(); |
| 385 | } |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 388 | void LocationsBuilderMIPS::VisitVecSub(HVecSub* instruction) { |
| 389 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 390 | } |
| 391 | |
| 392 | void InstructionCodeGeneratorMIPS::VisitVecSub(HVecSub* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 393 | LocationSummary* locations = instruction->GetLocations(); |
| 394 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 395 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 396 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 397 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 398 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 399 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 400 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 401 | __ SubvB(dst, lhs, rhs); |
| 402 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 403 | case DataType::Type::kUint16: |
| 404 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 405 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 406 | __ SubvH(dst, lhs, rhs); |
| 407 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 408 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 409 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 410 | __ SubvW(dst, lhs, rhs); |
| 411 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 412 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 413 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 414 | __ SubvD(dst, lhs, rhs); |
| 415 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 416 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 417 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 418 | __ FsubW(dst, lhs, rhs); |
| 419 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 420 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 421 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 422 | __ FsubD(dst, lhs, rhs); |
| 423 | break; |
| 424 | default: |
| 425 | LOG(FATAL) << "Unsupported SIMD type"; |
| 426 | UNREACHABLE(); |
| 427 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void LocationsBuilderMIPS::VisitVecMul(HVecMul* instruction) { |
| 431 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 432 | } |
| 433 | |
| 434 | void InstructionCodeGeneratorMIPS::VisitVecMul(HVecMul* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 435 | LocationSummary* locations = instruction->GetLocations(); |
| 436 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 437 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 438 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 439 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 440 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 441 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 442 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 443 | __ MulvB(dst, lhs, rhs); |
| 444 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 445 | case DataType::Type::kUint16: |
| 446 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 447 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 448 | __ MulvH(dst, lhs, rhs); |
| 449 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 450 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 451 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 452 | __ MulvW(dst, lhs, rhs); |
| 453 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 454 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 455 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 456 | __ MulvD(dst, lhs, rhs); |
| 457 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 458 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 459 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 460 | __ FmulW(dst, lhs, rhs); |
| 461 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 462 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 463 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 464 | __ FmulD(dst, lhs, rhs); |
| 465 | break; |
| 466 | default: |
| 467 | LOG(FATAL) << "Unsupported SIMD type"; |
| 468 | UNREACHABLE(); |
| 469 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | void LocationsBuilderMIPS::VisitVecDiv(HVecDiv* instruction) { |
| 473 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 474 | } |
| 475 | |
| 476 | void InstructionCodeGeneratorMIPS::VisitVecDiv(HVecDiv* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 477 | LocationSummary* locations = instruction->GetLocations(); |
| 478 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 479 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 480 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 481 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 482 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 483 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 484 | __ FdivW(dst, lhs, rhs); |
| 485 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 486 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 487 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 488 | __ FdivD(dst, lhs, rhs); |
| 489 | break; |
| 490 | default: |
| 491 | LOG(FATAL) << "Unsupported SIMD type"; |
| 492 | UNREACHABLE(); |
| 493 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 496 | void LocationsBuilderMIPS::VisitVecMin(HVecMin* instruction) { |
| 497 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 498 | } |
| 499 | |
| 500 | void InstructionCodeGeneratorMIPS::VisitVecMin(HVecMin* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 501 | LocationSummary* locations = instruction->GetLocations(); |
| 502 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 503 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 504 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 505 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 506 | case DataType::Type::kUint8: |
| 507 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 508 | __ Min_uB(dst, lhs, rhs); |
| 509 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 510 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 511 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 512 | __ Min_sB(dst, lhs, rhs); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 513 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 514 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 515 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 516 | __ Min_uH(dst, lhs, rhs); |
| 517 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 518 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 519 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 520 | __ Min_sH(dst, lhs, rhs); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 521 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 522 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 523 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 524 | if (instruction->IsUnsigned()) { |
| 525 | __ Min_uW(dst, lhs, rhs); |
| 526 | } else { |
| 527 | __ Min_sW(dst, lhs, rhs); |
| 528 | } |
| 529 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 530 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 531 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 532 | if (instruction->IsUnsigned()) { |
| 533 | __ Min_uD(dst, lhs, rhs); |
| 534 | } else { |
| 535 | __ Min_sD(dst, lhs, rhs); |
| 536 | } |
| 537 | break; |
| 538 | // When one of arguments is NaN, fmin.df returns other argument, but Java expects a NaN value. |
| 539 | // TODO: Fix min(x, NaN) cases for float and double. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 540 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 541 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 542 | DCHECK(!instruction->IsUnsigned()); |
| 543 | __ FminW(dst, lhs, rhs); |
| 544 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 545 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 546 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 547 | DCHECK(!instruction->IsUnsigned()); |
| 548 | __ FminD(dst, lhs, rhs); |
| 549 | break; |
| 550 | default: |
| 551 | LOG(FATAL) << "Unsupported SIMD type"; |
| 552 | UNREACHABLE(); |
| 553 | } |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void LocationsBuilderMIPS::VisitVecMax(HVecMax* instruction) { |
| 557 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 558 | } |
| 559 | |
| 560 | void InstructionCodeGeneratorMIPS::VisitVecMax(HVecMax* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 561 | LocationSummary* locations = instruction->GetLocations(); |
| 562 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 563 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 564 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 565 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 566 | case DataType::Type::kUint8: |
| 567 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 568 | __ Max_uB(dst, lhs, rhs); |
| 569 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 570 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 571 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 572 | __ Max_sB(dst, lhs, rhs); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 573 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 574 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 575 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 576 | __ Max_uH(dst, lhs, rhs); |
| 577 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 578 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 579 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 580 | __ Max_sH(dst, lhs, rhs); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 581 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 582 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 583 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 584 | if (instruction->IsUnsigned()) { |
| 585 | __ Max_uW(dst, lhs, rhs); |
| 586 | } else { |
| 587 | __ Max_sW(dst, lhs, rhs); |
| 588 | } |
| 589 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 590 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 591 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 592 | if (instruction->IsUnsigned()) { |
| 593 | __ Max_uD(dst, lhs, rhs); |
| 594 | } else { |
| 595 | __ Max_sD(dst, lhs, rhs); |
| 596 | } |
| 597 | break; |
| 598 | // When one of arguments is NaN, fmax.df returns other argument, but Java expects a NaN value. |
| 599 | // TODO: Fix max(x, NaN) cases for float and double. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 600 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 601 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 602 | DCHECK(!instruction->IsUnsigned()); |
| 603 | __ FmaxW(dst, lhs, rhs); |
| 604 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 605 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 606 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 607 | DCHECK(!instruction->IsUnsigned()); |
| 608 | __ FmaxD(dst, lhs, rhs); |
| 609 | break; |
| 610 | default: |
| 611 | LOG(FATAL) << "Unsupported SIMD type"; |
| 612 | UNREACHABLE(); |
| 613 | } |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 616 | void LocationsBuilderMIPS::VisitVecAnd(HVecAnd* instruction) { |
| 617 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 618 | } |
| 619 | |
| 620 | void InstructionCodeGeneratorMIPS::VisitVecAnd(HVecAnd* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 621 | LocationSummary* locations = instruction->GetLocations(); |
| 622 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 623 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 624 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 625 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 626 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 627 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 628 | case DataType::Type::kInt8: |
| 629 | case DataType::Type::kUint16: |
| 630 | case DataType::Type::kInt16: |
| 631 | case DataType::Type::kInt32: |
| 632 | case DataType::Type::kInt64: |
| 633 | case DataType::Type::kFloat32: |
| 634 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 635 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 636 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 637 | __ AndV(dst, lhs, rhs); // lanes do not matter |
| 638 | break; |
| 639 | default: |
| 640 | LOG(FATAL) << "Unsupported SIMD type"; |
| 641 | UNREACHABLE(); |
| 642 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | void LocationsBuilderMIPS::VisitVecAndNot(HVecAndNot* instruction) { |
| 646 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 647 | } |
| 648 | |
| 649 | void InstructionCodeGeneratorMIPS::VisitVecAndNot(HVecAndNot* instruction) { |
| 650 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 651 | } |
| 652 | |
| 653 | void LocationsBuilderMIPS::VisitVecOr(HVecOr* instruction) { |
| 654 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 655 | } |
| 656 | |
| 657 | void InstructionCodeGeneratorMIPS::VisitVecOr(HVecOr* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 658 | LocationSummary* locations = instruction->GetLocations(); |
| 659 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 660 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 661 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 662 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 663 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 664 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 665 | case DataType::Type::kInt8: |
| 666 | case DataType::Type::kUint16: |
| 667 | case DataType::Type::kInt16: |
| 668 | case DataType::Type::kInt32: |
| 669 | case DataType::Type::kInt64: |
| 670 | case DataType::Type::kFloat32: |
| 671 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 672 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 673 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 674 | __ OrV(dst, lhs, rhs); // lanes do not matter |
| 675 | break; |
| 676 | default: |
| 677 | LOG(FATAL) << "Unsupported SIMD type"; |
| 678 | UNREACHABLE(); |
| 679 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void LocationsBuilderMIPS::VisitVecXor(HVecXor* instruction) { |
| 683 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 684 | } |
| 685 | |
| 686 | void InstructionCodeGeneratorMIPS::VisitVecXor(HVecXor* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 687 | LocationSummary* locations = instruction->GetLocations(); |
| 688 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 689 | VectorRegister rhs = VectorRegisterFrom(locations->InAt(1)); |
| 690 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 691 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 692 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 693 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 694 | case DataType::Type::kInt8: |
| 695 | case DataType::Type::kUint16: |
| 696 | case DataType::Type::kInt16: |
| 697 | case DataType::Type::kInt32: |
| 698 | case DataType::Type::kInt64: |
| 699 | case DataType::Type::kFloat32: |
| 700 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 701 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 702 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 703 | __ XorV(dst, lhs, rhs); // lanes do not matter |
| 704 | break; |
| 705 | default: |
| 706 | LOG(FATAL) << "Unsupported SIMD type"; |
| 707 | UNREACHABLE(); |
| 708 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | // Helper to set up locations for vector shift operations. |
| 712 | static void CreateVecShiftLocations(ArenaAllocator* arena, HVecBinaryOperation* instruction) { |
| 713 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 714 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 715 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 716 | case DataType::Type::kInt8: |
| 717 | case DataType::Type::kUint16: |
| 718 | case DataType::Type::kInt16: |
| 719 | case DataType::Type::kInt32: |
| 720 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 721 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 722 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 723 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 724 | break; |
| 725 | default: |
| 726 | LOG(FATAL) << "Unsupported SIMD type"; |
| 727 | UNREACHABLE(); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | void LocationsBuilderMIPS::VisitVecShl(HVecShl* instruction) { |
| 732 | CreateVecShiftLocations(GetGraph()->GetArena(), instruction); |
| 733 | } |
| 734 | |
| 735 | void InstructionCodeGeneratorMIPS::VisitVecShl(HVecShl* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 736 | LocationSummary* locations = instruction->GetLocations(); |
| 737 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 738 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 739 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 740 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 741 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 742 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 743 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 744 | __ SlliB(dst, lhs, value); |
| 745 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 746 | case DataType::Type::kUint16: |
| 747 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 748 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 749 | __ SlliH(dst, lhs, value); |
| 750 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 751 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 752 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 753 | __ SlliW(dst, lhs, value); |
| 754 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 755 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 756 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 757 | __ SlliD(dst, lhs, value); |
| 758 | break; |
| 759 | default: |
| 760 | LOG(FATAL) << "Unsupported SIMD type"; |
| 761 | UNREACHABLE(); |
| 762 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void LocationsBuilderMIPS::VisitVecShr(HVecShr* instruction) { |
| 766 | CreateVecShiftLocations(GetGraph()->GetArena(), instruction); |
| 767 | } |
| 768 | |
| 769 | void InstructionCodeGeneratorMIPS::VisitVecShr(HVecShr* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 770 | LocationSummary* locations = instruction->GetLocations(); |
| 771 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 772 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 773 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 774 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 775 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 776 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 777 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 778 | __ SraiB(dst, lhs, value); |
| 779 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 780 | case DataType::Type::kUint16: |
| 781 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 782 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 783 | __ SraiH(dst, lhs, value); |
| 784 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 785 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 786 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 787 | __ SraiW(dst, lhs, value); |
| 788 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 789 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 790 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 791 | __ SraiD(dst, lhs, value); |
| 792 | break; |
| 793 | default: |
| 794 | LOG(FATAL) << "Unsupported SIMD type"; |
| 795 | UNREACHABLE(); |
| 796 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | void LocationsBuilderMIPS::VisitVecUShr(HVecUShr* instruction) { |
| 800 | CreateVecShiftLocations(GetGraph()->GetArena(), instruction); |
| 801 | } |
| 802 | |
| 803 | void InstructionCodeGeneratorMIPS::VisitVecUShr(HVecUShr* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 804 | LocationSummary* locations = instruction->GetLocations(); |
| 805 | VectorRegister lhs = VectorRegisterFrom(locations->InAt(0)); |
| 806 | VectorRegister dst = VectorRegisterFrom(locations->Out()); |
| 807 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 808 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 809 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 810 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 811 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 812 | __ SrliB(dst, lhs, value); |
| 813 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 814 | case DataType::Type::kUint16: |
| 815 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 816 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 817 | __ SrliH(dst, lhs, value); |
| 818 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 819 | case DataType::Type::kInt32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 820 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 821 | __ SrliW(dst, lhs, value); |
| 822 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 823 | case DataType::Type::kInt64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 824 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 825 | __ SrliD(dst, lhs, value); |
| 826 | break; |
| 827 | default: |
| 828 | LOG(FATAL) << "Unsupported SIMD type"; |
| 829 | UNREACHABLE(); |
| 830 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 833 | void LocationsBuilderMIPS::VisitVecSetScalars(HVecSetScalars* instruction) { |
| 834 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 835 | } |
| 836 | |
| 837 | void InstructionCodeGeneratorMIPS::VisitVecSetScalars(HVecSetScalars* instruction) { |
| 838 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 839 | } |
| 840 | |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 841 | // Helper to set up locations for vector accumulations. |
| 842 | static void CreateVecAccumLocations(ArenaAllocator* arena, HVecOperation* instruction) { |
| 843 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 844 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 845 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 846 | case DataType::Type::kInt8: |
| 847 | case DataType::Type::kUint16: |
| 848 | case DataType::Type::kInt16: |
| 849 | case DataType::Type::kInt32: |
| 850 | case DataType::Type::kInt64: |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 851 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 852 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 853 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Lena Djokic | bc5460b | 2017-07-20 16:07:36 +0200 | [diff] [blame] | 854 | locations->SetOut(Location::SameAsFirstInput()); |
| 855 | break; |
| 856 | default: |
| 857 | LOG(FATAL) << "Unsupported SIMD type"; |
| 858 | UNREACHABLE(); |
| 859 | } |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 860 | } |
| 861 | |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 862 | void LocationsBuilderMIPS::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) { |
| 863 | CreateVecAccumLocations(GetGraph()->GetArena(), instruction); |
| 864 | } |
| 865 | |
| 866 | void InstructionCodeGeneratorMIPS::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) { |
| 867 | LocationSummary* locations = instruction->GetLocations(); |
| 868 | VectorRegister acc = VectorRegisterFrom(locations->InAt(0)); |
| 869 | VectorRegister left = VectorRegisterFrom(locations->InAt(1)); |
| 870 | VectorRegister right = VectorRegisterFrom(locations->InAt(2)); |
| 871 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 872 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 873 | case DataType::Type::kInt8: |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 874 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 875 | if (instruction->GetOpKind() == HInstruction::kAdd) { |
Lena Djokic | bc5460b | 2017-07-20 16:07:36 +0200 | [diff] [blame] | 876 | __ MaddvB(acc, left, right); |
| 877 | } else { |
| 878 | __ MsubvB(acc, left, right); |
| 879 | } |
| 880 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 881 | case DataType::Type::kUint16: |
| 882 | case DataType::Type::kInt16: |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 883 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 884 | if (instruction->GetOpKind() == HInstruction::kAdd) { |
Lena Djokic | bc5460b | 2017-07-20 16:07:36 +0200 | [diff] [blame] | 885 | __ MaddvH(acc, left, right); |
| 886 | } else { |
| 887 | __ MsubvH(acc, left, right); |
| 888 | } |
| 889 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 890 | case DataType::Type::kInt32: |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 891 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 892 | if (instruction->GetOpKind() == HInstruction::kAdd) { |
Lena Djokic | bc5460b | 2017-07-20 16:07:36 +0200 | [diff] [blame] | 893 | __ MaddvW(acc, left, right); |
| 894 | } else { |
| 895 | __ MsubvW(acc, left, right); |
| 896 | } |
| 897 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 898 | case DataType::Type::kInt64: |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 899 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 900 | if (instruction->GetOpKind() == HInstruction::kAdd) { |
Lena Djokic | bc5460b | 2017-07-20 16:07:36 +0200 | [diff] [blame] | 901 | __ MaddvD(acc, left, right); |
| 902 | } else { |
| 903 | __ MsubvD(acc, left, right); |
| 904 | } |
| 905 | break; |
| 906 | default: |
| 907 | LOG(FATAL) << "Unsupported SIMD type"; |
| 908 | UNREACHABLE(); |
| 909 | } |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 912 | void LocationsBuilderMIPS::VisitVecSADAccumulate(HVecSADAccumulate* instruction) { |
| 913 | CreateVecAccumLocations(GetGraph()->GetArena(), instruction); |
| 914 | } |
| 915 | |
| 916 | void InstructionCodeGeneratorMIPS::VisitVecSADAccumulate(HVecSADAccumulate* instruction) { |
| 917 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 918 | // TODO: implement this, location helper already filled out (shared with MulAcc). |
| 919 | } |
| 920 | |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 921 | // Helper to set up locations for vector memory operations. |
| 922 | static void CreateVecMemLocations(ArenaAllocator* arena, |
| 923 | HVecMemoryOperation* instruction, |
| 924 | bool is_load) { |
| 925 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 926 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 927 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 928 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 929 | case DataType::Type::kInt8: |
| 930 | case DataType::Type::kUint16: |
| 931 | case DataType::Type::kInt16: |
| 932 | case DataType::Type::kInt32: |
| 933 | case DataType::Type::kInt64: |
| 934 | case DataType::Type::kFloat32: |
| 935 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 936 | locations->SetInAt(0, Location::RequiresRegister()); |
| 937 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 938 | if (is_load) { |
| 939 | locations->SetOut(Location::RequiresFpuRegister()); |
| 940 | } else { |
| 941 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 942 | } |
| 943 | break; |
| 944 | default: |
| 945 | LOG(FATAL) << "Unsupported SIMD type"; |
| 946 | UNREACHABLE(); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | // Helper to prepare register and offset for vector memory operations. Returns the offset and sets |
| 951 | // the output parameter adjusted_base to the original base or to a reserved temporary register (AT). |
| 952 | int32_t InstructionCodeGeneratorMIPS::VecAddress(LocationSummary* locations, |
| 953 | size_t size, |
| 954 | /* out */ Register* adjusted_base) { |
| 955 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 956 | Location index = locations->InAt(1); |
| 957 | int scale = TIMES_1; |
| 958 | switch (size) { |
| 959 | case 2: scale = TIMES_2; break; |
| 960 | case 4: scale = TIMES_4; break; |
| 961 | case 8: scale = TIMES_8; break; |
| 962 | default: break; |
| 963 | } |
| 964 | int32_t offset = mirror::Array::DataOffset(size).Int32Value(); |
| 965 | |
| 966 | if (index.IsConstant()) { |
| 967 | offset += index.GetConstant()->AsIntConstant()->GetValue() << scale; |
| 968 | __ AdjustBaseOffsetAndElementSizeShift(base, offset, scale); |
| 969 | *adjusted_base = base; |
| 970 | } else { |
| 971 | Register index_reg = index.AsRegister<Register>(); |
| 972 | if (scale != TIMES_1) { |
| 973 | __ Lsa(AT, index_reg, base, scale); |
| 974 | } else { |
| 975 | __ Addu(AT, base, index_reg); |
| 976 | } |
| 977 | *adjusted_base = AT; |
| 978 | } |
| 979 | return offset; |
| 980 | } |
| 981 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 982 | void LocationsBuilderMIPS::VisitVecLoad(HVecLoad* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 983 | CreateVecMemLocations(GetGraph()->GetArena(), instruction, /* is_load */ true); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | void InstructionCodeGeneratorMIPS::VisitVecLoad(HVecLoad* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 987 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 988 | size_t size = DataType::Size(instruction->GetPackedType()); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 989 | VectorRegister reg = VectorRegisterFrom(locations->Out()); |
| 990 | Register base; |
| 991 | int32_t offset = VecAddress(locations, size, &base); |
| 992 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 993 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 994 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 995 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 996 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 997 | __ LdB(reg, base, offset); |
| 998 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 999 | case DataType::Type::kUint16: |
| 1000 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1001 | // Loading 8-bytes (needed if dealing with compressed strings in StringCharAt) from unaligned |
| 1002 | // memory address may cause a trap to the kernel if the CPU doesn't directly support unaligned |
| 1003 | // loads and stores. |
| 1004 | // TODO: Implement support for StringCharAt. |
| 1005 | DCHECK(!instruction->IsStringCharAt()); |
| 1006 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 1007 | __ LdH(reg, base, offset); |
| 1008 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1009 | case DataType::Type::kInt32: |
| 1010 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1011 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1012 | __ LdW(reg, base, offset); |
| 1013 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1014 | case DataType::Type::kInt64: |
| 1015 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1016 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1017 | __ LdD(reg, base, offset); |
| 1018 | break; |
| 1019 | default: |
| 1020 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1021 | UNREACHABLE(); |
| 1022 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | void LocationsBuilderMIPS::VisitVecStore(HVecStore* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1026 | CreateVecMemLocations(GetGraph()->GetArena(), instruction, /* is_load */ false); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | void InstructionCodeGeneratorMIPS::VisitVecStore(HVecStore* instruction) { |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1030 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1031 | size_t size = DataType::Size(instruction->GetPackedType()); |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1032 | VectorRegister reg = VectorRegisterFrom(locations->InAt(2)); |
| 1033 | Register base; |
| 1034 | int32_t offset = VecAddress(locations, size, &base); |
| 1035 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1036 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1037 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1038 | case DataType::Type::kInt8: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1039 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 1040 | __ StB(reg, base, offset); |
| 1041 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1042 | case DataType::Type::kUint16: |
| 1043 | case DataType::Type::kInt16: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1044 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 1045 | __ StH(reg, base, offset); |
| 1046 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1047 | case DataType::Type::kInt32: |
| 1048 | case DataType::Type::kFloat32: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1049 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1050 | __ StW(reg, base, offset); |
| 1051 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1052 | case DataType::Type::kInt64: |
| 1053 | case DataType::Type::kFloat64: |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 1054 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1055 | __ StD(reg, base, offset); |
| 1056 | break; |
| 1057 | default: |
| 1058 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1059 | UNREACHABLE(); |
| 1060 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | #undef __ |
| 1064 | |
| 1065 | } // namespace mips |
| 1066 | } // namespace art |