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 | |
Chris Larsen | 0646da7 | 2015-09-22 16:02:40 -0700 | [diff] [blame] | 275 | static void GenNumberOfLeadingZeroes(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 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) { |
Chris Larsen | 0646da7 | 2015-09-22 16:02:40 -0700 | [diff] [blame] | 292 | GenNumberOfLeadingZeroes(invoke->GetLocations(), false, GetAssembler()); |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 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) { |
Chris Larsen | 0646da7 | 2015-09-22 16:02:40 -0700 | [diff] [blame] | 301 | GenNumberOfLeadingZeroes(invoke->GetLocations(), true, GetAssembler()); |
| 302 | } |
| 303 | |
| 304 | static void GenNumberOfTrailingZeroes(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 305 | Location in = locations->InAt(0); |
| 306 | Location out = locations->Out(); |
| 307 | |
| 308 | if (is64bit) { |
| 309 | __ Dsbh(out.AsRegister<GpuRegister>(), in.AsRegister<GpuRegister>()); |
| 310 | __ Dshd(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>()); |
| 311 | __ Dbitswap(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>()); |
| 312 | __ Dclz(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>()); |
| 313 | } else { |
| 314 | __ Rotr(out.AsRegister<GpuRegister>(), in.AsRegister<GpuRegister>(), 16); |
| 315 | __ Wsbh(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>()); |
| 316 | __ Bitswap(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>()); |
| 317 | __ Clz(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>()); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // int java.lang.Integer.numberOfTrailingZeros(int i) |
| 322 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 323 | CreateIntToIntLocations(arena_, invoke); |
| 324 | } |
| 325 | |
| 326 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 327 | GenNumberOfTrailingZeroes(invoke->GetLocations(), false, GetAssembler()); |
| 328 | } |
| 329 | |
| 330 | // int java.lang.Long.numberOfTrailingZeros(long i) |
| 331 | void IntrinsicLocationsBuilderMIPS64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 332 | CreateIntToIntLocations(arena_, invoke); |
| 333 | } |
| 334 | |
| 335 | void IntrinsicCodeGeneratorMIPS64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 336 | GenNumberOfTrailingZeroes(invoke->GetLocations(), true, GetAssembler()); |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Chris Larsen | 9aebff2 | 2015-09-22 17:54:15 -0700 | [diff] [blame] | 339 | static void GenRotateRight(HInvoke* invoke, |
| 340 | Primitive::Type type, |
| 341 | Mips64Assembler* assembler) { |
| 342 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 343 | |
| 344 | LocationSummary* locations = invoke->GetLocations(); |
| 345 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 346 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 347 | |
| 348 | if (invoke->InputAt(1)->IsIntConstant()) { |
| 349 | uint32_t shift = static_cast<uint32_t>(invoke->InputAt(1)->AsIntConstant()->GetValue()); |
| 350 | if (type == Primitive::kPrimInt) { |
| 351 | shift &= 0x1f; |
| 352 | __ Rotr(out, in, shift); |
| 353 | } else { |
| 354 | shift &= 0x3f; |
| 355 | if (shift < 32) { |
| 356 | __ Drotr(out, in, shift); |
| 357 | } else { |
| 358 | shift &= 0x1f; |
| 359 | __ Drotr32(out, in, shift); |
| 360 | } |
| 361 | } |
| 362 | } else { |
| 363 | GpuRegister shamt = locations->InAt(1).AsRegister<GpuRegister>(); |
| 364 | if (type == Primitive::kPrimInt) { |
| 365 | __ Rotrv(out, in, shamt); |
| 366 | } else { |
| 367 | __ Drotrv(out, in, shamt); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | // int java.lang.Integer.rotateRight(int i, int distance) |
| 373 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerRotateRight(HInvoke* invoke) { |
| 374 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 375 | LocationSummary::kNoCall, |
| 376 | kIntrinsified); |
| 377 | locations->SetInAt(0, Location::RequiresRegister()); |
| 378 | locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1))); |
| 379 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 380 | } |
| 381 | |
| 382 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerRotateRight(HInvoke* invoke) { |
| 383 | GenRotateRight(invoke, Primitive::kPrimInt, GetAssembler()); |
| 384 | } |
| 385 | |
| 386 | // int java.lang.Long.rotateRight(long i, int distance) |
| 387 | void IntrinsicLocationsBuilderMIPS64::VisitLongRotateRight(HInvoke* invoke) { |
| 388 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 389 | LocationSummary::kNoCall, |
| 390 | kIntrinsified); |
| 391 | locations->SetInAt(0, Location::RequiresRegister()); |
| 392 | locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1))); |
| 393 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 394 | } |
| 395 | |
| 396 | void IntrinsicCodeGeneratorMIPS64::VisitLongRotateRight(HInvoke* invoke) { |
| 397 | GenRotateRight(invoke, Primitive::kPrimLong, GetAssembler()); |
| 398 | } |
| 399 | |
Chris Larsen | 0f8f864 | 2015-10-02 17:25:58 -0700 | [diff] [blame] | 400 | static void GenRotateLeft(HInvoke* invoke, |
| 401 | Primitive::Type type, |
| 402 | Mips64Assembler* assembler) { |
| 403 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 404 | |
| 405 | LocationSummary* locations = invoke->GetLocations(); |
| 406 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 407 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 408 | |
| 409 | if (invoke->InputAt(1)->IsIntConstant()) { |
| 410 | int32_t shift = -static_cast<int32_t>(invoke->InputAt(1)->AsIntConstant()->GetValue()); |
| 411 | if (type == Primitive::kPrimInt) { |
| 412 | shift &= 0x1f; |
| 413 | __ Rotr(out, in, shift); |
| 414 | } else { |
| 415 | shift &= 0x3f; |
| 416 | if (shift < 32) { |
| 417 | __ Drotr(out, in, shift); |
| 418 | } else { |
| 419 | shift &= 0x1f; |
| 420 | __ Drotr32(out, in, shift); |
| 421 | } |
| 422 | } |
| 423 | } else { |
| 424 | GpuRegister shamt = locations->InAt(1).AsRegister<GpuRegister>(); |
| 425 | if (type == Primitive::kPrimInt) { |
| 426 | __ Subu(TMP, ZERO, shamt); |
| 427 | __ Rotrv(out, in, TMP); |
| 428 | } else { |
| 429 | __ Dsubu(TMP, ZERO, shamt); |
| 430 | __ Drotrv(out, in, TMP); |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | // int java.lang.Integer.rotateLeft(int i, int distance) |
| 436 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerRotateLeft(HInvoke* invoke) { |
| 437 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 438 | LocationSummary::kNoCall, |
| 439 | kIntrinsified); |
| 440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 441 | locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1))); |
| 442 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 443 | } |
| 444 | |
| 445 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerRotateLeft(HInvoke* invoke) { |
| 446 | GenRotateLeft(invoke, Primitive::kPrimInt, GetAssembler()); |
| 447 | } |
| 448 | |
| 449 | // int java.lang.Long.rotateLeft(long i, int distance) |
| 450 | void IntrinsicLocationsBuilderMIPS64::VisitLongRotateLeft(HInvoke* invoke) { |
| 451 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 452 | LocationSummary::kNoCall, |
| 453 | kIntrinsified); |
| 454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 455 | locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1))); |
| 456 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 457 | } |
| 458 | |
| 459 | void IntrinsicCodeGeneratorMIPS64::VisitLongRotateLeft(HInvoke* invoke) { |
| 460 | GenRotateLeft(invoke, Primitive::kPrimLong, GetAssembler()); |
| 461 | } |
| 462 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 463 | static void GenReverse(LocationSummary* locations, |
| 464 | Primitive::Type type, |
| 465 | Mips64Assembler* assembler) { |
| 466 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 467 | |
| 468 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 469 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 470 | |
| 471 | if (type == Primitive::kPrimInt) { |
| 472 | __ Rotr(out, in, 16); |
| 473 | __ Wsbh(out, out); |
| 474 | __ Bitswap(out, out); |
| 475 | } else { |
| 476 | __ Dsbh(out, in); |
| 477 | __ Dshd(out, out); |
| 478 | __ Dbitswap(out, out); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | // int java.lang.Integer.reverse(int) |
| 483 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverse(HInvoke* invoke) { |
| 484 | CreateIntToIntLocations(arena_, invoke); |
| 485 | } |
| 486 | |
| 487 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverse(HInvoke* invoke) { |
| 488 | GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 489 | } |
| 490 | |
| 491 | // long java.lang.Long.reverse(long) |
| 492 | void IntrinsicLocationsBuilderMIPS64::VisitLongReverse(HInvoke* invoke) { |
| 493 | CreateIntToIntLocations(arena_, invoke); |
| 494 | } |
| 495 | |
| 496 | void IntrinsicCodeGeneratorMIPS64::VisitLongReverse(HInvoke* invoke) { |
| 497 | GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 498 | } |
| 499 | |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 500 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 501 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 502 | LocationSummary::kNoCall, |
| 503 | kIntrinsified); |
| 504 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 505 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 506 | } |
| 507 | |
| 508 | static void MathAbsFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 509 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 510 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 511 | |
| 512 | if (is64bit) { |
| 513 | __ AbsD(out, in); |
| 514 | } else { |
| 515 | __ AbsS(out, in); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | // double java.lang.Math.abs(double) |
| 520 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsDouble(HInvoke* invoke) { |
| 521 | CreateFPToFPLocations(arena_, invoke); |
| 522 | } |
| 523 | |
| 524 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsDouble(HInvoke* invoke) { |
| 525 | MathAbsFP(invoke->GetLocations(), true, GetAssembler()); |
| 526 | } |
| 527 | |
| 528 | // float java.lang.Math.abs(float) |
| 529 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsFloat(HInvoke* invoke) { |
| 530 | CreateFPToFPLocations(arena_, invoke); |
| 531 | } |
| 532 | |
| 533 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsFloat(HInvoke* invoke) { |
| 534 | MathAbsFP(invoke->GetLocations(), false, GetAssembler()); |
| 535 | } |
| 536 | |
| 537 | static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) { |
| 538 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 539 | LocationSummary::kNoCall, |
| 540 | kIntrinsified); |
| 541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 542 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 543 | } |
| 544 | |
| 545 | static void GenAbsInteger(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 546 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 547 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 548 | |
| 549 | if (is64bit) { |
| 550 | __ Dsra32(AT, in, 31); |
| 551 | __ Xor(out, in, AT); |
| 552 | __ Dsubu(out, out, AT); |
| 553 | } else { |
| 554 | __ Sra(AT, in, 31); |
| 555 | __ Xor(out, in, AT); |
| 556 | __ Subu(out, out, AT); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | // int java.lang.Math.abs(int) |
| 561 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsInt(HInvoke* invoke) { |
| 562 | CreateIntToInt(arena_, invoke); |
| 563 | } |
| 564 | |
| 565 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsInt(HInvoke* invoke) { |
| 566 | GenAbsInteger(invoke->GetLocations(), false, GetAssembler()); |
| 567 | } |
| 568 | |
| 569 | // long java.lang.Math.abs(long) |
| 570 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsLong(HInvoke* invoke) { |
| 571 | CreateIntToInt(arena_, invoke); |
| 572 | } |
| 573 | |
| 574 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsLong(HInvoke* invoke) { |
| 575 | GenAbsInteger(invoke->GetLocations(), true, GetAssembler()); |
| 576 | } |
| 577 | |
| 578 | static void GenMinMaxFP(LocationSummary* locations, |
| 579 | bool is_min, |
| 580 | bool is_double, |
| 581 | Mips64Assembler* assembler) { |
| 582 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 583 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 584 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 585 | |
| 586 | if (is_double) { |
| 587 | if (is_min) { |
| 588 | __ MinD(out, lhs, rhs); |
| 589 | } else { |
| 590 | __ MaxD(out, lhs, rhs); |
| 591 | } |
| 592 | } else { |
| 593 | if (is_min) { |
| 594 | __ MinS(out, lhs, rhs); |
| 595 | } else { |
| 596 | __ MaxS(out, lhs, rhs); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 602 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 603 | LocationSummary::kNoCall, |
| 604 | kIntrinsified); |
| 605 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 606 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 607 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 608 | } |
| 609 | |
| 610 | // double java.lang.Math.min(double, double) |
| 611 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 612 | CreateFPFPToFPLocations(arena_, invoke); |
| 613 | } |
| 614 | |
| 615 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 616 | GenMinMaxFP(invoke->GetLocations(), true, true, GetAssembler()); |
| 617 | } |
| 618 | |
| 619 | // float java.lang.Math.min(float, float) |
| 620 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 621 | CreateFPFPToFPLocations(arena_, invoke); |
| 622 | } |
| 623 | |
| 624 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 625 | GenMinMaxFP(invoke->GetLocations(), true, false, GetAssembler()); |
| 626 | } |
| 627 | |
| 628 | // double java.lang.Math.max(double, double) |
| 629 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 630 | CreateFPFPToFPLocations(arena_, invoke); |
| 631 | } |
| 632 | |
| 633 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 634 | GenMinMaxFP(invoke->GetLocations(), false, true, GetAssembler()); |
| 635 | } |
| 636 | |
| 637 | // float java.lang.Math.max(float, float) |
| 638 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 639 | CreateFPFPToFPLocations(arena_, invoke); |
| 640 | } |
| 641 | |
| 642 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 643 | GenMinMaxFP(invoke->GetLocations(), false, false, GetAssembler()); |
| 644 | } |
| 645 | |
| 646 | static void GenMinMax(LocationSummary* locations, |
| 647 | bool is_min, |
| 648 | Mips64Assembler* assembler) { |
| 649 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 650 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 651 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 652 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 653 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 654 | // conditional move instruction which only changes the target |
| 655 | // (output) register if the condition is true (MIPS prior to r6 had |
| 656 | // MOVF, MOVT, and MOVZ). The SELEQZ and SELNEZ instructions always |
| 657 | // change the target (output) register. If the condition is true the |
| 658 | // output register gets the contents of the "rs" register; otherwise, |
| 659 | // the output register is set to zero. One consequence of this is |
| 660 | // that to implement something like "rd = c==0 ? rs : rt" MIPS64r6 |
| 661 | // needs to use a pair of SELEQZ/SELNEZ instructions. After |
| 662 | // executing this pair of instructions one of the output registers |
| 663 | // from the pair will necessarily contain zero. Then the code ORs the |
| 664 | // output registers from the SELEQZ/SELNEZ instructions to get the |
| 665 | // final result. |
| 666 | // |
| 667 | // The initial test to see if the output register is same as the |
| 668 | // first input register is needed to make sure that value in the |
| 669 | // first input register isn't clobbered before we've finished |
| 670 | // computing the output value. The logic in the corresponding else |
| 671 | // clause performs the same task but makes sure the second input |
| 672 | // register isn't clobbered in the event that it's the same register |
| 673 | // as the output register; the else clause also handles the case |
| 674 | // where the output register is distinct from both the first, and the |
| 675 | // second input registers. |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 676 | if (out == lhs) { |
| 677 | __ Slt(AT, rhs, lhs); |
| 678 | if (is_min) { |
| 679 | __ Seleqz(out, lhs, AT); |
| 680 | __ Selnez(AT, rhs, AT); |
| 681 | } else { |
| 682 | __ Selnez(out, lhs, AT); |
| 683 | __ Seleqz(AT, rhs, AT); |
| 684 | } |
| 685 | } else { |
| 686 | __ Slt(AT, lhs, rhs); |
| 687 | if (is_min) { |
| 688 | __ Seleqz(out, rhs, AT); |
| 689 | __ Selnez(AT, lhs, AT); |
| 690 | } else { |
| 691 | __ Selnez(out, rhs, AT); |
| 692 | __ Seleqz(AT, lhs, AT); |
| 693 | } |
| 694 | } |
| 695 | __ Or(out, out, AT); |
| 696 | } |
| 697 | |
| 698 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 699 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 700 | LocationSummary::kNoCall, |
| 701 | kIntrinsified); |
| 702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 703 | locations->SetInAt(1, Location::RequiresRegister()); |
| 704 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 705 | } |
| 706 | |
| 707 | // int java.lang.Math.min(int, int) |
| 708 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinIntInt(HInvoke* invoke) { |
| 709 | CreateIntIntToIntLocations(arena_, invoke); |
| 710 | } |
| 711 | |
| 712 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinIntInt(HInvoke* invoke) { |
| 713 | GenMinMax(invoke->GetLocations(), true, GetAssembler()); |
| 714 | } |
| 715 | |
| 716 | // long java.lang.Math.min(long, long) |
| 717 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinLongLong(HInvoke* invoke) { |
| 718 | CreateIntIntToIntLocations(arena_, invoke); |
| 719 | } |
| 720 | |
| 721 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinLongLong(HInvoke* invoke) { |
| 722 | GenMinMax(invoke->GetLocations(), true, GetAssembler()); |
| 723 | } |
| 724 | |
| 725 | // int java.lang.Math.max(int, int) |
| 726 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 727 | CreateIntIntToIntLocations(arena_, invoke); |
| 728 | } |
| 729 | |
| 730 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 731 | GenMinMax(invoke->GetLocations(), false, GetAssembler()); |
| 732 | } |
| 733 | |
| 734 | // long java.lang.Math.max(long, long) |
| 735 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 736 | CreateIntIntToIntLocations(arena_, invoke); |
| 737 | } |
| 738 | |
| 739 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 740 | GenMinMax(invoke->GetLocations(), false, GetAssembler()); |
| 741 | } |
| 742 | |
| 743 | // double java.lang.Math.sqrt(double) |
| 744 | void IntrinsicLocationsBuilderMIPS64::VisitMathSqrt(HInvoke* invoke) { |
| 745 | CreateFPToFPLocations(arena_, invoke); |
| 746 | } |
| 747 | |
| 748 | void IntrinsicCodeGeneratorMIPS64::VisitMathSqrt(HInvoke* invoke) { |
| 749 | LocationSummary* locations = invoke->GetLocations(); |
| 750 | Mips64Assembler* assembler = GetAssembler(); |
| 751 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 752 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 753 | |
| 754 | __ SqrtD(out, in); |
| 755 | } |
| 756 | |
| 757 | static void CreateFPToFP(ArenaAllocator* arena, HInvoke* invoke) { |
| 758 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 759 | LocationSummary::kNoCall, |
| 760 | kIntrinsified); |
| 761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 762 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 763 | } |
| 764 | |
| 765 | // double java.lang.Math.rint(double) |
| 766 | void IntrinsicLocationsBuilderMIPS64::VisitMathRint(HInvoke* invoke) { |
| 767 | CreateFPToFP(arena_, invoke); |
| 768 | } |
| 769 | |
| 770 | void IntrinsicCodeGeneratorMIPS64::VisitMathRint(HInvoke* invoke) { |
| 771 | LocationSummary* locations = invoke->GetLocations(); |
| 772 | Mips64Assembler* assembler = GetAssembler(); |
| 773 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 774 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 775 | |
| 776 | __ RintD(out, in); |
| 777 | } |
| 778 | |
| 779 | // double java.lang.Math.floor(double) |
| 780 | void IntrinsicLocationsBuilderMIPS64::VisitMathFloor(HInvoke* invoke) { |
| 781 | CreateFPToFP(arena_, invoke); |
| 782 | } |
| 783 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 784 | const constexpr uint16_t kFPLeaveUnchanged = kPositiveZero | |
| 785 | kPositiveInfinity | |
| 786 | kNegativeZero | |
| 787 | kNegativeInfinity | |
| 788 | kQuietNaN | |
| 789 | kSignalingNaN; |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 790 | |
| 791 | void IntrinsicCodeGeneratorMIPS64::VisitMathFloor(HInvoke* invoke) { |
| 792 | LocationSummary* locations = invoke->GetLocations(); |
| 793 | Mips64Assembler* assembler = GetAssembler(); |
| 794 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 795 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 796 | |
| 797 | Label done; |
| 798 | |
| 799 | // double floor(double in) { |
| 800 | // if in.isNaN || in.isInfinite || in.isZero { |
| 801 | // return in; |
| 802 | // } |
| 803 | __ ClassD(out, in); |
| 804 | __ Dmfc1(AT, out); |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 805 | __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 806 | __ MovD(out, in); |
| 807 | __ Bnezc(AT, &done); |
| 808 | |
| 809 | // Long outLong = floor(in); |
| 810 | // if outLong == Long.MAX_VALUE { |
| 811 | // // floor() has almost certainly returned a value which |
| 812 | // // can't be successfully represented as a signed 64-bit |
| 813 | // // number. Java expects that the input value will be |
| 814 | // // returned in these cases. |
| 815 | // // There is also a small probability that floor(in) |
| 816 | // // correctly truncates the input value to Long.MAX_VALUE. In |
| 817 | // // that case, this exception handling code still does the |
| 818 | // // correct thing. |
| 819 | // return in; |
| 820 | // } |
| 821 | __ FloorLD(out, in); |
| 822 | __ Dmfc1(AT, out); |
| 823 | __ MovD(out, in); |
| 824 | __ LoadConst64(TMP, kPrimLongMax); |
| 825 | __ Beqc(AT, TMP, &done); |
| 826 | |
| 827 | // double out = outLong; |
| 828 | // return out; |
| 829 | __ Dmtc1(AT, out); |
| 830 | __ Cvtdl(out, out); |
| 831 | __ Bind(&done); |
| 832 | // } |
| 833 | } |
| 834 | |
| 835 | // double java.lang.Math.ceil(double) |
| 836 | void IntrinsicLocationsBuilderMIPS64::VisitMathCeil(HInvoke* invoke) { |
| 837 | CreateFPToFP(arena_, invoke); |
| 838 | } |
| 839 | |
| 840 | void IntrinsicCodeGeneratorMIPS64::VisitMathCeil(HInvoke* invoke) { |
| 841 | LocationSummary* locations = invoke->GetLocations(); |
| 842 | Mips64Assembler* assembler = GetAssembler(); |
| 843 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 844 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 845 | |
| 846 | Label done; |
| 847 | |
| 848 | // double ceil(double in) { |
| 849 | // if in.isNaN || in.isInfinite || in.isZero { |
| 850 | // return in; |
| 851 | // } |
| 852 | __ ClassD(out, in); |
| 853 | __ Dmfc1(AT, out); |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 854 | __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 855 | __ MovD(out, in); |
| 856 | __ Bnezc(AT, &done); |
| 857 | |
| 858 | // Long outLong = ceil(in); |
| 859 | // if outLong == Long.MAX_VALUE { |
| 860 | // // ceil() has almost certainly returned a value which |
| 861 | // // can't be successfully represented as a signed 64-bit |
| 862 | // // number. Java expects that the input value will be |
| 863 | // // returned in these cases. |
| 864 | // // There is also a small probability that ceil(in) |
| 865 | // // correctly rounds up the input value to Long.MAX_VALUE. In |
| 866 | // // that case, this exception handling code still does the |
| 867 | // // correct thing. |
| 868 | // return in; |
| 869 | // } |
| 870 | __ CeilLD(out, in); |
| 871 | __ Dmfc1(AT, out); |
| 872 | __ MovD(out, in); |
| 873 | __ LoadConst64(TMP, kPrimLongMax); |
| 874 | __ Beqc(AT, TMP, &done); |
| 875 | |
| 876 | // double out = outLong; |
| 877 | // return out; |
| 878 | __ Dmtc1(AT, out); |
| 879 | __ Cvtdl(out, out); |
| 880 | __ Bind(&done); |
| 881 | // } |
| 882 | } |
| 883 | |
Chris Larsen | 70fb1f4 | 2015-09-04 10:15:27 -0700 | [diff] [blame] | 884 | // byte libcore.io.Memory.peekByte(long address) |
| 885 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 886 | CreateIntToIntLocations(arena_, invoke); |
| 887 | } |
| 888 | |
| 889 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 890 | Mips64Assembler* assembler = GetAssembler(); |
| 891 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 892 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 893 | |
| 894 | __ Lb(out, adr, 0); |
| 895 | } |
| 896 | |
| 897 | // short libcore.io.Memory.peekShort(long address) |
| 898 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 899 | CreateIntToIntLocations(arena_, invoke); |
| 900 | } |
| 901 | |
| 902 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 903 | Mips64Assembler* assembler = GetAssembler(); |
| 904 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 905 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 906 | |
| 907 | __ Lh(out, adr, 0); |
| 908 | } |
| 909 | |
| 910 | // int libcore.io.Memory.peekInt(long address) |
| 911 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 912 | CreateIntToIntLocations(arena_, invoke); |
| 913 | } |
| 914 | |
| 915 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 916 | Mips64Assembler* assembler = GetAssembler(); |
| 917 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 918 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 919 | |
| 920 | __ Lw(out, adr, 0); |
| 921 | } |
| 922 | |
| 923 | // long libcore.io.Memory.peekLong(long address) |
| 924 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 925 | CreateIntToIntLocations(arena_, invoke); |
| 926 | } |
| 927 | |
| 928 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 929 | Mips64Assembler* assembler = GetAssembler(); |
| 930 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 931 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 932 | |
| 933 | __ Ld(out, adr, 0); |
| 934 | } |
| 935 | |
| 936 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 937 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 938 | LocationSummary::kNoCall, |
| 939 | kIntrinsified); |
| 940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 941 | locations->SetInAt(1, Location::RequiresRegister()); |
| 942 | } |
| 943 | |
| 944 | // void libcore.io.Memory.pokeByte(long address, byte value) |
| 945 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 946 | CreateIntIntToVoidLocations(arena_, invoke); |
| 947 | } |
| 948 | |
| 949 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 950 | Mips64Assembler* assembler = GetAssembler(); |
| 951 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 952 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 953 | |
| 954 | __ Sb(val, adr, 0); |
| 955 | } |
| 956 | |
| 957 | // void libcore.io.Memory.pokeShort(long address, short value) |
| 958 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 959 | CreateIntIntToVoidLocations(arena_, invoke); |
| 960 | } |
| 961 | |
| 962 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 963 | Mips64Assembler* assembler = GetAssembler(); |
| 964 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 965 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 966 | |
| 967 | __ Sh(val, adr, 0); |
| 968 | } |
| 969 | |
| 970 | // void libcore.io.Memory.pokeInt(long address, int value) |
| 971 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 972 | CreateIntIntToVoidLocations(arena_, invoke); |
| 973 | } |
| 974 | |
| 975 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 976 | Mips64Assembler* assembler = GetAssembler(); |
| 977 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 978 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 979 | |
| 980 | __ Sw(val, adr, 00); |
| 981 | } |
| 982 | |
| 983 | // void libcore.io.Memory.pokeLong(long address, long value) |
| 984 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 985 | CreateIntIntToVoidLocations(arena_, invoke); |
| 986 | } |
| 987 | |
| 988 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 989 | Mips64Assembler* assembler = GetAssembler(); |
| 990 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 991 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 992 | |
| 993 | __ Sd(val, adr, 0); |
| 994 | } |
| 995 | |
Chris Larsen | 49e5539 | 2015-09-04 16:04:03 -0700 | [diff] [blame] | 996 | // Thread java.lang.Thread.currentThread() |
| 997 | void IntrinsicLocationsBuilderMIPS64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 998 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 999 | LocationSummary::kNoCall, |
| 1000 | kIntrinsified); |
| 1001 | locations->SetOut(Location::RequiresRegister()); |
| 1002 | } |
| 1003 | |
| 1004 | void IntrinsicCodeGeneratorMIPS64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 1005 | Mips64Assembler* assembler = GetAssembler(); |
| 1006 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 1007 | |
| 1008 | __ LoadFromOffset(kLoadUnsignedWord, |
| 1009 | out, |
| 1010 | TR, |
| 1011 | Thread::PeerOffset<kMips64PointerSize>().Int32Value()); |
| 1012 | } |
| 1013 | |
Chris Larsen | 1360ada | 2015-09-04 23:38:16 -0700 | [diff] [blame] | 1014 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 1015 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 1016 | LocationSummary::kNoCall, |
| 1017 | kIntrinsified); |
| 1018 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1019 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1020 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1021 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1022 | } |
| 1023 | |
| 1024 | static void GenUnsafeGet(HInvoke* invoke, |
| 1025 | Primitive::Type type, |
| 1026 | bool is_volatile, |
| 1027 | CodeGeneratorMIPS64* codegen) { |
| 1028 | LocationSummary* locations = invoke->GetLocations(); |
| 1029 | DCHECK((type == Primitive::kPrimInt) || |
| 1030 | (type == Primitive::kPrimLong) || |
| 1031 | (type == Primitive::kPrimNot)); |
| 1032 | Mips64Assembler* assembler = codegen->GetAssembler(); |
| 1033 | // Object pointer. |
| 1034 | GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1035 | // Long offset. |
| 1036 | GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1037 | GpuRegister trg = locations->Out().AsRegister<GpuRegister>(); |
| 1038 | |
| 1039 | __ Daddu(TMP, base, offset); |
| 1040 | if (is_volatile) { |
| 1041 | __ Sync(0); |
| 1042 | } |
| 1043 | switch (type) { |
| 1044 | case Primitive::kPrimInt: |
| 1045 | __ Lw(trg, TMP, 0); |
| 1046 | break; |
| 1047 | |
| 1048 | case Primitive::kPrimNot: |
| 1049 | __ Lwu(trg, TMP, 0); |
| 1050 | break; |
| 1051 | |
| 1052 | case Primitive::kPrimLong: |
| 1053 | __ Ld(trg, TMP, 0); |
| 1054 | break; |
| 1055 | |
| 1056 | default: |
| 1057 | LOG(FATAL) << "Unsupported op size " << type; |
| 1058 | UNREACHABLE(); |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | // int sun.misc.Unsafe.getInt(Object o, long offset) |
| 1063 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGet(HInvoke* invoke) { |
| 1064 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 1065 | } |
| 1066 | |
| 1067 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGet(HInvoke* invoke) { |
| 1068 | GenUnsafeGet(invoke, Primitive::kPrimInt, false, codegen_); |
| 1069 | } |
| 1070 | |
| 1071 | // int sun.misc.Unsafe.getIntVolatile(Object o, long offset) |
| 1072 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 1073 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 1074 | } |
| 1075 | |
| 1076 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 1077 | GenUnsafeGet(invoke, Primitive::kPrimInt, true, codegen_); |
| 1078 | } |
| 1079 | |
| 1080 | // long sun.misc.Unsafe.getLong(Object o, long offset) |
| 1081 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetLong(HInvoke* invoke) { |
| 1082 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 1083 | } |
| 1084 | |
| 1085 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetLong(HInvoke* invoke) { |
| 1086 | GenUnsafeGet(invoke, Primitive::kPrimLong, false, codegen_); |
| 1087 | } |
| 1088 | |
| 1089 | // long sun.misc.Unsafe.getLongVolatile(Object o, long offset) |
| 1090 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 1091 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 1092 | } |
| 1093 | |
| 1094 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 1095 | GenUnsafeGet(invoke, Primitive::kPrimLong, true, codegen_); |
| 1096 | } |
| 1097 | |
| 1098 | // Object sun.misc.Unsafe.getObject(Object o, long offset) |
| 1099 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetObject(HInvoke* invoke) { |
| 1100 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 1101 | } |
| 1102 | |
| 1103 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetObject(HInvoke* invoke) { |
| 1104 | GenUnsafeGet(invoke, Primitive::kPrimNot, false, codegen_); |
| 1105 | } |
| 1106 | |
| 1107 | // Object sun.misc.Unsafe.getObjectVolatile(Object o, long offset) |
| 1108 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 1109 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 1110 | } |
| 1111 | |
| 1112 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 1113 | GenUnsafeGet(invoke, Primitive::kPrimNot, true, codegen_); |
| 1114 | } |
| 1115 | |
| 1116 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, HInvoke* invoke) { |
| 1117 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 1118 | LocationSummary::kNoCall, |
| 1119 | kIntrinsified); |
| 1120 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1121 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1122 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1123 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1124 | } |
| 1125 | |
| 1126 | static void GenUnsafePut(LocationSummary* locations, |
| 1127 | Primitive::Type type, |
| 1128 | bool is_volatile, |
| 1129 | bool is_ordered, |
| 1130 | CodeGeneratorMIPS64* codegen) { |
| 1131 | DCHECK((type == Primitive::kPrimInt) || |
| 1132 | (type == Primitive::kPrimLong) || |
| 1133 | (type == Primitive::kPrimNot)); |
| 1134 | Mips64Assembler* assembler = codegen->GetAssembler(); |
| 1135 | // Object pointer. |
| 1136 | GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1137 | // Long offset. |
| 1138 | GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1139 | GpuRegister value = locations->InAt(3).AsRegister<GpuRegister>(); |
| 1140 | |
| 1141 | __ Daddu(TMP, base, offset); |
| 1142 | if (is_volatile || is_ordered) { |
| 1143 | __ Sync(0); |
| 1144 | } |
| 1145 | switch (type) { |
| 1146 | case Primitive::kPrimInt: |
| 1147 | case Primitive::kPrimNot: |
| 1148 | __ Sw(value, TMP, 0); |
| 1149 | break; |
| 1150 | |
| 1151 | case Primitive::kPrimLong: |
| 1152 | __ Sd(value, TMP, 0); |
| 1153 | break; |
| 1154 | |
| 1155 | default: |
| 1156 | LOG(FATAL) << "Unsupported op size " << type; |
| 1157 | UNREACHABLE(); |
| 1158 | } |
| 1159 | if (is_volatile) { |
| 1160 | __ Sync(0); |
| 1161 | } |
| 1162 | |
| 1163 | if (type == Primitive::kPrimNot) { |
| 1164 | codegen->MarkGCCard(base, value); |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | // void sun.misc.Unsafe.putInt(Object o, long offset, int x) |
| 1169 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePut(HInvoke* invoke) { |
| 1170 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1171 | } |
| 1172 | |
| 1173 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePut(HInvoke* invoke) { |
| 1174 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, false, codegen_); |
| 1175 | } |
| 1176 | |
| 1177 | // void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x) |
| 1178 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 1179 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1180 | } |
| 1181 | |
| 1182 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 1183 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, true, codegen_); |
| 1184 | } |
| 1185 | |
| 1186 | // void sun.misc.Unsafe.putIntVolatile(Object o, long offset, int x) |
| 1187 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 1188 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1189 | } |
| 1190 | |
| 1191 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 1192 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, true, false, codegen_); |
| 1193 | } |
| 1194 | |
| 1195 | // void sun.misc.Unsafe.putObject(Object o, long offset, Object x) |
| 1196 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObject(HInvoke* invoke) { |
| 1197 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1198 | } |
| 1199 | |
| 1200 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObject(HInvoke* invoke) { |
| 1201 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, false, codegen_); |
| 1202 | } |
| 1203 | |
| 1204 | // void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x) |
| 1205 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 1206 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1207 | } |
| 1208 | |
| 1209 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 1210 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, true, codegen_); |
| 1211 | } |
| 1212 | |
| 1213 | // void sun.misc.Unsafe.putObjectVolatile(Object o, long offset, Object x) |
| 1214 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 1215 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1216 | } |
| 1217 | |
| 1218 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 1219 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, true, false, codegen_); |
| 1220 | } |
| 1221 | |
| 1222 | // void sun.misc.Unsafe.putLong(Object o, long offset, long x) |
| 1223 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLong(HInvoke* invoke) { |
| 1224 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1225 | } |
| 1226 | |
| 1227 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLong(HInvoke* invoke) { |
| 1228 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, false, codegen_); |
| 1229 | } |
| 1230 | |
| 1231 | // void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x) |
| 1232 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 1233 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1234 | } |
| 1235 | |
| 1236 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 1237 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, true, codegen_); |
| 1238 | } |
| 1239 | |
| 1240 | // void sun.misc.Unsafe.putLongVolatile(Object o, long offset, long x) |
| 1241 | void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 1242 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 1243 | } |
| 1244 | |
| 1245 | void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 1246 | GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, true, false, codegen_); |
| 1247 | } |
| 1248 | |
Chris Larsen | 9701c2e | 2015-09-04 17:22:47 -0700 | [diff] [blame] | 1249 | // char java.lang.String.charAt(int index) |
| 1250 | void IntrinsicLocationsBuilderMIPS64::VisitStringCharAt(HInvoke* invoke) { |
| 1251 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1252 | LocationSummary::kCallOnSlowPath, |
| 1253 | kIntrinsified); |
| 1254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1255 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1256 | locations->SetOut(Location::SameAsFirstInput()); |
| 1257 | } |
| 1258 | |
| 1259 | void IntrinsicCodeGeneratorMIPS64::VisitStringCharAt(HInvoke* invoke) { |
| 1260 | LocationSummary* locations = invoke->GetLocations(); |
| 1261 | Mips64Assembler* assembler = GetAssembler(); |
| 1262 | |
| 1263 | // Location of reference to data array |
| 1264 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1265 | // Location of count |
| 1266 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1267 | |
| 1268 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1269 | GpuRegister idx = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1270 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1271 | |
| 1272 | // TODO: Maybe we can support range check elimination. Overall, |
| 1273 | // though, I think it's not worth the cost. |
| 1274 | // TODO: For simplicity, the index parameter is requested in a |
| 1275 | // register, so different from Quick we will not optimize the |
| 1276 | // code for constants (which would save a register). |
| 1277 | |
| 1278 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1279 | codegen_->AddSlowPath(slow_path); |
| 1280 | |
| 1281 | // Load the string size |
| 1282 | __ Lw(TMP, obj, count_offset); |
| 1283 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1284 | // Revert to slow path if idx is too large, or negative |
| 1285 | __ Bgeuc(idx, TMP, slow_path->GetEntryLabel()); |
| 1286 | |
| 1287 | // out = obj[2*idx]. |
| 1288 | __ Sll(TMP, idx, 1); // idx * 2 |
| 1289 | __ Daddu(TMP, TMP, obj); // Address of char at location idx |
| 1290 | __ Lhu(out, TMP, value_offset); // Load char at location idx |
| 1291 | |
| 1292 | __ Bind(slow_path->GetExitLabel()); |
| 1293 | } |
| 1294 | |
| 1295 | // int java.lang.String.compareTo(String anotherString) |
| 1296 | void IntrinsicLocationsBuilderMIPS64::VisitStringCompareTo(HInvoke* invoke) { |
| 1297 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1298 | LocationSummary::kCall, |
| 1299 | kIntrinsified); |
| 1300 | InvokeRuntimeCallingConvention calling_convention; |
| 1301 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1302 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1303 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1304 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1305 | } |
| 1306 | |
| 1307 | void IntrinsicCodeGeneratorMIPS64::VisitStringCompareTo(HInvoke* invoke) { |
| 1308 | Mips64Assembler* assembler = GetAssembler(); |
| 1309 | LocationSummary* locations = invoke->GetLocations(); |
| 1310 | |
| 1311 | // Note that the null check must have been done earlier. |
| 1312 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1313 | |
| 1314 | GpuRegister argument = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1315 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1316 | codegen_->AddSlowPath(slow_path); |
| 1317 | __ Beqzc(argument, slow_path->GetEntryLabel()); |
| 1318 | |
| 1319 | __ LoadFromOffset(kLoadDoubleword, |
| 1320 | TMP, |
| 1321 | TR, |
| 1322 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, |
| 1323 | pStringCompareTo).Int32Value()); |
| 1324 | __ Jalr(TMP); |
| 1325 | __ Nop(); |
| 1326 | __ Bind(slow_path->GetExitLabel()); |
| 1327 | } |
| 1328 | |
| 1329 | static void GenerateStringIndexOf(HInvoke* invoke, |
| 1330 | Mips64Assembler* assembler, |
| 1331 | CodeGeneratorMIPS64* codegen, |
| 1332 | ArenaAllocator* allocator, |
| 1333 | bool start_at_zero) { |
| 1334 | LocationSummary* locations = invoke->GetLocations(); |
| 1335 | GpuRegister tmp_reg = start_at_zero ? locations->GetTemp(0).AsRegister<GpuRegister>() : TMP; |
| 1336 | |
| 1337 | // Note that the null check must have been done earlier. |
| 1338 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1339 | |
| 1340 | // Check for code points > 0xFFFF. Either a slow-path check when we |
| 1341 | // don't know statically, or directly dispatch if we have a constant. |
| 1342 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 1343 | if (invoke->InputAt(1)->IsIntConstant()) { |
| 1344 | if (!IsUint<16>(invoke->InputAt(1)->AsIntConstant()->GetValue())) { |
| 1345 | // Always needs the slow-path. We could directly dispatch to it, |
| 1346 | // but this case should be rare, so for simplicity just put the |
| 1347 | // full slow-path down and branch unconditionally. |
| 1348 | slow_path = new (allocator) IntrinsicSlowPathMIPS64(invoke); |
| 1349 | codegen->AddSlowPath(slow_path); |
| 1350 | __ B(slow_path->GetEntryLabel()); |
| 1351 | __ Bind(slow_path->GetExitLabel()); |
| 1352 | return; |
| 1353 | } |
| 1354 | } else { |
| 1355 | GpuRegister char_reg = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1356 | __ LoadConst32(tmp_reg, std::numeric_limits<uint16_t>::max()); |
| 1357 | slow_path = new (allocator) IntrinsicSlowPathMIPS64(invoke); |
| 1358 | codegen->AddSlowPath(slow_path); |
| 1359 | __ Bltuc(tmp_reg, char_reg, slow_path->GetEntryLabel()); // UTF-16 required |
| 1360 | } |
| 1361 | |
| 1362 | if (start_at_zero) { |
| 1363 | DCHECK_EQ(tmp_reg, A2); |
| 1364 | // Start-index = 0. |
| 1365 | __ Clear(tmp_reg); |
| 1366 | } else { |
| 1367 | __ Slt(TMP, A2, ZERO); // if fromIndex < 0 |
| 1368 | __ Seleqz(A2, A2, TMP); // fromIndex = 0 |
| 1369 | } |
| 1370 | |
| 1371 | __ LoadFromOffset(kLoadDoubleword, |
| 1372 | TMP, |
| 1373 | TR, |
| 1374 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pIndexOf).Int32Value()); |
| 1375 | __ Jalr(TMP); |
| 1376 | __ Nop(); |
| 1377 | |
| 1378 | if (slow_path != nullptr) { |
| 1379 | __ Bind(slow_path->GetExitLabel()); |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | // int java.lang.String.indexOf(int ch) |
| 1384 | void IntrinsicLocationsBuilderMIPS64::VisitStringIndexOf(HInvoke* invoke) { |
| 1385 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1386 | LocationSummary::kCall, |
| 1387 | kIntrinsified); |
| 1388 | // We have a hand-crafted assembly stub that follows the runtime |
| 1389 | // calling convention. So it's best to align the inputs accordingly. |
| 1390 | InvokeRuntimeCallingConvention calling_convention; |
| 1391 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1392 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1393 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1394 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1395 | |
| 1396 | // Need a temp for slow-path codepoint compare, and need to send start-index=0. |
| 1397 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1398 | } |
| 1399 | |
| 1400 | void IntrinsicCodeGeneratorMIPS64::VisitStringIndexOf(HInvoke* invoke) { |
| 1401 | GenerateStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), true); |
| 1402 | } |
| 1403 | |
| 1404 | // int java.lang.String.indexOf(int ch, int fromIndex) |
| 1405 | void IntrinsicLocationsBuilderMIPS64::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1406 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1407 | LocationSummary::kCall, |
| 1408 | kIntrinsified); |
| 1409 | // We have a hand-crafted assembly stub that follows the runtime |
| 1410 | // calling convention. So it's best to align the inputs accordingly. |
| 1411 | InvokeRuntimeCallingConvention calling_convention; |
| 1412 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1413 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1414 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1415 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1416 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1417 | } |
| 1418 | |
| 1419 | void IntrinsicCodeGeneratorMIPS64::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1420 | GenerateStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), false); |
| 1421 | } |
| 1422 | |
| 1423 | // java.lang.String.String(byte[] bytes) |
| 1424 | void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1425 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1426 | LocationSummary::kCall, |
| 1427 | kIntrinsified); |
| 1428 | InvokeRuntimeCallingConvention calling_convention; |
| 1429 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1430 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1431 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1432 | locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 1433 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1434 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1435 | } |
| 1436 | |
| 1437 | void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1438 | Mips64Assembler* assembler = GetAssembler(); |
| 1439 | LocationSummary* locations = invoke->GetLocations(); |
| 1440 | |
| 1441 | GpuRegister byte_array = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1442 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1443 | codegen_->AddSlowPath(slow_path); |
| 1444 | __ Beqzc(byte_array, slow_path->GetEntryLabel()); |
| 1445 | |
| 1446 | __ LoadFromOffset(kLoadDoubleword, |
| 1447 | TMP, |
| 1448 | TR, |
| 1449 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromBytes).Int32Value()); |
| 1450 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1451 | __ Jalr(TMP); |
| 1452 | __ Nop(); |
| 1453 | __ Bind(slow_path->GetExitLabel()); |
| 1454 | } |
| 1455 | |
| 1456 | // java.lang.String.String(char[] value) |
| 1457 | void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1458 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1459 | LocationSummary::kCall, |
| 1460 | kIntrinsified); |
| 1461 | InvokeRuntimeCallingConvention calling_convention; |
| 1462 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1463 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1464 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1465 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1466 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1467 | } |
| 1468 | |
| 1469 | void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1470 | Mips64Assembler* assembler = GetAssembler(); |
| 1471 | |
| 1472 | __ LoadFromOffset(kLoadDoubleword, |
| 1473 | TMP, |
| 1474 | TR, |
| 1475 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromChars).Int32Value()); |
| 1476 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1477 | __ Jalr(TMP); |
| 1478 | __ Nop(); |
| 1479 | } |
| 1480 | |
| 1481 | // java.lang.String.String(String original) |
| 1482 | void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1483 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1484 | LocationSummary::kCall, |
| 1485 | kIntrinsified); |
| 1486 | InvokeRuntimeCallingConvention calling_convention; |
| 1487 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1488 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1489 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1490 | Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt); |
| 1491 | locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>())); |
| 1492 | } |
| 1493 | |
| 1494 | void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1495 | Mips64Assembler* assembler = GetAssembler(); |
| 1496 | LocationSummary* locations = invoke->GetLocations(); |
| 1497 | |
| 1498 | GpuRegister string_to_copy = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1499 | SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke); |
| 1500 | codegen_->AddSlowPath(slow_path); |
| 1501 | __ Beqzc(string_to_copy, slow_path->GetEntryLabel()); |
| 1502 | |
| 1503 | __ LoadFromOffset(kLoadDoubleword, |
| 1504 | TMP, |
| 1505 | TR, |
| 1506 | QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromString).Int32Value()); |
| 1507 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1508 | __ Jalr(TMP); |
| 1509 | __ Nop(); |
| 1510 | __ Bind(slow_path->GetExitLabel()); |
| 1511 | } |
| 1512 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1513 | // Unimplemented intrinsics. |
| 1514 | |
| 1515 | #define UNIMPLEMENTED_INTRINSIC(Name) \ |
| 1516 | void IntrinsicLocationsBuilderMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 1517 | } \ |
| 1518 | void IntrinsicCodeGeneratorMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 1519 | } |
| 1520 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1521 | UNIMPLEMENTED_INTRINSIC(MathRoundDouble) |
| 1522 | UNIMPLEMENTED_INTRINSIC(MathRoundFloat) |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 1523 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1524 | UNIMPLEMENTED_INTRINSIC(UnsafeCASInt) |
| 1525 | UNIMPLEMENTED_INTRINSIC(UnsafeCASLong) |
| 1526 | UNIMPLEMENTED_INTRINSIC(UnsafeCASObject) |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1527 | UNIMPLEMENTED_INTRINSIC(StringEquals) |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1528 | |
| 1529 | UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent) |
| 1530 | UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck) |
| 1531 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar) |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1532 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopy) |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 1533 | |
| 1534 | #undef UNIMPLEMENTED_INTRINSIC |
| 1535 | |
| 1536 | #undef __ |
| 1537 | |
| 1538 | } // namespace mips64 |
| 1539 | } // namespace art |