intrinsics_arm.cc revision 9ee23f4273efed8d6378f6ad8e63c65e30a17139
12bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe/*
22bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * Copyright (C) 2015 The Android Open Source Project
32bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe *
42bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
52bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * you may not use this file except in compliance with the License.
62bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * You may obtain a copy of the License at
72bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe *
82bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
92bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe *
102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * Unless required by applicable law or agreed to in writing, software
112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * See the License for the specific language governing permissions and
142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe * limitations under the License.
152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe */
162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "intrinsics_arm.h"
182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "arch/arm/instruction_set_features_arm.h"
20e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include "art_method.h"
212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "code_generator_arm.h"
222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "entrypoints/quick/quick_entrypoints.h"
232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "intrinsics.h"
242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "mirror/array-inl.h"
252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "mirror/string.h"
262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "thread.h"
272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#include "utils/arm/assembler_arm.h"
282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampenamespace art {
302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampenamespace arm {
322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeArmAssembler* IntrinsicCodeGeneratorARM::GetAssembler() {
342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  return codegen_->GetAssembler();
352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeArenaAllocator* IntrinsicCodeGeneratorARM::GetAllocator() {
382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  return codegen_->GetGraph()->GetArena();
392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#define __ codegen->GetAssembler()->
422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void MoveFromReturnRegister(Location trg, Primitive::Type type, CodeGeneratorARM* codegen) {
442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (!trg.IsValid()) {
452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    DCHECK(type == Primitive::kPrimVoid);
462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    return;
472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  DCHECK_NE(type, Primitive::kPrimVoid);
502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
51848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) {
522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    if (type == Primitive::kPrimLong) {
532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register trg_reg_lo = trg.AsRegisterPairLow<Register>();
542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register trg_reg_hi = trg.AsRegisterPairHigh<Register>();
552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register res_reg_lo = R0;
562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register res_reg_hi = R1;
572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      if (trg_reg_lo != res_reg_hi) {
582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe        if (trg_reg_lo != res_reg_lo) {
592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe          __ mov(trg_reg_lo, ShifterOperand(res_reg_lo));
602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe          __ mov(trg_reg_hi, ShifterOperand(res_reg_hi));
612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe        } else {
622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe          DCHECK_EQ(trg_reg_lo + 1, trg_reg_hi);
632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe        }
642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      } else {
652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe        __ mov(trg_reg_hi, ShifterOperand(res_reg_hi));
662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe        __ mov(trg_reg_lo, ShifterOperand(res_reg_lo));
672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      }
682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    } else {
692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register trg_reg = trg.AsRegister<Register>();
702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register res_reg = R0;
712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      if (trg_reg != res_reg) {
722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe        __ mov(trg_reg, ShifterOperand(res_reg));
732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      }
742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    }
752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    UNIMPLEMENTED(FATAL) << "Floating-point return.";
772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
80ec525fc30848189051b888da53ba051bc0878b78Roland Levillainstatic void MoveArguments(HInvoke* invoke, CodeGeneratorARM* codegen) {
812d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain  InvokeDexCallingConventionVisitorARM calling_convention_visitor;
82ec525fc30848189051b888da53ba051bc0878b78Roland Levillain  IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor);
832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe// Slow-path for fallback (calling the managed code to handle the intrinsic) in an intrinsified
862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe// call. This will copy the arguments into the positions for a regular call.
872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe//
882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe// Note: The actual parameters are required to be in the locations given by the invoke's location
892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe//       summary. If an intrinsic modifies those locations before a slowpath call, they must be
902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe//       restored!
912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampeclass IntrinsicSlowPathARM : public SlowPathCodeARM {
922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe public:
932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  explicit IntrinsicSlowPathARM(HInvoke* invoke) : invoke_(invoke) { }
942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE {
962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    CodeGeneratorARM* codegen = down_cast<CodeGeneratorARM*>(codegen_in);
972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ Bind(GetEntryLabel());
982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
99a8ac9130b872c080299afacf5dcaab513d13ea87Nicolas Geoffray    SaveLiveRegisters(codegen, invoke_->GetLocations());
1002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
101ec525fc30848189051b888da53ba051bc0878b78Roland Levillain    MoveArguments(invoke_, codegen);
1022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    if (invoke_->IsInvokeStaticOrDirect()) {
10494015b939060f5041d408d48717f22443e55b6adNicolas Geoffray      codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(),
10594015b939060f5041d408d48717f22443e55b6adNicolas Geoffray                                          Location::RegisterLocation(kArtMethodRegister));
1064ab02352db4051d590b793f34d166a0b5c633c4aSerban Constantinescu      codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this);
1072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    } else {
1082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      UNIMPLEMENTED(FATAL) << "Non-direct intrinsic slow-path not yet implemented";
1092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      UNREACHABLE();
1102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    }
1112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    // Copy the result back to the expected output.
1132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Location out = invoke_->GetLocations()->Out();
1142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    if (out.IsValid()) {
1152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      DCHECK(out.IsRegister());  // TODO: Replace this when we support output in memory.
1162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
1172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      MoveFromReturnRegister(out, invoke_->GetType(), codegen);
1182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    }
1192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
120a8ac9130b872c080299afacf5dcaab513d13ea87Nicolas Geoffray    RestoreLiveRegisters(codegen, invoke_->GetLocations());
1212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ b(GetExitLabel());
1222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
1232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1249931f319cf86c56c2855d800339a3410697633a6Alexandre Rames  const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathARM"; }
1259931f319cf86c56c2855d800339a3410697633a6Alexandre Rames
1262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe private:
1272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // The instruction where this slow path is happening.
1282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  HInvoke* const invoke_;
1292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathARM);
1312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe};
1322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#undef __
1342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampebool IntrinsicLocationsBuilderARM::TryDispatch(HInvoke* invoke) {
1362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Dispatch(invoke);
1372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* res = invoke->GetLocations();
1382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  return res != nullptr && res->Intrinsified();
1392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#define __ assembler->
1422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
1442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
1452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
1462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
1472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresFpuRegister());
1482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister());
1492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1512bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
1522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
1532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
1542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
1552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresRegister());
1562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresFpuRegister());
1572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
1602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location input = locations->InAt(0);
1612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location output = locations->Out();
1622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is64bit) {
1632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ vmovrrd(output.AsRegisterPairLow<Register>(),
1642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe               output.AsRegisterPairHigh<Register>(),
1652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe               FromLowSToD(input.AsFpuRegisterPairLow<SRegister>()));
1662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
1672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ vmovrs(output.AsRegister<Register>(), input.AsFpuRegister<SRegister>());
1682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
1692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
1722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location input = locations->InAt(0);
1732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location output = locations->Out();
1742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is64bit) {
1752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ vmovdrr(FromLowSToD(output.AsFpuRegisterPairLow<SRegister>()),
1762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe               input.AsRegisterPairLow<Register>(),
1772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe               input.AsRegisterPairHigh<Register>());
1782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
1792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ vmovsr(output.AsFpuRegister<SRegister>(), input.AsRegister<Register>());
1802bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
1812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
1842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateFPToIntLocations(arena_, invoke);
1852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
1872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToFPLocations(arena_, invoke);
1882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
1912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  MoveFPToInt(invoke->GetLocations(), true, GetAssembler());
1922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
1942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  MoveIntToFP(invoke->GetLocations(), true, GetAssembler());
1952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
1982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateFPToIntLocations(arena_, invoke);
1992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
2002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitFloatIntBitsToFloat(HInvoke* invoke) {
2012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToFPLocations(arena_, invoke);
2022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
2032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
2042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
2052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  MoveFPToInt(invoke->GetLocations(), false, GetAssembler());
2062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
2072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitFloatIntBitsToFloat(HInvoke* invoke) {
2082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  MoveIntToFP(invoke->GetLocations(), false, GetAssembler());
2092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
2102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
2112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
2122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
2132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
2142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
2152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresRegister());
2162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
2182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
2192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
2202bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
2212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
2222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
2232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresFpuRegister());
2242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
2262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
227611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakelingstatic void GenNumberOfLeadingZeros(LocationSummary* locations,
228611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling                                    Primitive::Type type,
229611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling                                    ArmAssembler* assembler) {
230611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  Location in = locations->InAt(0);
231611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  Register out = locations->Out().AsRegister<Register>();
232611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
233611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
234611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
235611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  if (type == Primitive::kPrimLong) {
236611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    Register in_reg_lo = in.AsRegisterPairLow<Register>();
237611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    Register in_reg_hi = in.AsRegisterPairHigh<Register>();
238611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    Label end;
239611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    __ clz(out, in_reg_hi);
240611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    __ CompareAndBranchIfNonZero(in_reg_hi, &end);
241611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    __ clz(out, in_reg_lo);
242611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    __ AddConstant(out, 32);
243611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    __ Bind(&end);
244611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  } else {
245611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling    __ clz(out, in.AsRegister<Register>());
246611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  }
247611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling}
248611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
249611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
250611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  CreateIntToIntLocations(arena_, invoke);
251611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling}
252611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
253611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
254611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
255611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling}
256611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
257611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
258611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
259611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling                                                           LocationSummary::kNoCall,
260611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling                                                           kIntrinsified);
261611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
262611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
263611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling}
264611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
265611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
266611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling  GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
267611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling}
268611d3395e9efc0ab8dbfa4a197fa022fbd8c7204Scott Wakeling
2699ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingstatic void GenNumberOfTrailingZeros(LocationSummary* locations,
2709ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                     Primitive::Type type,
2719ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                     ArmAssembler* assembler) {
2729ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
2739ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
2749ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register out = locations->Out().AsRegister<Register>();
2759ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
2769ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  if (type == Primitive::kPrimLong) {
2779ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2789ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2799ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Label end;
2809ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ rbit(out, in_reg_lo);
2819ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ clz(out, out);
2829ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ CompareAndBranchIfNonZero(in_reg_lo, &end);
2839ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ rbit(out, in_reg_hi);
2849ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ clz(out, out);
2859ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ AddConstant(out, 32);
2869ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Bind(&end);
2879ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  } else {
2889ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Register in = locations->InAt(0).AsRegister<Register>();
2899ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ rbit(out, in);
2909ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ clz(out, out);
2919ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  }
2929ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
2939ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
2949ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
2959ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
2969ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            LocationSummary::kNoCall,
2979ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            kIntrinsified);
2989ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
2999ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3009ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
3019ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3029ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
3039ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
3049ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
3059ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3069ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
3079ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
3089ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            LocationSummary::kNoCall,
3099ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            kIntrinsified);
3109ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
3119ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3129ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
3139ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3149ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
3159ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
3169ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
3179ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3189ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingstatic void GenIntegerRotate(LocationSummary* locations,
3199ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                             ArmAssembler* assembler,
3209ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                             bool is_left) {
3219ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register in = locations->InAt(0).AsRegister<Register>();
3229ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Location rhs = locations->InAt(1);
3239ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register out = locations->Out().AsRegister<Register>();
3249ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3259ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  if (rhs.IsConstant()) {
3269ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3279ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // so map all rotations to a +ve. equivalent in that range.
3289ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3299ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    uint32_t rot = rhs.GetConstant()->AsIntConstant()->GetValue() & 0x1F;
3309ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    if (rot) {
3319ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      // Rotate, mapping left rotations to right equivalents if necessary.
3329ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      // (e.g. left by 2 bits == right by 30.)
3339ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Ror(out, in, is_left ? (0x20 - rot) : rot);
3349ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    } else if (out != in) {
3359ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Mov(out, in);
3369ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    }
3379ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  } else {
3389ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    if (is_left) {
3399ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ rsb(out, rhs.AsRegister<Register>(), ShifterOperand(0));
3409ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Ror(out, in, out);
3419ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    } else {
3429ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Ror(out, in, rhs.AsRegister<Register>());
3439ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    }
3449ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  }
3459ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
3469ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3479ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3489ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling// rotates by swapping input regs (effectively rotating by the first 32-bits of
3499ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling// a larger rotation) or flipping direction (thus treating larger right/left
3509ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling// rotations as sub-word sized rotations in the other direction) as appropriate.
3519ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingstatic void GenLongRotate(LocationSummary* locations,
3529ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                          ArmAssembler* assembler,
3539ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                          bool is_left) {
3549ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3559ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3569ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Location rhs = locations->InAt(1);
3579ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3589ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3599ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3609ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  if (rhs.IsConstant()) {
3619ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    uint32_t rot = rhs.GetConstant()->AsIntConstant()->GetValue();
3629ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // Map all left rotations to right equivalents.
3639ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    if (is_left) {
3649ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      rot = 0x40 - rot;
3659ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    }
3669ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // Map all rotations to +ve. equivalents on the interval [0,63].
3679ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    rot &= 0x3F;
3689ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3699ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // logic below to a simple pair of binary orr.
3709ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // (e.g. 34 bits == in_reg swap + 2 bits right.)
3719ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    if (rot >= 0x20) {
3729ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      rot -= 0x20;
3739ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      std::swap(in_reg_hi, in_reg_lo);
3749ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    }
3759ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // Rotate, or mov to out for zero or word size rotations.
3769ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    if (rot) {
3779ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Lsr(out_reg_hi, in_reg_hi, rot);
3789ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, 0x20 - rot));
3799ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Lsr(out_reg_lo, in_reg_lo, rot);
3809ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, 0x20 - rot));
3819ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    } else {
3829ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Mov(out_reg_lo, in_reg_lo);
3839ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ Mov(out_reg_hi, in_reg_hi);
3849ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    }
3859ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  } else {
3869ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Register shift_left = locations->GetTemp(0).AsRegister<Register>();
3879ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Register shift_right = locations->GetTemp(1).AsRegister<Register>();
3889ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Label end;
3899ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    Label right;
3909ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3919ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ and_(shift_left, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3929ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsrs(shift_right, rhs.AsRegister<Register>(), 6);
3939ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ rsb(shift_right, shift_left, ShifterOperand(0x20), AL, kCcKeep);
3949ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
3959ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    if (is_left) {
3969ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ b(&right, CS);
3979ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    } else {
3989ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      __ b(&right, CC);
3999ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling      std::swap(shift_left, shift_right);
4009ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    }
4019ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4029ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
4039ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
4049ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsl(out_reg_hi, in_reg_hi, shift_left);
4059ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsr(out_reg_lo, in_reg_lo, shift_right);
4069ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
4079ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsl(out_reg_lo, in_reg_lo, shift_left);
4089ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsr(shift_left, in_reg_hi, shift_right);
4099ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
4109ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ b(&end);
4119ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4129ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
4139ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
4149ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Bind(&right);
4159ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsr(out_reg_hi, in_reg_hi, shift_right);
4169ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsl(out_reg_lo, in_reg_lo, shift_left);
4179ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
4189ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsr(out_reg_lo, in_reg_lo, shift_right);
4199ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Lsl(shift_right, in_reg_hi, shift_left);
4209ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
4219ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4229ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    __ Bind(&end);
4239ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  }
4249ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4259ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4269ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitIntegerRotateRight(HInvoke* invoke) {
4279ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
4289ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            LocationSummary::kNoCall,
4299ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            kIntrinsified);
4309ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
4319ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
4329ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4339ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4349ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4359ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitIntegerRotateRight(HInvoke* invoke) {
4369ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  GenIntegerRotate(invoke->GetLocations(), GetAssembler(), false /* is_left */);
4379ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4389ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4399ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitLongRotateRight(HInvoke* invoke) {
4409ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
4419ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            LocationSummary::kNoCall,
4429ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            kIntrinsified);
4439ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
4449ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  if (invoke->InputAt(1)->IsConstant()) {
4459ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->SetInAt(1, Location::ConstantLocation(invoke->InputAt(1)->AsConstant()));
4469ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  } else {
4479ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->SetInAt(1, Location::RequiresRegister());
4489ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->AddTemp(Location::RequiresRegister());
4499ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->AddTemp(Location::RequiresRegister());
4509ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  }
4519ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4529ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4539ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4549ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitLongRotateRight(HInvoke* invoke) {
4559ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  GenLongRotate(invoke->GetLocations(), GetAssembler(), false /* is_left */);
4569ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4579ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4589ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitIntegerRotateLeft(HInvoke* invoke) {
4599ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
4609ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            LocationSummary::kNoCall,
4619ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            kIntrinsified);
4629ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
4639ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
4649ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4659ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4669ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4679ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitIntegerRotateLeft(HInvoke* invoke) {
4689ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  GenIntegerRotate(invoke->GetLocations(), GetAssembler(), true /* is_left */);
4699ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4709ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4719ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicLocationsBuilderARM::VisitLongRotateLeft(HInvoke* invoke) {
4729ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  LocationSummary* locations = new (arena_) LocationSummary(invoke,
4739ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            LocationSummary::kNoCall,
4749ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling                                                            kIntrinsified);
4759ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetInAt(0, Location::RequiresRegister());
4769ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  if (invoke->InputAt(1)->IsConstant()) {
4779ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->SetInAt(1, Location::ConstantLocation(invoke->InputAt(1)->AsConstant()));
4789ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  } else {
4799ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->SetInAt(1, Location::RequiresRegister());
4809ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->AddTemp(Location::RequiresRegister());
4819ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling    locations->AddTemp(Location::RequiresRegister());
4829ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  }
4839ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4849ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4859ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4869ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakelingvoid IntrinsicCodeGeneratorARM::VisitLongRotateLeft(HInvoke* invoke) {
4879ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling  GenLongRotate(invoke->GetLocations(), GetAssembler(), true /* is_left */);
4889ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling}
4899ee23f4273efed8d6378f6ad8e63c65e30a17139Scott Wakeling
4902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void MathAbsFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
4912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location in = locations->InAt(0);
4922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location out = locations->Out();
4932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
4942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is64bit) {
4952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ vabsd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
4962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe             FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
4972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
4982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ vabss(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
4992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
5002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathAbsDouble(HInvoke* invoke) {
5032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateFPToFPLocations(arena_, invoke);
5042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathAbsDouble(HInvoke* invoke) {
5072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  MathAbsFP(invoke->GetLocations(), true, GetAssembler());
5082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathAbsFloat(HInvoke* invoke) {
5112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateFPToFPLocations(arena_, invoke);
5122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathAbsFloat(HInvoke* invoke) {
5152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  MathAbsFP(invoke->GetLocations(), false, GetAssembler());
5162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) {
5192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
5202bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
5212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
5222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresRegister());
5232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->AddTemp(Location::RequiresRegister());
5262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void GenAbsInteger(LocationSummary* locations,
5292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                          bool is64bit,
5302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                          ArmAssembler* assembler) {
5312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location in = locations->InAt(0);
5322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Location output = locations->Out();
5332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register mask = locations->GetTemp(0).AsRegister<Register>();
5352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is64bit) {
5372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register in_reg_lo = in.AsRegisterPairLow<Register>();
5382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register in_reg_hi = in.AsRegisterPairHigh<Register>();
5392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register out_reg_lo = output.AsRegisterPairLow<Register>();
5402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register out_reg_hi = output.AsRegisterPairHigh<Register>();
5412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    DCHECK_NE(out_reg_lo, in_reg_hi) << "Diagonal overlap unexpected.";
5432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ Asr(mask, in_reg_hi, 31);
5452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ adds(out_reg_lo, in_reg_lo, ShifterOperand(mask));
5462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ adc(out_reg_hi, in_reg_hi, ShifterOperand(mask));
5472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ eor(out_reg_lo, mask, ShifterOperand(out_reg_lo));
5482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ eor(out_reg_hi, mask, ShifterOperand(out_reg_hi));
5492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
5502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register in_reg = in.AsRegister<Register>();
5512bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register out_reg = output.AsRegister<Register>();
5522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ Asr(mask, in_reg, 31);
5542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ add(out_reg, in_reg, ShifterOperand(mask));
5552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ eor(out_reg, mask, ShifterOperand(out_reg));
5562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
5572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathAbsInt(HInvoke* invoke) {
5602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToIntPlusTemp(arena_, invoke);
5612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathAbsInt(HInvoke* invoke) {
5642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenAbsInteger(invoke->GetLocations(), false, GetAssembler());
5652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathAbsLong(HInvoke* invoke) {
5692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToIntPlusTemp(arena_, invoke);
5702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathAbsLong(HInvoke* invoke) {
5732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenAbsInteger(invoke->GetLocations(), true, GetAssembler());
5742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void GenMinMax(LocationSummary* locations,
5772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                      bool is_min,
5782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                      ArmAssembler* assembler) {
5792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register op1 = locations->InAt(0).AsRegister<Register>();
5802bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register op2 = locations->InAt(1).AsRegister<Register>();
5812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register out = locations->Out().AsRegister<Register>();
5822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ cmp(op1, ShifterOperand(op2));
5842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ it((is_min) ? Condition::LT : Condition::GT, kItElse);
5862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ mov(out, ShifterOperand(op1), is_min ? Condition::LT : Condition::GT);
5872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ mov(out, ShifterOperand(op2), is_min ? Condition::GE : Condition::LE);
5882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
5912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
5922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
5932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
5942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresRegister());
5952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(1, Location::RequiresRegister());
5962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
5982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
5992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathMinIntInt(HInvoke* invoke) {
6002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntToIntLocations(arena_, invoke);
6012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathMinIntInt(HInvoke* invoke) {
6042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenMinMax(invoke->GetLocations(), true, GetAssembler());
6052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathMaxIntInt(HInvoke* invoke) {
6082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntToIntLocations(arena_, invoke);
6092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathMaxIntInt(HInvoke* invoke) {
6122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenMinMax(invoke->GetLocations(), false, GetAssembler());
6132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMathSqrt(HInvoke* invoke) {
6162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateFPToFPLocations(arena_, invoke);
6172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMathSqrt(HInvoke* invoke) {
6202bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = invoke->GetLocations();
6212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
6222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ vsqrtd(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
6232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe            FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
6242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPeekByte(HInvoke* invoke) {
6272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToIntLocations(arena_, invoke);
6282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPeekByte(HInvoke* invoke) {
6312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
6322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Ignore upper 4B of long address.
6332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ ldrsb(invoke->GetLocations()->Out().AsRegister<Register>(),
6342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe           Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
6352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPeekIntNative(HInvoke* invoke) {
6382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToIntLocations(arena_, invoke);
6392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPeekIntNative(HInvoke* invoke) {
6422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
6432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Ignore upper 4B of long address.
6442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ ldr(invoke->GetLocations()->Out().AsRegister<Register>(),
6452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe         Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
6462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPeekLongNative(HInvoke* invoke) {
6492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToIntLocations(arena_, invoke);
6502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6512bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPeekLongNative(HInvoke* invoke) {
6532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
6542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Ignore upper 4B of long address.
6552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
6562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
6572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // exception. So we can't use ldrd as addr may be unaligned.
6582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>();
6592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>();
6602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (addr == lo) {
6612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ ldr(hi, Address(addr, 4));
6622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ ldr(lo, Address(addr, 0));
6632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
6642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ ldr(lo, Address(addr, 0));
6652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ ldr(hi, Address(addr, 4));
6662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
6672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPeekShortNative(HInvoke* invoke) {
6702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntToIntLocations(arena_, invoke);
6712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPeekShortNative(HInvoke* invoke) {
6742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
6752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Ignore upper 4B of long address.
6762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ ldrsh(invoke->GetLocations()->Out().AsRegister<Register>(),
6772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe           Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
6782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6802bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
6812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
6822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
6832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
6842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresRegister());
6852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(1, Location::RequiresRegister());
6862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPokeByte(HInvoke* invoke) {
6892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntToVoidLocations(arena_, invoke);
6902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPokeByte(HInvoke* invoke) {
6932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
6942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ strb(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
6952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe          Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
6962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
6972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
6982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPokeIntNative(HInvoke* invoke) {
6992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntToVoidLocations(arena_, invoke);
7002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPokeIntNative(HInvoke* invoke) {
7032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
7042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ str(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
7052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe         Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
7062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPokeLongNative(HInvoke* invoke) {
7092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntToVoidLocations(arena_, invoke);
7102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPokeLongNative(HInvoke* invoke) {
7132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
7142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Ignore upper 4B of long address.
7152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
7162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
7172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // exception. So we can't use ldrd as addr may be unaligned.
7182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ str(invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>(), Address(addr, 0));
7192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ str(invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>(), Address(addr, 4));
7202bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitMemoryPokeShortNative(HInvoke* invoke) {
7232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntToVoidLocations(arena_, invoke);
7242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitMemoryPokeShortNative(HInvoke* invoke) {
7272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
7282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ strh(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
7292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe          Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
7302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitThreadCurrentThread(HInvoke* invoke) {
7332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena_) LocationSummary(invoke,
7342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                            LocationSummary::kNoCall,
7352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                            kIntrinsified);
7362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister());
7372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitThreadCurrentThread(HInvoke* invoke) {
7402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
7412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ LoadFromOffset(kLoadWord,
7422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                    invoke->GetLocations()->Out().AsRegister<Register>(),
7432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                    TR,
7442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                    Thread::PeerOffset<kArmPointerSize>().Int32Value());
7452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void GenUnsafeGet(HInvoke* invoke,
7482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         Primitive::Type type,
7492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         bool is_volatile,
7502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         CodeGeneratorARM* codegen) {
7512bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = invoke->GetLocations();
7522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  DCHECK((type == Primitive::kPrimInt) ||
7532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe         (type == Primitive::kPrimLong) ||
7542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe         (type == Primitive::kPrimNot));
7552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = codegen->GetAssembler();
7562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register base = locations->InAt(1).AsRegister<Register>();           // Object pointer.
7572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register offset = locations->InAt(2).AsRegisterPairLow<Register>();  // Long offset, lo part only.
7582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (type == Primitive::kPrimLong) {
7602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register trg_lo = locations->Out().AsRegisterPairLow<Register>();
7612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ add(IP, base, ShifterOperand(offset));
7622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
7632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register trg_hi = locations->Out().AsRegisterPairHigh<Register>();
7642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ ldrexd(trg_lo, trg_hi, IP);
7652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    } else {
7662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ ldrd(trg_lo, Address(IP));
7672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    }
7682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
7692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register trg = locations->Out().AsRegister<Register>();
7702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ ldr(trg, Address(base, offset));
7712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
7722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is_volatile) {
7742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ dmb(ISH);
7752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
7764d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain
7774d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain  if (type == Primitive::kPrimNot) {
7784d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    Register trg = locations->Out().AsRegister<Register>();
7794d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    __ MaybeUnpoisonHeapReference(trg);
7804d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain  }
7812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
7842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
7852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
7862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
7872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::NoLocation());        // Unused receiver.
7882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(1, Location::RequiresRegister());
7892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(2, Location::RequiresRegister());
7902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
7932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeGet(HInvoke* invoke) {
7942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntToIntLocations(arena_, invoke);
7952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
7972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntToIntLocations(arena_, invoke);
7982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
7992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeGetLong(HInvoke* invoke) {
8002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntToIntLocations(arena_, invoke);
8012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
8032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntToIntLocations(arena_, invoke);
8042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeGetObject(HInvoke* invoke) {
8062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntToIntLocations(arena_, invoke);
8072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
8092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntToIntLocations(arena_, invoke);
8102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeGet(HInvoke* invoke) {
8132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafeGet(invoke, Primitive::kPrimInt, false, codegen_);
8142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
8162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafeGet(invoke, Primitive::kPrimInt, true, codegen_);
8172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeGetLong(HInvoke* invoke) {
8192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafeGet(invoke, Primitive::kPrimLong, false, codegen_);
8202bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
8222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafeGet(invoke, Primitive::kPrimLong, true, codegen_);
8232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeGetObject(HInvoke* invoke) {
8252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafeGet(invoke, Primitive::kPrimNot, false, codegen_);
8262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
8282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafeGet(invoke, Primitive::kPrimNot, true, codegen_);
8292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntIntIntIntToVoid(ArenaAllocator* arena,
8322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                     const ArmInstructionSetFeatures& features,
8332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                     Primitive::Type type,
8342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                     bool is_volatile,
8352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                     HInvoke* invoke) {
8362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
8372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
8382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
8392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::NoLocation());        // Unused receiver.
8402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(1, Location::RequiresRegister());
8412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(2, Location::RequiresRegister());
8422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(3, Location::RequiresRegister());
8432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (type == Primitive::kPrimLong) {
8452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    // Potentially need temps for ldrexd-strexd loop.
8462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    if (is_volatile && !features.HasAtomicLdrdAndStrd()) {
8472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      locations->AddTemp(Location::RequiresRegister());  // Temp_lo.
8482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      locations->AddTemp(Location::RequiresRegister());  // Temp_hi.
8492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    }
8502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else if (type == Primitive::kPrimNot) {
8512bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    // Temps for card-marking.
8522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    locations->AddTemp(Location::RequiresRegister());  // Temp.
8532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    locations->AddTemp(Location::RequiresRegister());  // Card.
8542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
8552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePut(HInvoke* invoke) {
8582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, false, invoke);
8592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutOrdered(HInvoke* invoke) {
8612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, false, invoke);
8622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutVolatile(HInvoke* invoke) {
8642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, true, invoke);
8652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutObject(HInvoke* invoke) {
8672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, false, invoke);
8682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
8702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, false, invoke);
8712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
8732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, true, invoke);
8742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutLong(HInvoke* invoke) {
8762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimLong, false, invoke);
8772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
8792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimLong, false, invoke);
8802bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
8822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimLong, true, invoke);
8832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
8842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void GenUnsafePut(LocationSummary* locations,
8862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         Primitive::Type type,
8872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         bool is_volatile,
8882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         bool is_ordered,
8892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                         CodeGeneratorARM* codegen) {
8902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = codegen->GetAssembler();
8912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register base = locations->InAt(1).AsRegister<Register>();           // Object pointer.
8932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register offset = locations->InAt(2).AsRegisterPairLow<Register>();  // Long offset, lo part only.
8942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register value;
8952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
8962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is_volatile || is_ordered) {
8972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ dmb(ISH);
8982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
8992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (type == Primitive::kPrimLong) {
9012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>();
9022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    value = value_lo;
9032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
9042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register temp_lo = locations->GetTemp(0).AsRegister<Register>();
9052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register temp_hi = locations->GetTemp(1).AsRegister<Register>();
9062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>();
9072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ add(IP, base, ShifterOperand(offset));
9092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      Label loop_head;
9102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ Bind(&loop_head);
9112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ ldrexd(temp_lo, temp_hi, IP);
9122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ strexd(temp_lo, value_lo, value_hi, IP);
9132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ cmp(temp_lo, ShifterOperand(0));
9142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ b(&loop_head, NE);
9152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    } else {
9162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ add(IP, base, ShifterOperand(offset));
9172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe      __ strd(value_lo, Address(IP));
9182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    }
9192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  } else {
9204d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    value = locations->InAt(3).AsRegister<Register>();
9214d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    Register source = value;
9224d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
9234d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain      Register temp = locations->GetTemp(0).AsRegister<Register>();
9244d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain      __ Mov(temp, value);
9254d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain      __ PoisonHeapReference(temp);
9264d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain      source = temp;
9274d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    }
9284d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    __ str(source, Address(base, offset));
9292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
9302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (is_volatile) {
9322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    __ dmb(ISH);
9332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
9342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (type == Primitive::kPrimNot) {
9362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register temp = locations->GetTemp(0).AsRegister<Register>();
9372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    Register card = locations->GetTemp(1).AsRegister<Register>();
93807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray    bool value_can_be_null = true;  // TODO: Worth finding out this information?
93907276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray    codegen->MarkGCCard(temp, card, base, value, value_can_be_null);
9402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
9412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePut(HInvoke* invoke) {
9442bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, false, codegen_);
9452bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9462bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutOrdered(HInvoke* invoke) {
9472bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, true, codegen_);
9482bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutVolatile(HInvoke* invoke) {
9502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, true, false, codegen_);
9512bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutObject(HInvoke* invoke) {
9532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, false, codegen_);
9542bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
9562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, true, codegen_);
9572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
9592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, true, false, codegen_);
9602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutLong(HInvoke* invoke) {
9622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, false, codegen_);
9632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
9652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, true, codegen_);
9662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
9682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, true, false, codegen_);
9692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena,
9722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                HInvoke* invoke) {
9732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena) LocationSummary(invoke,
9742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           LocationSummary::kNoCall,
9752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                           kIntrinsified);
9762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::NoLocation());        // Unused receiver.
9772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(1, Location::RequiresRegister());
9782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(2, Location::RequiresRegister());
9792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(3, Location::RequiresRegister());
9802bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(4, Location::RequiresRegister());
9812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
9832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->AddTemp(Location::RequiresRegister());  // Pointer.
9852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->AddTemp(Location::RequiresRegister());  // Temp 1.
9862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->AddTemp(Location::RequiresRegister());  // Temp 2.
9872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
9882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampestatic void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM* codegen) {
9902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  DCHECK_NE(type, Primitive::kPrimLong);
9912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = codegen->GetAssembler();
9932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register out = locations->Out().AsRegister<Register>();              // Boolean result.
9952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
9962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register base = locations->InAt(1).AsRegister<Register>();           // Object pointer.
9972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register offset = locations->InAt(2).AsRegisterPairLow<Register>();  // Offset (discard high 4B).
9982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register expected_lo = locations->InAt(3).AsRegister<Register>();    // Expected.
9992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register value_lo = locations->InAt(4).AsRegister<Register>();       // Value.
10002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register tmp_ptr = locations->GetTemp(0).AsRegister<Register>();     // Pointer to actual memory.
10022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register tmp_lo = locations->GetTemp(1).AsRegister<Register>();      // Value in memory.
10032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  if (type == Primitive::kPrimNot) {
10052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    // Mark card for object assuming new value is stored. Worst case we will mark an unchanged
10062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe    // object and scan the receiver at the next GC for nothing.
100707276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray    bool value_can_be_null = true;  // TODO: Worth finding out this information?
100807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray    codegen->MarkGCCard(tmp_ptr, tmp_lo, base, value_lo, value_can_be_null);
10092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  }
10102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Prevent reordering with prior memory operations.
10122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ dmb(ISH);
10132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ add(tmp_ptr, base, ShifterOperand(offset));
10152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10164d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain  if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
10174d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    codegen->GetAssembler()->PoisonHeapReference(expected_lo);
10184d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    codegen->GetAssembler()->PoisonHeapReference(value_lo);
10194d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain  }
10204d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain
10212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // do {
10222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  //   tmp = [r_ptr] - expected;
10232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
10242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // result = tmp != 0;
10252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Label loop_head;
10272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ Bind(&loop_head);
10282bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ ldrex(tmp_lo, tmp_ptr);
10302bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10312bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ subs(tmp_lo, tmp_lo, ShifterOperand(expected_lo));
10322bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10332bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ it(EQ, ItState::kItT);
10342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ strex(tmp_lo, value_lo, tmp_ptr, EQ);
10352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ cmp(tmp_lo, ShifterOperand(1), EQ);
10362bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10372bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ b(&loop_head, EQ);
10382bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10392bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ dmb(ISH);
10402bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10412bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ rsbs(out, tmp_lo, ShifterOperand(1));
10422bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ it(CC);
10432bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ mov(out, ShifterOperand(0), CC);
10444d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain
10454d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain  if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
10464d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    codegen->GetAssembler()->UnpoisonHeapReference(value_lo);
10474d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain    codegen->GetAssembler()->UnpoisonHeapReference(expected_lo);
10484d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain  }
10492bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
10502bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1051ca71458862be8505330b7fd5649a062f31d143dcAndreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeCASInt(HInvoke* invoke) {
10522bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke);
10532bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
1054ca71458862be8505330b7fd5649a062f31d143dcAndreas Gampevoid IntrinsicLocationsBuilderARM::VisitUnsafeCASObject(HInvoke* invoke) {
10552bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke);
10562bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
10572bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeCASInt(HInvoke* invoke) {
10582bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_);
10592bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
10602bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitUnsafeCASObject(HInvoke* invoke) {
10612bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_);
10622bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
10632bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10642bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitStringCharAt(HInvoke* invoke) {
10652bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = new (arena_) LocationSummary(invoke,
10662bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                            LocationSummary::kCallOnSlowPath,
10672bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe                                                            kIntrinsified);
10682bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(0, Location::RequiresRegister());
10692bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetInAt(1, Location::RequiresRegister());
10702bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
10712bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10722bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->AddTemp(Location::RequiresRegister());
10732bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  locations->AddTemp(Location::RequiresRegister());
10742bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
10752bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10762bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitStringCharAt(HInvoke* invoke) {
10772bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  ArmAssembler* assembler = GetAssembler();
10782bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  LocationSummary* locations = invoke->GetLocations();
10792bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10802bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Location of reference to data array
10812bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  const MemberOffset value_offset = mirror::String::ValueOffset();
10822bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Location of count
10832bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  const MemberOffset count_offset = mirror::String::CountOffset();
10842bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10852bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register obj = locations->InAt(0).AsRegister<Register>();  // String object pointer.
10862bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register idx = locations->InAt(1).AsRegister<Register>();  // Index of character.
10872bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register out = locations->Out().AsRegister<Register>();    // Result character.
10882bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10892bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register temp = locations->GetTemp(0).AsRegister<Register>();
10902bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  Register array_temp = locations->GetTemp(1).AsRegister<Register>();
10912bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10922bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // TODO: Maybe we can support range check elimination. Overall, though, I think it's not worth
10932bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  //       the cost.
10942bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // TODO: For simplicity, the index parameter is requested in a register, so different from Quick
10952bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  //       we will not optimize the code for constants (which would save a register).
10962bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
10972bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  SlowPathCodeARM* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
10982bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  codegen_->AddSlowPath(slow_path);
10992bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
11002bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ ldr(temp, Address(obj, count_offset.Int32Value()));          // temp = str.length.
11012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  codegen_->MaybeRecordImplicitNullCheck(invoke);
11022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ cmp(idx, ShifterOperand(temp));
11032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ b(slow_path->GetEntryLabel(), CS);
11042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1105848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ add(array_temp, obj, ShifterOperand(value_offset.Int32Value()));  // array_temp := str.value.
11062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
11072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  // Load the value.
1108848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ ldrh(out, Address(array_temp, idx, LSL, 1));                 // out := array_temp[idx].
11092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
11102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe  __ Bind(slow_path->GetExitLabel());
11112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
11122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
1113d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffrayvoid IntrinsicLocationsBuilderARM::VisitStringCompareTo(HInvoke* invoke) {
1114d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  // The inputs plus one temp.
1115d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1116d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray                                                            LocationSummary::kCall,
1117d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray                                                            kIntrinsified);
1118d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  InvokeRuntimeCallingConvention calling_convention;
1119d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1120d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1121d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  locations->SetOut(Location::RegisterLocation(R0));
1122d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray}
1123d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
1124d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffrayvoid IntrinsicCodeGeneratorARM::VisitStringCompareTo(HInvoke* invoke) {
1125d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  ArmAssembler* assembler = GetAssembler();
1126d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  LocationSummary* locations = invoke->GetLocations();
1127d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
1128512e04d1ea7fb33e3992715fe55be8a834d4a79cNicolas Geoffray  // Note that the null check must have been done earlier.
1129641547a5f18ca2ea54469cceadcfef64f132e5e0Calin Juravle  DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1130d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
1131d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  Register argument = locations->InAt(1).AsRegister<Register>();
1132d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  __ cmp(argument, ShifterOperand(0));
1133d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  SlowPathCodeARM* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1134d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  codegen_->AddSlowPath(slow_path);
1135d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  __ b(slow_path->GetEntryLabel(), EQ);
1136d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
1137d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  __ LoadFromOffset(
1138d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray      kLoadWord, LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pStringCompareTo).Int32Value());
1139d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  __ blx(LR);
1140d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  __ Bind(slow_path->GetExitLabel());
1141d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray}
1142d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
1143289cd55808111d23c92f2739a096942a8049649aAgi Csakivoid IntrinsicLocationsBuilderARM::VisitStringEquals(HInvoke* invoke) {
1144289cd55808111d23c92f2739a096942a8049649aAgi Csaki  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1145289cd55808111d23c92f2739a096942a8049649aAgi Csaki                                                            LocationSummary::kNoCall,
1146289cd55808111d23c92f2739a096942a8049649aAgi Csaki                                                            kIntrinsified);
1147289cd55808111d23c92f2739a096942a8049649aAgi Csaki  InvokeRuntimeCallingConvention calling_convention;
1148289cd55808111d23c92f2739a096942a8049649aAgi Csaki  locations->SetInAt(0, Location::RequiresRegister());
1149289cd55808111d23c92f2739a096942a8049649aAgi Csaki  locations->SetInAt(1, Location::RequiresRegister());
1150289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Temporary registers to store lengths of strings and for calculations.
1151289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Using instruction cbz requires a low register, so explicitly set a temp to be R0.
1152289cd55808111d23c92f2739a096942a8049649aAgi Csaki  locations->AddTemp(Location::RegisterLocation(R0));
1153289cd55808111d23c92f2739a096942a8049649aAgi Csaki  locations->AddTemp(Location::RequiresRegister());
1154289cd55808111d23c92f2739a096942a8049649aAgi Csaki  locations->AddTemp(Location::RequiresRegister());
1155289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1156289cd55808111d23c92f2739a096942a8049649aAgi Csaki  locations->SetOut(Location::RequiresRegister());
1157289cd55808111d23c92f2739a096942a8049649aAgi Csaki}
1158289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1159289cd55808111d23c92f2739a096942a8049649aAgi Csakivoid IntrinsicCodeGeneratorARM::VisitStringEquals(HInvoke* invoke) {
1160289cd55808111d23c92f2739a096942a8049649aAgi Csaki  ArmAssembler* assembler = GetAssembler();
1161289cd55808111d23c92f2739a096942a8049649aAgi Csaki  LocationSummary* locations = invoke->GetLocations();
1162289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1163289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Register str = locations->InAt(0).AsRegister<Register>();
1164289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Register arg = locations->InAt(1).AsRegister<Register>();
1165289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Register out = locations->Out().AsRegister<Register>();
1166289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1167289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Register temp = locations->GetTemp(0).AsRegister<Register>();
1168289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1169289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1170289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1171289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Label loop;
1172289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Label end;
1173289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Label return_true;
1174289cd55808111d23c92f2739a096942a8049649aAgi Csaki  Label return_false;
1175289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1176289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Get offsets of count, value, and class fields within a string object.
1177289cd55808111d23c92f2739a096942a8049649aAgi Csaki  const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1178289cd55808111d23c92f2739a096942a8049649aAgi Csaki  const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1179289cd55808111d23c92f2739a096942a8049649aAgi Csaki  const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1180289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1181289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Note that the null check must have been done earlier.
1182289cd55808111d23c92f2739a096942a8049649aAgi Csaki  DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1183289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1184289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Check if input is null, return false if it is.
1185289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ CompareAndBranchIfZero(arg, &return_false);
1186289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1187289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Instanceof check for the argument by comparing class fields.
1188289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // All string objects must have the same type since String cannot be subclassed.
1189289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Receiver must be a string object, so its class field is equal to all strings' class fields.
1190289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // If the argument is a string object, its class field must be equal to receiver's class field.
1191289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ ldr(temp, Address(str, class_offset));
1192289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ ldr(temp1, Address(arg, class_offset));
1193289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ cmp(temp, ShifterOperand(temp1));
1194289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ b(&return_false, NE);
1195289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1196289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Load lengths of this and argument strings.
1197289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ ldr(temp, Address(str, count_offset));
1198289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ ldr(temp1, Address(arg, count_offset));
1199289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Check if lengths are equal, return false if they're not.
1200289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ cmp(temp, ShifterOperand(temp1));
1201289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ b(&return_false, NE);
1202289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Return true if both strings are empty.
1203289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ cbz(temp, &return_true);
1204289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1205289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Reference equality check, return true if same reference.
1206289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ cmp(str, ShifterOperand(arg));
1207289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ b(&return_true, EQ);
1208289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1209289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Assertions that must hold in order to compare strings 2 characters at a time.
1210289cd55808111d23c92f2739a096942a8049649aAgi Csaki  DCHECK_ALIGNED(value_offset, 4);
1211289cd55808111d23c92f2739a096942a8049649aAgi Csaki  static_assert(IsAligned<4>(kObjectAlignment), "String of odd length is not zero padded");
1212289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1213289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ LoadImmediate(temp1, value_offset);
1214289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1215289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Loop to compare strings 2 characters at a time starting at the front of the string.
1216289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Ok to do this because strings with an odd length are zero-padded.
1217289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ Bind(&loop);
1218289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ ldr(out, Address(str, temp1));
1219289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ ldr(temp2, Address(arg, temp1));
1220289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ cmp(out, ShifterOperand(temp2));
1221289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ b(&return_false, NE);
1222289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ add(temp1, temp1, ShifterOperand(sizeof(uint32_t)));
1223a63f0d47edbcbe13a23411851a9c6e81f9342cc2Vladimir Marko  __ subs(temp, temp, ShifterOperand(sizeof(uint32_t) /  sizeof(uint16_t)));
1224a63f0d47edbcbe13a23411851a9c6e81f9342cc2Vladimir Marko  __ b(&loop, GT);
1225289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1226289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Return true and exit the function.
1227289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // If loop does not result in returning false, we return true.
1228289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ Bind(&return_true);
1229289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ LoadImmediate(out, 1);
1230289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ b(&end);
1231289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1232289cd55808111d23c92f2739a096942a8049649aAgi Csaki  // Return false and exit the function.
1233289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ Bind(&return_false);
1234289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ LoadImmediate(out, 0);
1235289cd55808111d23c92f2739a096942a8049649aAgi Csaki  __ Bind(&end);
1236289cd55808111d23c92f2739a096942a8049649aAgi Csaki}
1237289cd55808111d23c92f2739a096942a8049649aAgi Csaki
1238ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampestatic void GenerateVisitStringIndexOf(HInvoke* invoke,
1239ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                       ArmAssembler* assembler,
1240ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                       CodeGeneratorARM* codegen,
1241ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                       ArenaAllocator* allocator,
1242ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                       bool start_at_zero) {
1243ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  LocationSummary* locations = invoke->GetLocations();
1244ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  Register tmp_reg = locations->GetTemp(0).AsRegister<Register>();
1245ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1246ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // Note that the null check must have been done earlier.
1247ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1248ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1249ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
1250ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // or directly dispatch if we have a constant.
1251ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  SlowPathCodeARM* slow_path = nullptr;
1252ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  if (invoke->InputAt(1)->IsIntConstant()) {
1253ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    if (static_cast<uint32_t>(invoke->InputAt(1)->AsIntConstant()->GetValue()) >
1254ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe        std::numeric_limits<uint16_t>::max()) {
1255ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      // Always needs the slow-path. We could directly dispatch to it, but this case should be
1256ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      // rare, so for simplicity just put the full slow-path down and branch unconditionally.
1257ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1258ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      codegen->AddSlowPath(slow_path);
1259ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      __ b(slow_path->GetEntryLabel());
1260ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      __ Bind(slow_path->GetExitLabel());
1261ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe      return;
1262ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    }
1263ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  } else {
1264ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    Register char_reg = locations->InAt(1).AsRegister<Register>();
1265ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    __ LoadImmediate(tmp_reg, std::numeric_limits<uint16_t>::max());
1266ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    __ cmp(char_reg, ShifterOperand(tmp_reg));
1267ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1268ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    codegen->AddSlowPath(slow_path);
1269ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    __ b(slow_path->GetEntryLabel(), HI);
1270ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  }
1271ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1272ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  if (start_at_zero) {
1273ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    DCHECK_EQ(tmp_reg, R2);
1274ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    // Start-index = 0.
1275ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    __ LoadImmediate(tmp_reg, 0);
1276ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  }
1277ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1278ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  __ LoadFromOffset(kLoadWord, LR, TR,
1279ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                    QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pIndexOf).Int32Value());
1280ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  __ blx(LR);
1281ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1282ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  if (slow_path != nullptr) {
1283ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe    __ Bind(slow_path->GetExitLabel());
1284ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  }
1285ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe}
1286ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1287ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) {
1288ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1289ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                                            LocationSummary::kCall,
1290ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                                            kIntrinsified);
1291ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1292ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // best to align the inputs accordingly.
1293ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  InvokeRuntimeCallingConvention calling_convention;
1294ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1295ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1296ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetOut(Location::RegisterLocation(R0));
1297ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1298ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // Need a temp for slow-path codepoint compare, and need to send start-index=0.
1299ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1300ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe}
1301ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1302ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) {
1303ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  GenerateVisitStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), true);
1304ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe}
1305ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1306ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampevoid IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) {
1307ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1308ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                                            LocationSummary::kCall,
1309ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe                                                            kIntrinsified);
1310ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1311ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // best to align the inputs accordingly.
1312ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  InvokeRuntimeCallingConvention calling_convention;
1313ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1314ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1315ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1316ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->SetOut(Location::RegisterLocation(R0));
1317ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1318ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  // Need a temp for slow-path codepoint compare.
1319ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  locations->AddTemp(Location::RequiresRegister());
1320ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe}
1321ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1322ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampevoid IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) {
1323ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe  GenerateVisitStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), false);
1324ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe}
1325ba6fdbcb764d5a8972f5ff2d7147e4d78226b347Andreas Gampe
1326848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haovoid IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1327848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1328848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao                                                            LocationSummary::kCall,
1329848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao                                                            kIntrinsified);
1330848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  InvokeRuntimeCallingConvention calling_convention;
1331848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1332848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1333848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1334848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1335848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetOut(Location::RegisterLocation(R0));
1336848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao}
1337848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1338848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haovoid IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1339848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  ArmAssembler* assembler = GetAssembler();
1340848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  LocationSummary* locations = invoke->GetLocations();
1341848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1342848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  Register byte_array = locations->InAt(0).AsRegister<Register>();
1343848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ cmp(byte_array, ShifterOperand(0));
1344848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  SlowPathCodeARM* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1345848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  codegen_->AddSlowPath(slow_path);
1346848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ b(slow_path->GetEntryLabel(), EQ);
1347848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1348848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ LoadFromOffset(
1349848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao      kLoadWord, LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocStringFromBytes).Int32Value());
1350848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1351848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ blx(LR);
1352848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ Bind(slow_path->GetExitLabel());
1353848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao}
1354848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1355848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haovoid IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1356848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1357848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao                                                            LocationSummary::kCall,
1358848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao                                                            kIntrinsified);
1359848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  InvokeRuntimeCallingConvention calling_convention;
1360848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1361848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1362848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1363848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetOut(Location::RegisterLocation(R0));
1364848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao}
1365848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1366848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haovoid IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1367848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  ArmAssembler* assembler = GetAssembler();
1368848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1369848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ LoadFromOffset(
1370848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao      kLoadWord, LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocStringFromChars).Int32Value());
1371848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1372848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ blx(LR);
1373848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao}
1374848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1375848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haovoid IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) {
1376848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  LocationSummary* locations = new (arena_) LocationSummary(invoke,
1377848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao                                                            LocationSummary::kCall,
1378848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao                                                            kIntrinsified);
1379848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  InvokeRuntimeCallingConvention calling_convention;
1380848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1381848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  locations->SetOut(Location::RegisterLocation(R0));
1382848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao}
1383848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1384848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haovoid IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) {
1385848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  ArmAssembler* assembler = GetAssembler();
1386848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  LocationSummary* locations = invoke->GetLocations();
1387848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1388848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  Register string_to_copy = locations->InAt(0).AsRegister<Register>();
1389848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ cmp(string_to_copy, ShifterOperand(0));
1390848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  SlowPathCodeARM* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1391848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  codegen_->AddSlowPath(slow_path);
1392848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ b(slow_path->GetEntryLabel(), EQ);
1393848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
1394848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ LoadFromOffset(kLoadWord,
1395848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao      LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocStringFromString).Int32Value());
1396848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1397848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ blx(LR);
1398848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao  __ Bind(slow_path->GetExitLabel());
1399848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao}
1400848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao
14012bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe// Unimplemented intrinsics.
14022bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
14032bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe#define UNIMPLEMENTED_INTRINSIC(Name)                                                  \
14042bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicLocationsBuilderARM::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
14052bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}                                                                                      \
14062bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampevoid IntrinsicCodeGeneratorARM::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) {    \
14072bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}
14082bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
14092bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(IntegerReverse)
14102bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(IntegerReverseBytes)
14112bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(LongReverse)
14122bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(LongReverseBytes)
14132bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(ShortReverseBytes)
14142bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathMinDoubleDouble)
14152bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathMinFloatFloat)
14162bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathMaxDoubleDouble)
14172bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathMaxFloatFloat)
14182bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathMinLongLong)
14192bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathMaxLongLong)
14202bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathCeil)          // Could be done by changing rounding mode, maybe?
14212bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathFloor)         // Could be done by changing rounding mode, maybe?
14222bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathRint)
14232bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathRoundDouble)   // Could be done by changing rounding mode, maybe?
14242bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(MathRoundFloat)    // Could be done by changing rounding mode, maybe?
14252bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(UnsafeCASLong)     // High register pressure.
14262bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar)
14272bcf9bf784a0021630d8fe63d7230d46d6891780Andreas GampeUNIMPLEMENTED_INTRINSIC(ReferenceGetReferent)
1428848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff HaoUNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck)
14292bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe
14304d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain#undef UNIMPLEMENTED_INTRINSIC
14314d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain
14324d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain#undef __
14334d02711ea578dbb789abb30cbaf12f9926e13d81Roland Levillain
14342bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}  // namespace arm
14352bcf9bf784a0021630d8fe63d7230d46d6891780Andreas Gampe}  // namespace art
1436