Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "intrinsics_mips64.h" |
| 18 | |
| 19 | #include "arch/mips64/instruction_set_features_mips64.h" |
| 20 | #include "art_method.h" |
| 21 | #include "code_generator_mips64.h" |
| 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | #include "intrinsics.h" |
| 24 | #include "mirror/array-inl.h" |
| 25 | #include "mirror/string.h" |
| 26 | #include "thread.h" |
| 27 | #include "utils/mips64/assembler_mips64.h" |
| 28 | #include "utils/mips64/constants_mips64.h" |
| 29 | |
| 30 | namespace art { |
| 31 | |
| 32 | namespace mips64 { |
| 33 | |
| 34 | IntrinsicLocationsBuilderMIPS64::IntrinsicLocationsBuilderMIPS64(CodeGeneratorMIPS64* codegen) |
| 35 | : arena_(codegen->GetGraph()->GetArena()) { |
| 36 | } |
| 37 | |
| 38 | Mips64Assembler* IntrinsicCodeGeneratorMIPS64::GetAssembler() { |
| 39 | return reinterpret_cast<Mips64Assembler*>(codegen_->GetAssembler()); |
| 40 | } |
| 41 | |
| 42 | ArenaAllocator* IntrinsicCodeGeneratorMIPS64::GetAllocator() { |
| 43 | return codegen_->GetGraph()->GetArena(); |
| 44 | } |
| 45 | |
Chris Larsen | 9701c2e | 2015-09-04 17:22:47 -0700 | [diff] [blame] | 46 | #define __ codegen->GetAssembler()-> |
| 47 | |
| 48 | static void MoveFromReturnRegister(Location trg, |
| 49 | Primitive::Type type, |
| 50 | CodeGeneratorMIPS64* codegen) { |
| 51 | if (!trg.IsValid()) { |
| 52 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 57 | |
| 58 | if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) { |
| 59 | GpuRegister trg_reg = trg.AsRegister<GpuRegister>(); |
| 60 | if (trg_reg != V0) { |
| 61 | __ Move(V0, trg_reg); |
| 62 | } |
| 63 | } else { |
| 64 | FpuRegister trg_reg = trg.AsFpuRegister<FpuRegister>(); |
| 65 | if (trg_reg != F0) { |
| 66 | if (type == Primitive::kPrimFloat) { |
| 67 | __ MovS(F0, trg_reg); |
| 68 | } else { |
| 69 | __ MovD(F0, trg_reg); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static void MoveArguments(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
| 76 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 77 | IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor); |
| 78 | } |
| 79 | |
| 80 | // Slow-path for fallback (calling the managed code to handle the |
| 81 | // intrinsic) in an intrinsified call. This will copy the arguments |
| 82 | // into the positions for a regular call. |
| 83 | // |
| 84 | // Note: The actual parameters are required to be in the locations |
| 85 | // given by the invoke's location summary. If an intrinsic |
| 86 | // modifies those locations before a slowpath call, they must be |
| 87 | // restored! |
| 88 | class IntrinsicSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 89 | public: |
| 90 | explicit IntrinsicSlowPathMIPS64(HInvoke* invoke) : invoke_(invoke) { } |
| 91 | |
| 92 | void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE { |
| 93 | CodeGeneratorMIPS64* codegen = down_cast<CodeGeneratorMIPS64*>(codegen_in); |
| 94 | |
| 95 | __ Bind(GetEntryLabel()); |
| 96 | |
| 97 | SaveLiveRegisters(codegen, invoke_->GetLocations()); |
| 98 | |
| 99 | MoveArguments(invoke_, codegen); |
| 100 | |
| 101 | if (invoke_->IsInvokeStaticOrDirect()) { |
| 102 | codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(), |
| 103 | Location::RegisterLocation(A0)); |
| 104 | codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this); |
| 105 | } else { |
| 106 | UNIMPLEMENTED(FATAL) << "Non-direct intrinsic slow-path not yet implemented"; |
| 107 | UNREACHABLE(); |
| 108 | } |
| 109 | |
| 110 | // Copy the result back to the expected output. |
| 111 | Location out = invoke_->GetLocations()->Out(); |
| 112 | if (out.IsValid()) { |
| 113 | DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory. |
| 114 | DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 115 | MoveFromReturnRegister(out, invoke_->GetType(), codegen); |
| 116 | } |
| 117 | |
| 118 | RestoreLiveRegisters(codegen, invoke_->GetLocations()); |
| 119 | __ B(GetExitLabel()); |
| 120 | } |
| 121 | |
| 122 | const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathMIPS64"; } |
| 123 | |
| 124 | private: |
| 125 | // The instruction where this slow path is happening. |
| 126 | HInvoke* const invoke_; |
| 127 | |
| 128 | DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathMIPS64); |
| 129 | }; |
| 130 | |
| 131 | #undef __ |
| 132 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 133 | bool IntrinsicLocationsBuilderMIPS64::TryDispatch(HInvoke* invoke) { |
| 134 | Dispatch(invoke); |
| 135 | LocationSummary* res = invoke->GetLocations(); |
| 136 | return res != nullptr && res->Intrinsified(); |
| 137 | } |
| 138 | |
| 139 | #define __ assembler-> |
| 140 | |
| 141 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 142 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 143 | LocationSummary::kNoCall, |
| 144 | kIntrinsified); |
| 145 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 146 | locations->SetOut(Location::RequiresRegister()); |
| 147 | } |
| 148 | |
| 149 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 150 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 151 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 152 | |
| 153 | if (is64bit) { |
| 154 | __ Dmfc1(out, in); |
| 155 | } else { |
| 156 | __ Mfc1(out, in); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // long java.lang.Double.doubleToRawLongBits(double) |
| 161 | void IntrinsicLocationsBuilderMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 162 | CreateFPToIntLocations(arena_, invoke); |
| 163 | } |
| 164 | |
| 165 | void IntrinsicCodeGeneratorMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 166 | MoveFPToInt(invoke->GetLocations(), true, GetAssembler()); |
| 167 | } |
| 168 | |
| 169 | // int java.lang.Float.floatToRawIntBits(float) |
| 170 | void IntrinsicLocationsBuilderMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 171 | CreateFPToIntLocations(arena_, invoke); |
| 172 | } |
| 173 | |
| 174 | void IntrinsicCodeGeneratorMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 175 | MoveFPToInt(invoke->GetLocations(), false, GetAssembler()); |
| 176 | } |
| 177 | |
| 178 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 179 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 180 | LocationSummary::kNoCall, |
| 181 | kIntrinsified); |
| 182 | locations->SetInAt(0, Location::RequiresRegister()); |
| 183 | locations->SetOut(Location::RequiresFpuRegister()); |
| 184 | } |
| 185 | |
| 186 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 187 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 188 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 189 | |
| 190 | if (is64bit) { |
| 191 | __ Dmtc1(in, out); |
| 192 | } else { |
| 193 | __ Mtc1(in, out); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // double java.lang.Double.longBitsToDouble(long) |
| 198 | void IntrinsicLocationsBuilderMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 199 | CreateIntToFPLocations(arena_, invoke); |
| 200 | } |
| 201 | |
| 202 | void IntrinsicCodeGeneratorMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 203 | MoveIntToFP(invoke->GetLocations(), true, GetAssembler()); |
| 204 | } |
| 205 | |
| 206 | // float java.lang.Float.intBitsToFloat(int) |
| 207 | void IntrinsicLocationsBuilderMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 208 | CreateIntToFPLocations(arena_, invoke); |
| 209 | } |
| 210 | |
| 211 | void IntrinsicCodeGeneratorMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 212 | MoveIntToFP(invoke->GetLocations(), false, GetAssembler()); |
| 213 | } |
| 214 | |
| 215 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 216 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 217 | LocationSummary::kNoCall, |
| 218 | kIntrinsified); |
| 219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 220 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 221 | } |
| 222 | |
| 223 | static void GenReverseBytes(LocationSummary* locations, |
| 224 | Primitive::Type type, |
| 225 | Mips64Assembler* assembler) { |
| 226 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 227 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 228 | |
| 229 | switch (type) { |
| 230 | case Primitive::kPrimShort: |
| 231 | __ Dsbh(out, in); |
| 232 | __ Seh(out, out); |
| 233 | break; |
| 234 | case Primitive::kPrimInt: |
| 235 | __ Rotr(out, in, 16); |
| 236 | __ Wsbh(out, out); |
| 237 | break; |
| 238 | case Primitive::kPrimLong: |
| 239 | __ Dsbh(out, in); |
| 240 | __ Dshd(out, out); |
| 241 | break; |
| 242 | default: |
| 243 | LOG(FATAL) << "Unexpected size for reverse-bytes: " << type; |
| 244 | UNREACHABLE(); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // int java.lang.Integer.reverseBytes(int) |
| 249 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 250 | CreateIntToIntLocations(arena_, invoke); |
| 251 | } |
| 252 | |
| 253 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 254 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 255 | } |
| 256 | |
| 257 | // long java.lang.Long.reverseBytes(long) |
| 258 | void IntrinsicLocationsBuilderMIPS64::VisitLongReverseBytes(HInvoke* invoke) { |
| 259 | CreateIntToIntLocations(arena_, invoke); |
| 260 | } |
| 261 | |
| 262 | void IntrinsicCodeGeneratorMIPS64::VisitLongReverseBytes(HInvoke* invoke) { |
| 263 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 264 | } |
| 265 | |
| 266 | // short java.lang.Short.reverseBytes(short) |
| 267 | void IntrinsicLocationsBuilderMIPS64::VisitShortReverseBytes(HInvoke* invoke) { |
| 268 | CreateIntToIntLocations(arena_, invoke); |
| 269 | } |
| 270 | |
| 271 | void IntrinsicCodeGeneratorMIPS64::VisitShortReverseBytes(HInvoke* invoke) { |
| 272 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetAssembler()); |
| 273 | } |
| 274 | |
| 275 | static void GenCountZeroes(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 276 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 277 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 278 | |
| 279 | if (is64bit) { |
| 280 | __ Dclz(out, in); |
| 281 | } else { |
| 282 | __ Clz(out, in); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // int java.lang.Integer.numberOfLeadingZeros(int i) |
| 287 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 288 | CreateIntToIntLocations(arena_, invoke); |
| 289 | } |
| 290 | |
| 291 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 292 | GenCountZeroes(invoke->GetLocations(), false, GetAssembler()); |
| 293 | } |
| 294 | |
| 295 | // int java.lang.Long.numberOfLeadingZeros(long i) |
| 296 | void IntrinsicLocationsBuilderMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 297 | CreateIntToIntLocations(arena_, invoke); |
| 298 | } |
| 299 | |
| 300 | void IntrinsicCodeGeneratorMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 301 | GenCountZeroes(invoke->GetLocations(), true, GetAssembler()); |
| 302 | } |
| 303 | |
| 304 | static void GenReverse(LocationSummary* locations, |
| 305 | Primitive::Type type, |
| 306 | Mips64Assembler* assembler) { |
| 307 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 308 | |
| 309 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 310 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 311 | |
| 312 | if (type == Primitive::kPrimInt) { |
| 313 | __ Rotr(out, in, 16); |
| 314 | __ Wsbh(out, out); |
| 315 | __ Bitswap(out, out); |
| 316 | } else { |
| 317 | __ Dsbh(out, in); |
| 318 | __ Dshd(out, out); |
| 319 | __ Dbitswap(out, out); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // int java.lang.Integer.reverse(int) |
| 324 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverse(HInvoke* invoke) { |
| 325 | CreateIntToIntLocations(arena_, invoke); |
| 326 | } |
| 327 | |
| 328 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverse(HInvoke* invoke) { |
| 329 | GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 330 | } |
| 331 | |
| 332 | // long java.lang.Long.reverse(long) |
| 333 | void IntrinsicLocationsBuilderMIPS64::VisitLongReverse(HInvoke* invoke) { |
| 334 | CreateIntToIntLocations(arena_, invoke); |
| 335 | } |
| 336 | |
| 337 | void IntrinsicCodeGeneratorMIPS64::VisitLongReverse(HInvoke* invoke) { |
| 338 | GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 339 | } |
| 340 | |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 341 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 342 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 343 | LocationSummary::kNoCall, |
| 344 | kIntrinsified); |
| 345 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 346 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 347 | } |
| 348 | |
| 349 | static void MathAbsFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 350 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 351 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 352 | |
| 353 | if (is64bit) { |
| 354 | __ AbsD(out, in); |
| 355 | } else { |
| 356 | __ AbsS(out, in); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // double java.lang.Math.abs(double) |
| 361 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsDouble(HInvoke* invoke) { |
| 362 | CreateFPToFPLocations(arena_, invoke); |
| 363 | } |
| 364 | |
| 365 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsDouble(HInvoke* invoke) { |
| 366 | MathAbsFP(invoke->GetLocations(), true, GetAssembler()); |
| 367 | } |
| 368 | |
| 369 | // float java.lang.Math.abs(float) |
| 370 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsFloat(HInvoke* invoke) { |
| 371 | CreateFPToFPLocations(arena_, invoke); |
| 372 | } |
| 373 | |
| 374 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsFloat(HInvoke* invoke) { |
| 375 | MathAbsFP(invoke->GetLocations(), false, GetAssembler()); |
| 376 | } |
| 377 | |
| 378 | static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) { |
| 379 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 380 | LocationSummary::kNoCall, |
| 381 | kIntrinsified); |
| 382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 383 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 384 | } |
| 385 | |
| 386 | static void GenAbsInteger(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 387 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 388 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 389 | |
| 390 | if (is64bit) { |
| 391 | __ Dsra32(AT, in, 31); |
| 392 | __ Xor(out, in, AT); |
| 393 | __ Dsubu(out, out, AT); |
| 394 | } else { |
| 395 | __ Sra(AT, in, 31); |
| 396 | __ Xor(out, in, AT); |
| 397 | __ Subu(out, out, AT); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // int java.lang.Math.abs(int) |
| 402 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsInt(HInvoke* invoke) { |
| 403 | CreateIntToInt(arena_, invoke); |
| 404 | } |
| 405 | |
| 406 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsInt(HInvoke* invoke) { |
| 407 | GenAbsInteger(invoke->GetLocations(), false, GetAssembler()); |
| 408 | } |
| 409 | |
| 410 | // long java.lang.Math.abs(long) |
| 411 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsLong(HInvoke* invoke) { |
| 412 | CreateIntToInt(arena_, invoke); |
| 413 | } |
| 414 | |
| 415 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsLong(HInvoke* invoke) { |
| 416 | GenAbsInteger(invoke->GetLocations(), true, GetAssembler()); |
| 417 | } |
| 418 | |
| 419 | static void GenMinMaxFP(LocationSummary* locations, |
| 420 | bool is_min, |
| 421 | bool is_double, |
| 422 | Mips64Assembler* assembler) { |
| 423 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 424 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 425 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 426 | |
| 427 | if (is_double) { |
| 428 | if (is_min) { |
| 429 | __ MinD(out, lhs, rhs); |
| 430 | } else { |
| 431 | __ MaxD(out, lhs, rhs); |
| 432 | } |
| 433 | } else { |
| 434 | if (is_min) { |
| 435 | __ MinS(out, lhs, rhs); |
| 436 | } else { |
| 437 | __ MaxS(out, lhs, rhs); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 443 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 444 | LocationSummary::kNoCall, |
| 445 | kIntrinsified); |
| 446 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 447 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 448 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 449 | } |
| 450 | |
| 451 | // double java.lang.Math.min(double, double) |
| 452 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 453 | CreateFPFPToFPLocations(arena_, invoke); |
| 454 | } |
| 455 | |
| 456 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 457 | GenMinMaxFP(invoke->GetLocations(), true, true, GetAssembler()); |
| 458 | } |
| 459 | |
| 460 | // float java.lang.Math.min(float, float) |
| 461 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 462 | CreateFPFPToFPLocations(arena_, invoke); |
| 463 | } |
| 464 | |
| 465 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 466 | GenMinMaxFP(invoke->GetLocations(), true, false, GetAssembler()); |
| 467 | } |
| 468 | |
| 469 | // double java.lang.Math.max(double, double) |
| 470 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 471 | CreateFPFPToFPLocations(arena_, invoke); |
| 472 | } |
| 473 | |
| 474 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 475 | GenMinMaxFP(invoke->GetLocations(), false, true, GetAssembler()); |
| 476 | } |
| 477 | |
| 478 | // float java.lang.Math.max(float, float) |
| 479 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 480 | CreateFPFPToFPLocations(arena_, invoke); |
| 481 | } |
| 482 | |
| 483 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 484 | GenMinMaxFP(invoke->GetLocations(), false, false, GetAssembler()); |
| 485 | } |
| 486 | |
| 487 | static void GenMinMax(LocationSummary* locations, |
| 488 | bool is_min, |
| 489 | Mips64Assembler* assembler) { |
| 490 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 491 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 492 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 493 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 494 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 495 | // conditional move instruction which only changes the target |
| 496 | // (output) register if the condition is true (MIPS prior to r6 had |
| 497 | // MOVF, MOVT, and MOVZ). The SELEQZ and SELNEZ instructions always |
| 498 | // change the target (output) register. If the condition is true the |
| 499 | // output register gets the contents of the "rs" register; otherwise, |
| 500 | // the output register is set to zero. One consequence of this is |
| 501 | // that to implement something like "rd = c==0 ? rs : rt" MIPS64r6 |
| 502 | // needs to use a pair of SELEQZ/SELNEZ instructions. After |
| 503 | // executing this pair of instructions one of the output registers |
| 504 | // from the pair will necessarily contain zero. Then the code ORs the |
| 505 | // output registers from the SELEQZ/SELNEZ instructions to get the |
| 506 | // final result. |
| 507 | // |
| 508 | // The initial test to see if the output register is same as the |
| 509 | // first input register is needed to make sure that value in the |
| 510 | // first input register isn't clobbered before we've finished |
| 511 | // computing the output value. The logic in the corresponding else |
| 512 | // clause performs the same task but makes sure the second input |
| 513 | // register isn't clobbered in the event that it's the same register |
| 514 | // as the output register; the else clause also handles the case |
| 515 | // where the output register is distinct from both the first, and the |
| 516 | // second input registers. |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 517 | if (out == lhs) { |
| 518 | __ Slt(AT, rhs, lhs); |
| 519 | if (is_min) { |
| 520 | __ Seleqz(out, lhs, AT); |
| 521 | __ Selnez(AT, rhs, AT); |
| 522 | } else { |
| 523 | __ Selnez(out, lhs, AT); |
| 524 | __ Seleqz(AT, rhs, AT); |
| 525 | } |
| 526 | } else { |
| 527 | __ Slt(AT, lhs, rhs); |
| 528 | if (is_min) { |
| 529 | __ Seleqz(out, rhs, AT); |
| 530 | __ Selnez(AT, lhs, AT); |
| 531 | } else { |
| 532 | __ Selnez(out, rhs, AT); |
| 533 | __ Seleqz(AT, lhs, AT); |
| 534 | } |
| 535 | } |
| 536 | __ Or(out, out, AT); |
| 537 | } |
| 538 | |
| 539 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 540 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 541 | LocationSummary::kNoCall, |
| 542 | kIntrinsified); |
| 543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 544 | locations->SetInAt(1, Location::RequiresRegister()); |
| 545 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 546 | } |
| 547 | |
| 548 | // int java.lang.Math.min(int, int) |
| 549 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinIntInt(HInvoke* invoke) { |
| 550 | CreateIntIntToIntLocations(arena_, invoke); |
| 551 | } |
| 552 | |
| 553 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinIntInt(HInvoke* invoke) { |
| 554 | GenMinMax(invoke->GetLocations(), true, GetAssembler()); |
| 555 | } |
| 556 | |
| 557 | // long java.lang.Math.min(long, long) |
| 558 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinLongLong(HInvoke* invoke) { |
| 559 | CreateIntIntToIntLocations(arena_, invoke); |
| 560 | } |
| 561 | |
| 562 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinLongLong(HInvoke* invoke) { |
| 563 | GenMinMax(invoke->GetLocations(), true, GetAssembler()); |
| 564 | } |
| 565 | |
| 566 | // int java.lang.Math.max(int, int) |
| 567 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 568 | CreateIntIntToIntLocations(arena_, invoke); |
| 569 | } |
| 570 | |
| 571 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 572 | GenMinMax(invoke->GetLocations(), false, GetAssembler()); |
| 573 | } |
| 574 | |
| 575 | // long java.lang.Math.max(long, long) |
| 576 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 577 | CreateIntIntToIntLocations(arena_, invoke); |
| 578 | } |
| 579 | |
| 580 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 581 | GenMinMax(invoke->GetLocations(), false, GetAssembler()); |
| 582 | } |
| 583 | |
| 584 | // double java.lang.Math.sqrt(double) |
| 585 | void IntrinsicLocationsBuilderMIPS64::VisitMathSqrt(HInvoke* invoke) { |
| 586 | CreateFPToFPLocations(arena_, invoke); |
| 587 | } |
| 588 | |
| 589 | void IntrinsicCodeGeneratorMIPS64::VisitMathSqrt(HInvoke* invoke) { |
| 590 | LocationSummary* locations = invoke->GetLocations(); |
| 591 | Mips64Assembler* assembler = GetAssembler(); |
| 592 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 593 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 594 | |
| 595 | __ SqrtD(out, in); |
| 596 | } |
| 597 | |
| 598 | static void CreateFPToFP(ArenaAllocator* arena, HInvoke* invoke) { |
| 599 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 600 | LocationSummary::kNoCall, |
| 601 | kIntrinsified); |
| 602 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 603 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 604 | } |
| 605 | |
| 606 | // double java.lang.Math.rint(double) |
| 607 | void IntrinsicLocationsBuilderMIPS64::VisitMathRint(HInvoke* invoke) { |
| 608 | CreateFPToFP(arena_, invoke); |
| 609 | } |
| 610 | |
| 611 | void IntrinsicCodeGeneratorMIPS64::VisitMathRint(HInvoke* invoke) { |
| 612 | LocationSummary* locations = invoke->GetLocations(); |
| 613 | Mips64Assembler* assembler = GetAssembler(); |
| 614 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 615 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 616 | |
| 617 | __ RintD(out, in); |
| 618 | } |
| 619 | |
| 620 | // double java.lang.Math.floor(double) |
| 621 | void IntrinsicLocationsBuilderMIPS64::VisitMathFloor(HInvoke* invoke) { |
| 622 | CreateFPToFP(arena_, invoke); |
| 623 | } |
| 624 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 625 | const constexpr uint16_t kFPLeaveUnchanged = kPositiveZero | |
| 626 | kPositiveInfinity | |
| 627 | kNegativeZero | |
| 628 | kNegativeInfinity | |
| 629 | kQuietNaN | |
| 630 | kSignalingNaN; |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 631 | |
| 632 | void IntrinsicCodeGeneratorMIPS64::VisitMathFloor(HInvoke* invoke) { |
| 633 | LocationSummary* locations = invoke->GetLocations(); |
| 634 | Mips64Assembler* assembler = GetAssembler(); |
| 635 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 636 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 637 | |
| 638 | Label done; |
| 639 | |
| 640 | // double floor(double in) { |
| 641 | // if in.isNaN || in.isInfinite || in.isZero { |
| 642 | // return in; |
| 643 | // } |
| 644 | __ ClassD(out, in); |
| 645 | __ Dmfc1(AT, out); |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 646 | __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 647 | __ MovD(out, in); |
| 648 | __ Bnezc(AT, &done); |
| 649 | |
| 650 | // Long outLong = floor(in); |
| 651 | // if outLong == Long.MAX_VALUE { |
| 652 | // // floor() has almost certainly returned a value which |
| 653 | // // can't be successfully represented as a signed 64-bit |
| 654 | // // number. Java expects that the input value will be |
| 655 | // // returned in these cases. |
| 656 | // // There is also a small probability that floor(in) |
| 657 | // // correctly truncates the input value to Long.MAX_VALUE. In |
| 658 | // // that case, this exception handling code still does the |
| 659 | // // correct thing. |
| 660 | // return in; |
| 661 | // } |
| 662 | __ FloorLD(out, in); |
| 663 | __ Dmfc1(AT, out); |
| 664 | __ MovD(out, in); |
| 665 | __ LoadConst64(TMP, kPrimLongMax); |
| 666 | __ Beqc(AT, TMP, &done); |
| 667 | |
| 668 | // double out = outLong; |
| 669 | // return out; |
| 670 | __ Dmtc1(AT, out); |
| 671 | __ Cvtdl(out, out); |
| 672 | __ Bind(&done); |
| 673 | // } |
| 674 | } |
| 675 | |
| 676 | // double java.lang.Math.ceil(double) |
| 677 | void IntrinsicLocationsBuilderMIPS64::VisitMathCeil(HInvoke* invoke) { |
| 678 | CreateFPToFP(arena_, invoke); |
| 679 | } |
| 680 | |
| 681 | void IntrinsicCodeGeneratorMIPS64::VisitMathCeil(HInvoke* invoke) { |
| 682 | LocationSummary* locations = invoke->GetLocations(); |
| 683 | Mips64Assembler* assembler = GetAssembler(); |
| 684 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 685 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 686 | |
| 687 | Label done; |
| 688 | |
| 689 | // double ceil(double in) { |
| 690 | // if in.isNaN || in.isInfinite || in.isZero { |
| 691 | // return in; |
| 692 | // } |
| 693 | __ ClassD(out, in); |
| 694 | __ Dmfc1(AT, out); |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 695 | __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 696 | __ MovD(out, in); |
| 697 | __ Bnezc(AT, &done); |
| 698 | |
| 699 | // Long outLong = ceil(in); |
| 700 | // if outLong == Long.MAX_VALUE { |
| 701 | // // ceil() has almost certainly returned a value which |
| 702 | // // can't be successfully represented as a signed 64-bit |
| 703 | // // number. Java expects that the input value will be |
| 704 | // // returned in these cases. |
| 705 | // // There is also a small probability that ceil(in) |
| 706 | // // correctly rounds up the input value to Long.MAX_VALUE. In |
| 707 | // // that case, this exception handling code still does the |
| 708 | // // correct thing. |
| 709 | // return in; |
| 710 | // } |
| 711 | __ CeilLD(out, in); |
| 712 | __ Dmfc1(AT, out); |
| 713 | __ MovD(out, in); |
| 714 | __ LoadConst64(TMP, kPrimLongMax); |
| 715 | __ Beqc(AT, TMP, &done); |
| 716 | |
| 717 | // double out = outLong; |
| 718 | // return out; |
| 719 | __ Dmtc1(AT, out); |
| 720 | __ Cvtdl(out, out); |
| 721 | __ Bind(&done); |
| 722 | // } |
| 723 | } |
| 724 | |
Chris Larsen | 70fb1f4 | 2015-09-04 10:15:27 -0700 | [diff] [blame] | 725 | // byte libcore.io.Memory.peekByte(long address) |
| 726 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 727 | CreateIntToIntLocations(arena_, invoke); |
| 728 | } |
| 729 | |
| 730 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 731 | Mips64Assembler* assembler = GetAssembler(); |
| 732 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 733 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 734 | |
| 735 | __ Lb(out, adr, 0); |
| 736 | } |
| 737 | |
| 738 | // short libcore.io.Memory.peekShort(long address) |
| 739 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 740 | CreateIntToIntLocations(arena_, invoke); |
| 741 | } |
| 742 | |
| 743 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 744 | Mips64Assembler* assembler = GetAssembler(); |
| 745 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 746 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 747 | |
| 748 | __ Lh(out, adr, 0); |
| 749 | } |
| 750 | |
| 751 | // int libcore.io.Memory.peekInt(long address) |
| 752 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 753 | CreateIntToIntLocations(arena_, invoke); |
| 754 | } |
| 755 | |
| 756 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 757 | Mips64Assembler* assembler = GetAssembler(); |
| 758 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 759 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 760 | |
| 761 | __ Lw(out, adr, 0); |
| 762 | } |
| 763 | |
| 764 | // long libcore.io.Memory.peekLong(long address) |
| 765 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 766 | CreateIntToIntLocations(arena_, invoke); |
| 767 | } |
| 768 | |
| 769 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 770 | Mips64Assembler* assembler = GetAssembler(); |
| 771 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 772 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 773 | |
| 774 | __ Ld(out, adr, 0); |
| 775 | } |
| 776 | |
| 777 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 778 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 779 | LocationSummary::kNoCall, |
| 780 | kIntrinsified); |
| 781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 782 | locations->SetInAt(1, Location::RequiresRegister()); |
| 783 | } |
| 784 | |
| 785 | // void libcore.io.Memory.pokeByte(long address, byte value) |
| 786 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 787 | CreateIntIntToVoidLocations(arena_, invoke); |
| 788 | } |
| 789 | |
| 790 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 791 | Mips64Assembler* assembler = GetAssembler(); |
| 792 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 793 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 794 | |
| 795 | __ Sb(val, adr, 0); |
| 796 | } |
| 797 | |
| 798 | // void libcore.io.Memory.pokeShort(long address, short value) |
| 799 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 800 | CreateIntIntToVoidLocations(arena_, invoke); |
| 801 | } |
| 802 | |
| 803 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 804 | Mips64Assembler* assembler = GetAssembler(); |
| 805 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 806 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 807 | |
| 808 | __ Sh(val, adr, 0); |
| 809 | } |
| 810 | |
| 811 | // void libcore.io.Memory.pokeInt(long address, int value) |
| 812 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 813 | CreateIntIntToVoidLocations(arena_, invoke); |
| 814 | } |
| 815 | |
| 816 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 817 | Mips64Assembler* assembler = GetAssembler(); |
| 818 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 819 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 820 | |
| 821 | __ Sw(val, adr, 00); |
| 822 | } |
| 823 | |
| 824 | // void libcore.io.Memory.pokeLong(long address, long value) |
| 825 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 826 | CreateIntIntToVoidLocations(arena_, invoke); |
| 827 | } |
| 828 | |
| 829 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 830 | Mips64Assembler* assembler = GetAssembler(); |
| 831 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 832 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 833 | |
| 834 | __ Sd(val, adr, 0); |
| 835 | } |
| 836 | |
Chris Larsen | 49e5539 | 2015-09-04 16:04:03 -0700 | [diff] [blame] | 837 | // Thread java.lang.Thread.currentThread() |
| 838 | void IntrinsicLocationsBuilderMIPS64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 839 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 840 | LocationSummary::kNoCall, |
| 841 | kIntrinsified); |
| 842 | locations->SetOut(Location::RequiresRegister()); |
| 843 | } |
| 844 | |
| 845 | void IntrinsicCodeGeneratorMIPS64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 846 | Mips64Assembler* assembler = GetAssembler(); |
| 847 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 848 | |
| 849 | __ LoadFromOffset(kLoadUnsignedWord, |
| 850 | out, |
| 851 | TR, |
| 852 | Thread::PeerOffset<kMips64PointerSize>().Int32Value()); |
| 853 | } |
| 854 | |
Chris Larsen | 1360ada | 2015-09-04 23:38:16 -0700 | [diff] [blame^] | 855 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 856 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 857 | LocationSummary::kNoCall, |
| 858 | kIntrinsified); |
| 859 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 860 | locations->SetInAt(1, Location::RequiresRegister()); |
| 861 | locations->SetInAt(2, Location::RequiresRegister()); |
| 862 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 863 | } |
| 864 | |
| 865 | static void GenUnsafeGet(HInvoke* invoke, |
| 866 | Primitive::Type type, |
| 867 | bool is_volatile, |
| 868 | CodeGeneratorMIPS64* codegen) { |
| 869 | LocationSummary* locations = invoke->GetLocations(); |
| 870 | DCHECK((type == Primitive::kPrimInt) || |
| 871 | (type == Primitive::kPrimLong) || |
| 872 | (type == Primitive::kPrimNot)); |
| 873 | Mips64Assembler* assembler = codegen->GetAssembler(); |
| 874 | // Object pointer. |
| 875 | GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>(); |
| 876 | // Long offset. |
| 877 | GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>(); |
| 878 | GpuRegister trg = locations->Out().AsRegister<GpuRegister>(); |
| 879 | |
| 880 | __ Daddu(TMP, base, offset); |
| 881 | if (is_volatile) { |
| 882 | __ Sync(0); |
| 883 | } |
| 884 | switch (type) { |
| 885 | case Primitive::kPrimInt: |
| 886 | __ Lw(trg, TMP, 0); |
| 887 | break; |
| 888 | |
| 889 | case Primitive::kPrimNot: |
| 890 | __ Lwu(trg, TMP, 0); |
| 891 | break; |
| 892 | |
| 893 | case Primitive::kPrimLong: |
| 894 | __ Ld(trg, TMP, 0); |
| 895 | break; |
| 896 | |
| 897 | default: |
| 898 | LOG(FATAL) << "Unsupported op size " << type; |
| 899 | UNREACHABLE(); |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | // int sun.misc.Unsafe.getInt(Object o, long offset) |
| 904 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGet(HInvoke* invoke) { |
| 905 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 906 | } |
| 907 | |
| 908 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGet(HInvoke* invoke) { |
| 909 | GenUnsafeGet(invoke, Primitive::kPrimInt, false, codegen_); |
| 910 | } |
| 911 | |
| 912 | // int sun.misc.Unsafe.getIntVolatile(Object o, long offset) |
| 913 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 914 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 915 | } |
| 916 | |
| 917 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 918 | GenUnsafeGet(invoke, Primitive::kPrimInt, true, codegen_); |
| 919 | } |
| 920 | |
| 921 | // long sun.misc.Unsafe.getLong(Object o, long offset) |
| 922 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetLong(HInvoke* invoke) { |
| 923 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 924 | } |
| 925 | |
| 926 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetLong(HInvoke* invoke) { |
| 927 | GenUnsafeGet(invoke, Primitive::kPrimLong, false, codegen_); |
| 928 | } |
| 929 | |
| 930 | // long sun.misc.Unsafe.getLongVolatile(Object o, long offset) |
| 931 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 932 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 933 | } |
| 934 | |
| 935 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 936 | GenUnsafeGet(invoke, Primitive::kPrimLong, true, codegen_); |
| 937 | } |
| 938 | |
| 939 | // Object sun.misc.Unsafe.getObject(Object o, long offset) |
| 940 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetObject(HInvoke* invoke) { |
| 941 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 942 | } |
| 943 | |
| 944 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetObject(HInvoke* invoke) { |
| 945 | GenUnsafeGet(invoke, Primitive::kPrimNot, false, codegen_); |
| 946 | } |
| 947 | |
| 948 | // Object sun.misc.Unsafe.getObjectVolatile(Object o, long offset) |
| 949 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 950 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 951 | } |
| 952 | |
| 953 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 954 | GenUnsafeGet(invoke, Primitive::kPrimNot, true, codegen_); |
| 955 | } |
| 956 | |
| 957 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, HInvoke* invoke) { |
| 958 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 959 | LocationSummary::kNoCall, |
| 960 | kIntrinsified); |
| 961 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 962 | locations->SetInAt(1, Location::RequiresRegister()); |
| 963 | locations->SetInAt(2, Location::RequiresRegister()); |
| 964 | locations->SetInAt(3, Location::RequiresRegister()); |
| 965 | } |
| 966 | |
| 967 | static void GenUnsafePut(LocationSummary* locations, |
| 968 | Primitive::Type type, |
| 969 | bool is_volatile, |
| 970 | bool is_ordered, |
| 971 | CodeGeneratorMIPS64* codegen) { |
| 972 | DCHECK((type == Primitive::kPrimInt) || |
| 973 | (type == Primitive::kPrimLong) || |
| 974 | (type == Primitive::kPrimNot)); |
| 975 | Mips64Assembler* assembler = codegen->GetAssembler(); |
| 976 | // Object pointer. |
| 977 | GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>(); |
| 978 | // Long offset. |
| 979 | GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>(); |
| 980 | GpuRegister value = locations->InAt(3).AsRegister<GpuRegister>(); |
| 981 | |
| 982 | __ Daddu(TMP, base, offset); |
| 983 | if (is_volatile || is_ordered) { |
| 984 | __ Sync(0); |
| 985 | } |
| 986 | switch (type) { |
| 987 | case Primitive::kPrimInt: |
| 988 | case Primitive::kPrimNot: |
| 989 | __ Sw(value, TMP, 0); |
| 990 | break; |
| 991 | |
| 992 | case Primitive::kPrimLong: |
| 993 | __ Sd(value, TMP, 0); |
| 994 | break; |
| 995 | |
| 996 | default: |
| 997 | LOG(FATAL) << "Unsupported op size " << type; |
| 998 | UNREACHABLE(); |
| 999 | } |
| 1000 | if (is_volatile) { |
| 1001 | __ Sync(0); |
| 1002 | } |
| 1003 | |
| 1004 | if (type == Primitive::kPrimNot) { |
| 1005 | codegen->MarkGCCard(base, value); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | // void sun.misc.Unsafe.putInt(Object o, long offset, int x) |
| 1010 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePut(HInvoke* invoke) { |
| 1011 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1012 | } |
| 1013 | |
| 1014 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePut(HInvoke* invoke) { |
| 1015 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, false, codegen_); |
| 1016 | } |
| 1017 | |
| 1018 | // void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x) |
| 1019 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 1020 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1021 | } |
| 1022 | |
| 1023 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 1024 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, true, codegen_); |
| 1025 | } |
| 1026 | |
| 1027 | // void sun.misc.Unsafe.putIntVolatile(Object o, long offset, int x) |
| 1028 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 1029 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1030 | } |
| 1031 | |
| 1032 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 1033 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, true, false, codegen_); |
| 1034 | } |
| 1035 | |
| 1036 | // void sun.misc.Unsafe.putObject(Object o, long offset, Object x) |
| 1037 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObject(HInvoke* invoke) { |
| 1038 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1039 | } |
| 1040 | |
| 1041 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObject(HInvoke* invoke) { |
| 1042 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, false, codegen_); |
| 1043 | } |
| 1044 | |
| 1045 | // void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x) |
| 1046 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 1047 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1048 | } |
| 1049 | |
| 1050 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 1051 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, true, codegen_); |
| 1052 | } |
| 1053 | |
| 1054 | // void sun.misc.Unsafe.putObjectVolatile(Object o, long offset, Object x) |
| 1055 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 1056 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1057 | } |
| 1058 | |
| 1059 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 1060 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, true, false, codegen_); |
| 1061 | } |
| 1062 | |
| 1063 | // void sun.misc.Unsafe.putLong(Object o, long offset, long x) |
| 1064 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLong(HInvoke* invoke) { |
| 1065 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1066 | } |
| 1067 | |
| 1068 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLong(HInvoke* invoke) { |
| 1069 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, false, codegen_); |
| 1070 | } |
| 1071 | |
| 1072 | // void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x) |
| 1073 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 1074 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1075 | } |
| 1076 | |
| 1077 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 1078 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, true, codegen_); |
| 1079 | } |
| 1080 | |
| 1081 | // void sun.misc.Unsafe.putLongVolatile(Object o, long offset, long x) |
| 1082 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 1083 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1084 | } |
| 1085 | |
| 1086 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 1087 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, true, false, codegen_); |
| 1088 | } |
| 1089 | |
Chris Larsen | 9701c2e | 2015-09-04 17:22:47 -0700 | [diff] [blame] | 1090 | // char java.lang.String.charAt(int index) |
| 1091 | void IntrinsicLocationsBuilderMIPS64::VisitStringCharAt(HInvoke* invoke) { |
| 1092 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1093 | LocationSummary::kCallOnSlowPath, |
| 1094 | kIntrinsified); |
| 1095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1096 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1097 | locations->SetOut(Location::SameAsFirstInput()); |
| 1098 | } |
| 1099 | |
| 1100 | void IntrinsicCodeGeneratorMIPS64::VisitStringCharAt(HInvoke* invoke) { |
| 1101 | LocationSummary* locations = invoke->GetLocations(); |
| 1102 | Mips64Assembler* assembler = GetAssembler(); |
| 1103 | |
| 1104 | // Location of reference to data array |
| 1105 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1106 | // Location of count |
| 1107 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1108 | |
| 1109 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1110 | GpuRegister idx = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1111 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1112 | |
| 1113 | // TODO: Maybe we can support range check elimination. Overall, |
| 1114 | // though, I think it's not worth the cost. |
| 1115 | // TODO: For simplicity, the index parameter is requested in a |
| 1116 | // register, so different from Quick we will not optimize the |
| 1117 | // code for constants (which would save a register). |
| 1118 | |
| 1119 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1120 | codegen_->AddSlowPath(slow_path); |
| 1121 | |
| 1122 | // Load the string size |
| 1123 | __ Lw(TMP, obj, count_offset); |
| 1124 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1125 | // Revert to slow path if idx is too large, or negative |
| 1126 | __ Bgeuc(idx, TMP, slow_path->GetEntryLabel()); |
| 1127 | |
| 1128 | // out = obj[2*idx]. |
| 1129 | __ Sll(TMP, idx, 1); // idx * 2 |
| 1130 | __ Daddu(TMP, TMP, obj); // Address of char at location idx |
| 1131 | __ Lhu(out, TMP, value_offset); // Load char at location idx |
| 1132 | |
| 1133 | __ Bind(slow_path->GetExitLabel()); |
| 1134 | } |
| 1135 | |
| 1136 | // int java.lang.String.compareTo(String anotherString) |
| 1137 | void IntrinsicLocationsBuilderMIPS64::VisitStringCompareTo(HInvoke* invoke) { |
| 1138 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1139 | LocationSummary::kCall, |
| 1140 | kIntrinsified); |
| 1141 | InvokeRuntimeCallingConvention calling_convention; |
| 1142 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1143 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1144 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1145 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1146 | } |
| 1147 | |
| 1148 | void IntrinsicCodeGeneratorMIPS64::VisitStringCompareTo(HInvoke* invoke) { |
| 1149 | Mips64Assembler* assembler = GetAssembler(); |
| 1150 | LocationSummary* locations = invoke->GetLocations(); |
| 1151 | |
| 1152 | // Note that the null check must have been done earlier. |
| 1153 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1154 | |
| 1155 | GpuRegister argument = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1156 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1157 | codegen_->AddSlowPath(slow_path); |
| 1158 | __ Beqzc(argument, slow_path->GetEntryLabel()); |
| 1159 | |
| 1160 | __ LoadFromOffset(kLoadDoubleword, |
| 1161 | TMP, |
| 1162 | TR, |
| 1163 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, |
| 1164 | pStringCompareTo).Int32Value()); |
| 1165 | __ Jalr(TMP); |
| 1166 | __ Nop(); |
| 1167 | __ Bind(slow_path->GetExitLabel()); |
| 1168 | } |
| 1169 | |
| 1170 | static void GenerateStringIndexOf(HInvoke* invoke, |
| 1171 | Mips64Assembler* assembler, |
| 1172 | CodeGeneratorMIPS64* codegen, |
| 1173 | ArenaAllocator* allocator, |
| 1174 | bool start_at_zero) { |
| 1175 | LocationSummary* locations = invoke->GetLocations(); |
| 1176 | GpuRegister tmp_reg = start_at_zero ? locations->GetTemp(0).AsRegister<GpuRegister>() : TMP; |
| 1177 | |
| 1178 | // Note that the null check must have been done earlier. |
| 1179 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1180 | |
| 1181 | // Check for code points > 0xFFFF. Either a slow-path check when we |
| 1182 | // don't know statically, or directly dispatch if we have a constant. |
| 1183 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 1184 | if (invoke->InputAt(1)->IsIntConstant()) { |
| 1185 | if (!IsUint<16>(invoke->InputAt(1)->AsIntConstant()->GetValue())) { |
| 1186 | // Always needs the slow-path. We could directly dispatch to it, |
| 1187 | // but this case should be rare, so for simplicity just put the |
| 1188 | // full slow-path down and branch unconditionally. |
| 1189 | slow_path = new (allocator) IntrinsicSlowPathMIPS64(invoke); |
| 1190 | codegen->AddSlowPath(slow_path); |
| 1191 | __ B(slow_path->GetEntryLabel()); |
| 1192 | __ Bind(slow_path->GetExitLabel()); |
| 1193 | return; |
| 1194 | } |
| 1195 | } else { |
| 1196 | GpuRegister char_reg = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1197 | __ LoadConst32(tmp_reg, std::numeric_limits<uint16_t>::max()); |
| 1198 | slow_path = new (allocator) IntrinsicSlowPathMIPS64(invoke); |
| 1199 | codegen->AddSlowPath(slow_path); |
| 1200 | __ Bltuc(tmp_reg, char_reg, slow_path->GetEntryLabel()); // UTF-16 required |
| 1201 | } |
| 1202 | |
| 1203 | if (start_at_zero) { |
| 1204 | DCHECK_EQ(tmp_reg, A2); |
| 1205 | // Start-index = 0. |
| 1206 | __ Clear(tmp_reg); |
| 1207 | } else { |
| 1208 | __ Slt(TMP, A2, ZERO); // if fromIndex < 0 |
| 1209 | __ Seleqz(A2, A2, TMP); // fromIndex = 0 |
| 1210 | } |
| 1211 | |
| 1212 | __ LoadFromOffset(kLoadDoubleword, |
| 1213 | TMP, |
| 1214 | TR, |
| 1215 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pIndexOf).Int32Value()); |
| 1216 | __ Jalr(TMP); |
| 1217 | __ Nop(); |
| 1218 | |
| 1219 | if (slow_path != nullptr) { |
| 1220 | __ Bind(slow_path->GetExitLabel()); |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | // int java.lang.String.indexOf(int ch) |
| 1225 | void IntrinsicLocationsBuilderMIPS64::VisitStringIndexOf(HInvoke* invoke) { |
| 1226 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1227 | LocationSummary::kCall, |
| 1228 | kIntrinsified); |
| 1229 | // We have a hand-crafted assembly stub that follows the runtime |
| 1230 | // calling convention. So it's best to align the inputs accordingly. |
| 1231 | InvokeRuntimeCallingConvention calling_convention; |
| 1232 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1233 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1234 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1235 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1236 | |
| 1237 | // Need a temp for slow-path codepoint compare, and need to send start-index=0. |
| 1238 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1239 | } |
| 1240 | |
| 1241 | void IntrinsicCodeGeneratorMIPS64::VisitStringIndexOf(HInvoke* invoke) { |
| 1242 | GenerateStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), true); |
| 1243 | } |
| 1244 | |
| 1245 | // int java.lang.String.indexOf(int ch, int fromIndex) |
| 1246 | void IntrinsicLocationsBuilderMIPS64::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1247 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1248 | LocationSummary::kCall, |
| 1249 | kIntrinsified); |
| 1250 | // We have a hand-crafted assembly stub that follows the runtime |
| 1251 | // calling convention. So it's best to align the inputs accordingly. |
| 1252 | InvokeRuntimeCallingConvention calling_convention; |
| 1253 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1254 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1255 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1256 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1257 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1258 | } |
| 1259 | |
| 1260 | void IntrinsicCodeGeneratorMIPS64::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1261 | GenerateStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), false); |
| 1262 | } |
| 1263 | |
| 1264 | // java.lang.String.String(byte[] bytes) |
| 1265 | void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1266 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1267 | LocationSummary::kCall, |
| 1268 | kIntrinsified); |
| 1269 | InvokeRuntimeCallingConvention calling_convention; |
| 1270 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1271 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1272 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1273 | locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 1274 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1275 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1276 | } |
| 1277 | |
| 1278 | void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1279 | Mips64Assembler* assembler = GetAssembler(); |
| 1280 | LocationSummary* locations = invoke->GetLocations(); |
| 1281 | |
| 1282 | GpuRegister byte_array = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1283 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1284 | codegen_->AddSlowPath(slow_path); |
| 1285 | __ Beqzc(byte_array, slow_path->GetEntryLabel()); |
| 1286 | |
| 1287 | __ LoadFromOffset(kLoadDoubleword, |
| 1288 | TMP, |
| 1289 | TR, |
| 1290 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromBytes).Int32Value()); |
| 1291 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1292 | __ Jalr(TMP); |
| 1293 | __ Nop(); |
| 1294 | __ Bind(slow_path->GetExitLabel()); |
| 1295 | } |
| 1296 | |
| 1297 | // java.lang.String.String(char[] value) |
| 1298 | void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1299 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1300 | LocationSummary::kCall, |
| 1301 | kIntrinsified); |
| 1302 | InvokeRuntimeCallingConvention calling_convention; |
| 1303 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1304 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1305 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1306 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1307 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1308 | } |
| 1309 | |
| 1310 | void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1311 | Mips64Assembler* assembler = GetAssembler(); |
| 1312 | |
| 1313 | __ LoadFromOffset(kLoadDoubleword, |
| 1314 | TMP, |
| 1315 | TR, |
| 1316 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromChars).Int32Value()); |
| 1317 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1318 | __ Jalr(TMP); |
| 1319 | __ Nop(); |
| 1320 | } |
| 1321 | |
| 1322 | // java.lang.String.String(String original) |
| 1323 | void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1324 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1325 | LocationSummary::kCall, |
| 1326 | kIntrinsified); |
| 1327 | InvokeRuntimeCallingConvention calling_convention; |
| 1328 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1329 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1330 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1331 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1332 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1333 | } |
| 1334 | |
| 1335 | void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1336 | Mips64Assembler* assembler = GetAssembler(); |
| 1337 | LocationSummary* locations = invoke->GetLocations(); |
| 1338 | |
| 1339 | GpuRegister string_to_copy = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1340 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1341 | codegen_->AddSlowPath(slow_path); |
| 1342 | __ Beqzc(string_to_copy, slow_path->GetEntryLabel()); |
| 1343 | |
| 1344 | __ LoadFromOffset(kLoadDoubleword, |
| 1345 | TMP, |
| 1346 | TR, |
| 1347 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromString).Int32Value()); |
| 1348 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1349 | __ Jalr(TMP); |
| 1350 | __ Nop(); |
| 1351 | __ Bind(slow_path->GetExitLabel()); |
| 1352 | } |
| 1353 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1354 | // Unimplemented intrinsics. |
| 1355 | |
| 1356 | #define UNIMPLEMENTED_INTRINSIC(Name) \ |
| 1357 | void IntrinsicLocationsBuilderMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 1358 | } \ |
| 1359 | void IntrinsicCodeGeneratorMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 1360 | } |
| 1361 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1362 | UNIMPLEMENTED_INTRINSIC(MathRoundDouble) |
| 1363 | UNIMPLEMENTED_INTRINSIC(MathRoundFloat) |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 1364 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1365 | UNIMPLEMENTED_INTRINSIC(UnsafeCASInt) |
| 1366 | UNIMPLEMENTED_INTRINSIC(UnsafeCASLong) |
| 1367 | UNIMPLEMENTED_INTRINSIC(UnsafeCASObject) |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1368 | UNIMPLEMENTED_INTRINSIC(StringEquals) |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1369 | UNIMPLEMENTED_INTRINSIC(LongRotateLeft) |
| 1370 | UNIMPLEMENTED_INTRINSIC(LongRotateRight) |
| 1371 | UNIMPLEMENTED_INTRINSIC(LongNumberOfTrailingZeros) |
| 1372 | UNIMPLEMENTED_INTRINSIC(IntegerRotateLeft) |
| 1373 | UNIMPLEMENTED_INTRINSIC(IntegerRotateRight) |
| 1374 | UNIMPLEMENTED_INTRINSIC(IntegerNumberOfTrailingZeros) |
| 1375 | |
| 1376 | UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent) |
| 1377 | UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck) |
| 1378 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar) |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1379 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopy) |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1380 | |
| 1381 | #undef UNIMPLEMENTED_INTRINSIC |
| 1382 | |
| 1383 | #undef __ |
| 1384 | |
| 1385 | } // namespace mips64 |
| 1386 | } // namespace art |