Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "intrinsics_mips.h" |
| 18 | |
| 19 | #include "arch/mips/instruction_set_features_mips.h" |
| 20 | #include "art_method.h" |
| 21 | #include "code_generator_mips.h" |
| 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | #include "intrinsics.h" |
| 24 | #include "mirror/array-inl.h" |
| 25 | #include "mirror/string.h" |
| 26 | #include "thread.h" |
| 27 | #include "utils/mips/assembler_mips.h" |
| 28 | #include "utils/mips/constants_mips.h" |
| 29 | |
| 30 | namespace art { |
| 31 | |
| 32 | namespace mips { |
| 33 | |
| 34 | IntrinsicLocationsBuilderMIPS::IntrinsicLocationsBuilderMIPS(CodeGeneratorMIPS* codegen) |
| 35 | : arena_(codegen->GetGraph()->GetArena()) { |
| 36 | } |
| 37 | |
| 38 | MipsAssembler* IntrinsicCodeGeneratorMIPS::GetAssembler() { |
| 39 | return reinterpret_cast<MipsAssembler*>(codegen_->GetAssembler()); |
| 40 | } |
| 41 | |
| 42 | ArenaAllocator* IntrinsicCodeGeneratorMIPS::GetAllocator() { |
| 43 | return codegen_->GetGraph()->GetArena(); |
| 44 | } |
| 45 | |
| 46 | #define __ codegen->GetAssembler()-> |
| 47 | |
| 48 | static void MoveFromReturnRegister(Location trg, |
| 49 | Primitive::Type type, |
| 50 | CodeGeneratorMIPS* codegen) { |
| 51 | if (!trg.IsValid()) { |
| 52 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 57 | |
| 58 | if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) { |
| 59 | Register trg_reg = trg.AsRegister<Register>(); |
| 60 | if (trg_reg != V0) { |
| 61 | __ Move(V0, trg_reg); |
| 62 | } |
| 63 | } else { |
| 64 | FRegister trg_reg = trg.AsFpuRegister<FRegister>(); |
| 65 | if (trg_reg != F0) { |
| 66 | if (type == Primitive::kPrimFloat) { |
| 67 | __ MovS(F0, trg_reg); |
| 68 | } else { |
| 69 | __ MovD(F0, trg_reg); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static void MoveArguments(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
| 76 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 77 | IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor); |
| 78 | } |
| 79 | |
| 80 | // Slow-path for fallback (calling the managed code to handle the |
| 81 | // intrinsic) in an intrinsified call. This will copy the arguments |
| 82 | // into the positions for a regular call. |
| 83 | // |
| 84 | // Note: The actual parameters are required to be in the locations |
| 85 | // given by the invoke's location summary. If an intrinsic |
| 86 | // modifies those locations before a slowpath call, they must be |
| 87 | // restored! |
| 88 | class IntrinsicSlowPathMIPS : public SlowPathCodeMIPS { |
| 89 | public: |
| 90 | explicit IntrinsicSlowPathMIPS(HInvoke* invoke) : invoke_(invoke) { } |
| 91 | |
| 92 | void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE { |
| 93 | CodeGeneratorMIPS* codegen = down_cast<CodeGeneratorMIPS*>(codegen_in); |
| 94 | |
| 95 | __ Bind(GetEntryLabel()); |
| 96 | |
| 97 | SaveLiveRegisters(codegen, invoke_->GetLocations()); |
| 98 | |
| 99 | MoveArguments(invoke_, codegen); |
| 100 | |
| 101 | if (invoke_->IsInvokeStaticOrDirect()) { |
| 102 | codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(), |
| 103 | Location::RegisterLocation(A0)); |
| 104 | codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this); |
| 105 | } else { |
| 106 | UNIMPLEMENTED(FATAL) << "Non-direct intrinsic slow-path not yet implemented"; |
| 107 | UNREACHABLE(); |
| 108 | } |
| 109 | |
| 110 | // Copy the result back to the expected output. |
| 111 | Location out = invoke_->GetLocations()->Out(); |
| 112 | if (out.IsValid()) { |
| 113 | DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory. |
| 114 | DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 115 | MoveFromReturnRegister(out, invoke_->GetType(), codegen); |
| 116 | } |
| 117 | |
| 118 | RestoreLiveRegisters(codegen, invoke_->GetLocations()); |
| 119 | __ B(GetExitLabel()); |
| 120 | } |
| 121 | |
| 122 | const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathMIPS"; } |
| 123 | |
| 124 | private: |
| 125 | // The instruction where this slow path is happening. |
| 126 | HInvoke* const invoke_; |
| 127 | |
| 128 | DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathMIPS); |
| 129 | }; |
| 130 | |
| 131 | #undef __ |
| 132 | |
| 133 | bool IntrinsicLocationsBuilderMIPS::TryDispatch(HInvoke* invoke) { |
| 134 | Dispatch(invoke); |
| 135 | LocationSummary* res = invoke->GetLocations(); |
| 136 | return res != nullptr && res->Intrinsified(); |
| 137 | } |
| 138 | |
| 139 | #define __ assembler-> |
| 140 | |
| 141 | // Unimplemented intrinsics. |
| 142 | |
| 143 | #define UNIMPLEMENTED_INTRINSIC(Name) \ |
| 144 | void IntrinsicLocationsBuilderMIPS::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 145 | } \ |
| 146 | void IntrinsicCodeGeneratorMIPS::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 147 | } |
| 148 | |
| 149 | UNIMPLEMENTED_INTRINSIC(IntegerReverse) |
| 150 | UNIMPLEMENTED_INTRINSIC(LongReverse) |
| 151 | UNIMPLEMENTED_INTRINSIC(ShortReverseBytes) |
| 152 | UNIMPLEMENTED_INTRINSIC(IntegerReverseBytes) |
| 153 | UNIMPLEMENTED_INTRINSIC(LongReverseBytes) |
| 154 | UNIMPLEMENTED_INTRINSIC(LongNumberOfLeadingZeros) |
| 155 | UNIMPLEMENTED_INTRINSIC(IntegerNumberOfLeadingZeros) |
| 156 | UNIMPLEMENTED_INTRINSIC(FloatIntBitsToFloat) |
| 157 | UNIMPLEMENTED_INTRINSIC(DoubleLongBitsToDouble) |
| 158 | UNIMPLEMENTED_INTRINSIC(FloatFloatToRawIntBits) |
| 159 | UNIMPLEMENTED_INTRINSIC(DoubleDoubleToRawLongBits) |
| 160 | UNIMPLEMENTED_INTRINSIC(MathAbsDouble) |
| 161 | UNIMPLEMENTED_INTRINSIC(MathAbsFloat) |
| 162 | UNIMPLEMENTED_INTRINSIC(MathAbsInt) |
| 163 | UNIMPLEMENTED_INTRINSIC(MathAbsLong) |
| 164 | UNIMPLEMENTED_INTRINSIC(MathMinDoubleDouble) |
| 165 | UNIMPLEMENTED_INTRINSIC(MathMinFloatFloat) |
| 166 | UNIMPLEMENTED_INTRINSIC(MathMaxDoubleDouble) |
| 167 | UNIMPLEMENTED_INTRINSIC(MathMaxFloatFloat) |
| 168 | UNIMPLEMENTED_INTRINSIC(MathMinIntInt) |
| 169 | UNIMPLEMENTED_INTRINSIC(MathMinLongLong) |
| 170 | UNIMPLEMENTED_INTRINSIC(MathMaxIntInt) |
| 171 | UNIMPLEMENTED_INTRINSIC(MathMaxLongLong) |
| 172 | UNIMPLEMENTED_INTRINSIC(MathSqrt) |
| 173 | UNIMPLEMENTED_INTRINSIC(MathCeil) |
| 174 | UNIMPLEMENTED_INTRINSIC(MathFloor) |
| 175 | UNIMPLEMENTED_INTRINSIC(MathRint) |
| 176 | UNIMPLEMENTED_INTRINSIC(MathRoundDouble) |
| 177 | UNIMPLEMENTED_INTRINSIC(MathRoundFloat) |
| 178 | UNIMPLEMENTED_INTRINSIC(MemoryPeekByte) |
| 179 | UNIMPLEMENTED_INTRINSIC(MemoryPeekIntNative) |
| 180 | UNIMPLEMENTED_INTRINSIC(MemoryPeekLongNative) |
| 181 | UNIMPLEMENTED_INTRINSIC(MemoryPeekShortNative) |
| 182 | UNIMPLEMENTED_INTRINSIC(MemoryPokeByte) |
| 183 | UNIMPLEMENTED_INTRINSIC(MemoryPokeIntNative) |
| 184 | UNIMPLEMENTED_INTRINSIC(MemoryPokeLongNative) |
| 185 | UNIMPLEMENTED_INTRINSIC(MemoryPokeShortNative) |
| 186 | UNIMPLEMENTED_INTRINSIC(ThreadCurrentThread) |
| 187 | UNIMPLEMENTED_INTRINSIC(UnsafeGet) |
| 188 | UNIMPLEMENTED_INTRINSIC(UnsafeGetVolatile) |
| 189 | UNIMPLEMENTED_INTRINSIC(UnsafeGetLong) |
| 190 | UNIMPLEMENTED_INTRINSIC(UnsafeGetLongVolatile) |
| 191 | UNIMPLEMENTED_INTRINSIC(UnsafeGetObject) |
| 192 | UNIMPLEMENTED_INTRINSIC(UnsafeGetObjectVolatile) |
| 193 | UNIMPLEMENTED_INTRINSIC(UnsafePut) |
| 194 | UNIMPLEMENTED_INTRINSIC(UnsafePutOrdered) |
| 195 | UNIMPLEMENTED_INTRINSIC(UnsafePutVolatile) |
| 196 | UNIMPLEMENTED_INTRINSIC(UnsafePutObject) |
| 197 | UNIMPLEMENTED_INTRINSIC(UnsafePutObjectOrdered) |
| 198 | UNIMPLEMENTED_INTRINSIC(UnsafePutObjectVolatile) |
| 199 | UNIMPLEMENTED_INTRINSIC(UnsafePutLong) |
| 200 | UNIMPLEMENTED_INTRINSIC(UnsafePutLongOrdered) |
| 201 | UNIMPLEMENTED_INTRINSIC(UnsafePutLongVolatile) |
| 202 | UNIMPLEMENTED_INTRINSIC(UnsafeCASInt) |
| 203 | UNIMPLEMENTED_INTRINSIC(UnsafeCASLong) |
| 204 | UNIMPLEMENTED_INTRINSIC(UnsafeCASObject) |
| 205 | UNIMPLEMENTED_INTRINSIC(StringCharAt) |
| 206 | UNIMPLEMENTED_INTRINSIC(StringCompareTo) |
| 207 | UNIMPLEMENTED_INTRINSIC(StringEquals) |
| 208 | UNIMPLEMENTED_INTRINSIC(StringIndexOf) |
| 209 | UNIMPLEMENTED_INTRINSIC(StringIndexOfAfter) |
| 210 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromBytes) |
| 211 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromChars) |
| 212 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromString) |
| 213 | UNIMPLEMENTED_INTRINSIC(LongRotateLeft) |
| 214 | UNIMPLEMENTED_INTRINSIC(LongRotateRight) |
| 215 | UNIMPLEMENTED_INTRINSIC(LongNumberOfTrailingZeros) |
| 216 | UNIMPLEMENTED_INTRINSIC(IntegerRotateLeft) |
| 217 | UNIMPLEMENTED_INTRINSIC(IntegerRotateRight) |
| 218 | UNIMPLEMENTED_INTRINSIC(IntegerNumberOfTrailingZeros) |
| 219 | |
| 220 | UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent) |
| 221 | UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck) |
| 222 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar) |
| 223 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopy) |
| 224 | |
| 225 | #undef UNIMPLEMENTED_INTRINSIC |
| 226 | |
| 227 | #undef __ |
| 228 | |
| 229 | } // namespace mips |
| 230 | } // namespace art |