Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "intrinsics_mips64.h" |
| 18 | |
| 19 | #include "arch/mips64/instruction_set_features_mips64.h" |
| 20 | #include "art_method.h" |
| 21 | #include "code_generator_mips64.h" |
| 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | #include "intrinsics.h" |
| 24 | #include "mirror/array-inl.h" |
| 25 | #include "mirror/string.h" |
| 26 | #include "thread.h" |
| 27 | #include "utils/mips64/assembler_mips64.h" |
| 28 | #include "utils/mips64/constants_mips64.h" |
| 29 | |
| 30 | namespace art { |
| 31 | |
| 32 | namespace mips64 { |
| 33 | |
| 34 | IntrinsicLocationsBuilderMIPS64::IntrinsicLocationsBuilderMIPS64(CodeGeneratorMIPS64* codegen) |
| 35 | : arena_(codegen->GetGraph()->GetArena()) { |
| 36 | } |
| 37 | |
| 38 | Mips64Assembler* IntrinsicCodeGeneratorMIPS64::GetAssembler() { |
| 39 | return reinterpret_cast<Mips64Assembler*>(codegen_->GetAssembler()); |
| 40 | } |
| 41 | |
| 42 | ArenaAllocator* IntrinsicCodeGeneratorMIPS64::GetAllocator() { |
| 43 | return codegen_->GetGraph()->GetArena(); |
| 44 | } |
| 45 | |
| 46 | bool IntrinsicLocationsBuilderMIPS64::TryDispatch(HInvoke* invoke) { |
| 47 | Dispatch(invoke); |
| 48 | LocationSummary* res = invoke->GetLocations(); |
| 49 | return res != nullptr && res->Intrinsified(); |
| 50 | } |
| 51 | |
| 52 | #define __ assembler-> |
| 53 | |
| 54 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 55 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 56 | LocationSummary::kNoCall, |
| 57 | kIntrinsified); |
| 58 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 59 | locations->SetOut(Location::RequiresRegister()); |
| 60 | } |
| 61 | |
| 62 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 63 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 64 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 65 | |
| 66 | if (is64bit) { |
| 67 | __ Dmfc1(out, in); |
| 68 | } else { |
| 69 | __ Mfc1(out, in); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // long java.lang.Double.doubleToRawLongBits(double) |
| 74 | void IntrinsicLocationsBuilderMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 75 | CreateFPToIntLocations(arena_, invoke); |
| 76 | } |
| 77 | |
| 78 | void IntrinsicCodeGeneratorMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 79 | MoveFPToInt(invoke->GetLocations(), true, GetAssembler()); |
| 80 | } |
| 81 | |
| 82 | // int java.lang.Float.floatToRawIntBits(float) |
| 83 | void IntrinsicLocationsBuilderMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 84 | CreateFPToIntLocations(arena_, invoke); |
| 85 | } |
| 86 | |
| 87 | void IntrinsicCodeGeneratorMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 88 | MoveFPToInt(invoke->GetLocations(), false, GetAssembler()); |
| 89 | } |
| 90 | |
| 91 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 92 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 93 | LocationSummary::kNoCall, |
| 94 | kIntrinsified); |
| 95 | locations->SetInAt(0, Location::RequiresRegister()); |
| 96 | locations->SetOut(Location::RequiresFpuRegister()); |
| 97 | } |
| 98 | |
| 99 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 100 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 101 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 102 | |
| 103 | if (is64bit) { |
| 104 | __ Dmtc1(in, out); |
| 105 | } else { |
| 106 | __ Mtc1(in, out); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // double java.lang.Double.longBitsToDouble(long) |
| 111 | void IntrinsicLocationsBuilderMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 112 | CreateIntToFPLocations(arena_, invoke); |
| 113 | } |
| 114 | |
| 115 | void IntrinsicCodeGeneratorMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 116 | MoveIntToFP(invoke->GetLocations(), true, GetAssembler()); |
| 117 | } |
| 118 | |
| 119 | // float java.lang.Float.intBitsToFloat(int) |
| 120 | void IntrinsicLocationsBuilderMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 121 | CreateIntToFPLocations(arena_, invoke); |
| 122 | } |
| 123 | |
| 124 | void IntrinsicCodeGeneratorMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 125 | MoveIntToFP(invoke->GetLocations(), false, GetAssembler()); |
| 126 | } |
| 127 | |
| 128 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 129 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 130 | LocationSummary::kNoCall, |
| 131 | kIntrinsified); |
| 132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 133 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 134 | } |
| 135 | |
| 136 | static void GenReverseBytes(LocationSummary* locations, |
| 137 | Primitive::Type type, |
| 138 | Mips64Assembler* assembler) { |
| 139 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 140 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 141 | |
| 142 | switch (type) { |
| 143 | case Primitive::kPrimShort: |
| 144 | __ Dsbh(out, in); |
| 145 | __ Seh(out, out); |
| 146 | break; |
| 147 | case Primitive::kPrimInt: |
| 148 | __ Rotr(out, in, 16); |
| 149 | __ Wsbh(out, out); |
| 150 | break; |
| 151 | case Primitive::kPrimLong: |
| 152 | __ Dsbh(out, in); |
| 153 | __ Dshd(out, out); |
| 154 | break; |
| 155 | default: |
| 156 | LOG(FATAL) << "Unexpected size for reverse-bytes: " << type; |
| 157 | UNREACHABLE(); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // int java.lang.Integer.reverseBytes(int) |
| 162 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 163 | CreateIntToIntLocations(arena_, invoke); |
| 164 | } |
| 165 | |
| 166 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 167 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 168 | } |
| 169 | |
| 170 | // long java.lang.Long.reverseBytes(long) |
| 171 | void IntrinsicLocationsBuilderMIPS64::VisitLongReverseBytes(HInvoke* invoke) { |
| 172 | CreateIntToIntLocations(arena_, invoke); |
| 173 | } |
| 174 | |
| 175 | void IntrinsicCodeGeneratorMIPS64::VisitLongReverseBytes(HInvoke* invoke) { |
| 176 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 177 | } |
| 178 | |
| 179 | // short java.lang.Short.reverseBytes(short) |
| 180 | void IntrinsicLocationsBuilderMIPS64::VisitShortReverseBytes(HInvoke* invoke) { |
| 181 | CreateIntToIntLocations(arena_, invoke); |
| 182 | } |
| 183 | |
| 184 | void IntrinsicCodeGeneratorMIPS64::VisitShortReverseBytes(HInvoke* invoke) { |
| 185 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetAssembler()); |
| 186 | } |
| 187 | |
| 188 | static void GenCountZeroes(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 189 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 190 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 191 | |
| 192 | if (is64bit) { |
| 193 | __ Dclz(out, in); |
| 194 | } else { |
| 195 | __ Clz(out, in); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // int java.lang.Integer.numberOfLeadingZeros(int i) |
| 200 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 201 | CreateIntToIntLocations(arena_, invoke); |
| 202 | } |
| 203 | |
| 204 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 205 | GenCountZeroes(invoke->GetLocations(), false, GetAssembler()); |
| 206 | } |
| 207 | |
| 208 | // int java.lang.Long.numberOfLeadingZeros(long i) |
| 209 | void IntrinsicLocationsBuilderMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 210 | CreateIntToIntLocations(arena_, invoke); |
| 211 | } |
| 212 | |
| 213 | void IntrinsicCodeGeneratorMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 214 | GenCountZeroes(invoke->GetLocations(), true, GetAssembler()); |
| 215 | } |
| 216 | |
| 217 | static void GenReverse(LocationSummary* locations, |
| 218 | Primitive::Type type, |
| 219 | Mips64Assembler* assembler) { |
| 220 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 221 | |
| 222 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 223 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 224 | |
| 225 | if (type == Primitive::kPrimInt) { |
| 226 | __ Rotr(out, in, 16); |
| 227 | __ Wsbh(out, out); |
| 228 | __ Bitswap(out, out); |
| 229 | } else { |
| 230 | __ Dsbh(out, in); |
| 231 | __ Dshd(out, out); |
| 232 | __ Dbitswap(out, out); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // int java.lang.Integer.reverse(int) |
| 237 | void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverse(HInvoke* invoke) { |
| 238 | CreateIntToIntLocations(arena_, invoke); |
| 239 | } |
| 240 | |
| 241 | void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverse(HInvoke* invoke) { |
| 242 | GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 243 | } |
| 244 | |
| 245 | // long java.lang.Long.reverse(long) |
| 246 | void IntrinsicLocationsBuilderMIPS64::VisitLongReverse(HInvoke* invoke) { |
| 247 | CreateIntToIntLocations(arena_, invoke); |
| 248 | } |
| 249 | |
| 250 | void IntrinsicCodeGeneratorMIPS64::VisitLongReverse(HInvoke* invoke) { |
| 251 | GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 252 | } |
| 253 | |
| 254 | // Unimplemented intrinsics. |
| 255 | |
| 256 | #define UNIMPLEMENTED_INTRINSIC(Name) \ |
| 257 | void IntrinsicLocationsBuilderMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 258 | } \ |
| 259 | void IntrinsicCodeGeneratorMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 260 | } |
| 261 | |
| 262 | UNIMPLEMENTED_INTRINSIC(MathAbsDouble) |
| 263 | UNIMPLEMENTED_INTRINSIC(MathAbsFloat) |
| 264 | UNIMPLEMENTED_INTRINSIC(MathAbsInt) |
| 265 | UNIMPLEMENTED_INTRINSIC(MathAbsLong) |
| 266 | UNIMPLEMENTED_INTRINSIC(MathMinDoubleDouble) |
| 267 | UNIMPLEMENTED_INTRINSIC(MathMinFloatFloat) |
| 268 | UNIMPLEMENTED_INTRINSIC(MathMaxDoubleDouble) |
| 269 | UNIMPLEMENTED_INTRINSIC(MathMaxFloatFloat) |
| 270 | UNIMPLEMENTED_INTRINSIC(MathMinIntInt) |
| 271 | UNIMPLEMENTED_INTRINSIC(MathMinLongLong) |
| 272 | UNIMPLEMENTED_INTRINSIC(MathMaxIntInt) |
| 273 | UNIMPLEMENTED_INTRINSIC(MathMaxLongLong) |
| 274 | UNIMPLEMENTED_INTRINSIC(MathSqrt) |
| 275 | UNIMPLEMENTED_INTRINSIC(MathCeil) |
| 276 | UNIMPLEMENTED_INTRINSIC(MathFloor) |
| 277 | UNIMPLEMENTED_INTRINSIC(MathRint) |
| 278 | UNIMPLEMENTED_INTRINSIC(MathRoundDouble) |
| 279 | UNIMPLEMENTED_INTRINSIC(MathRoundFloat) |
| 280 | UNIMPLEMENTED_INTRINSIC(MemoryPeekByte) |
| 281 | UNIMPLEMENTED_INTRINSIC(MemoryPeekIntNative) |
| 282 | UNIMPLEMENTED_INTRINSIC(MemoryPeekLongNative) |
| 283 | UNIMPLEMENTED_INTRINSIC(MemoryPeekShortNative) |
| 284 | UNIMPLEMENTED_INTRINSIC(MemoryPokeByte) |
| 285 | UNIMPLEMENTED_INTRINSIC(MemoryPokeIntNative) |
| 286 | UNIMPLEMENTED_INTRINSIC(MemoryPokeLongNative) |
| 287 | UNIMPLEMENTED_INTRINSIC(MemoryPokeShortNative) |
| 288 | UNIMPLEMENTED_INTRINSIC(ThreadCurrentThread) |
| 289 | UNIMPLEMENTED_INTRINSIC(UnsafeGet) |
| 290 | UNIMPLEMENTED_INTRINSIC(UnsafeGetVolatile) |
| 291 | UNIMPLEMENTED_INTRINSIC(UnsafeGetLong) |
| 292 | UNIMPLEMENTED_INTRINSIC(UnsafeGetLongVolatile) |
| 293 | UNIMPLEMENTED_INTRINSIC(UnsafeGetObject) |
| 294 | UNIMPLEMENTED_INTRINSIC(UnsafeGetObjectVolatile) |
| 295 | UNIMPLEMENTED_INTRINSIC(UnsafePut) |
| 296 | UNIMPLEMENTED_INTRINSIC(UnsafePutOrdered) |
| 297 | UNIMPLEMENTED_INTRINSIC(UnsafePutVolatile) |
| 298 | UNIMPLEMENTED_INTRINSIC(UnsafePutObject) |
| 299 | UNIMPLEMENTED_INTRINSIC(UnsafePutObjectOrdered) |
| 300 | UNIMPLEMENTED_INTRINSIC(UnsafePutObjectVolatile) |
| 301 | UNIMPLEMENTED_INTRINSIC(UnsafePutLong) |
| 302 | UNIMPLEMENTED_INTRINSIC(UnsafePutLongOrdered) |
| 303 | UNIMPLEMENTED_INTRINSIC(UnsafePutLongVolatile) |
| 304 | UNIMPLEMENTED_INTRINSIC(UnsafeCASInt) |
| 305 | UNIMPLEMENTED_INTRINSIC(UnsafeCASLong) |
| 306 | UNIMPLEMENTED_INTRINSIC(UnsafeCASObject) |
| 307 | UNIMPLEMENTED_INTRINSIC(StringCharAt) |
| 308 | UNIMPLEMENTED_INTRINSIC(StringCompareTo) |
| 309 | UNIMPLEMENTED_INTRINSIC(StringEquals) |
| 310 | UNIMPLEMENTED_INTRINSIC(StringIndexOf) |
| 311 | UNIMPLEMENTED_INTRINSIC(StringIndexOfAfter) |
| 312 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromBytes) |
| 313 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromChars) |
| 314 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromString) |
| 315 | UNIMPLEMENTED_INTRINSIC(LongRotateLeft) |
| 316 | UNIMPLEMENTED_INTRINSIC(LongRotateRight) |
| 317 | UNIMPLEMENTED_INTRINSIC(LongNumberOfTrailingZeros) |
| 318 | UNIMPLEMENTED_INTRINSIC(IntegerRotateLeft) |
| 319 | UNIMPLEMENTED_INTRINSIC(IntegerRotateRight) |
| 320 | UNIMPLEMENTED_INTRINSIC(IntegerNumberOfTrailingZeros) |
| 321 | |
| 322 | UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent) |
| 323 | UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck) |
| 324 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar) |
| 325 | |
| 326 | #undef UNIMPLEMENTED_INTRINSIC |
| 327 | |
| 328 | #undef __ |
| 329 | |
| 330 | } // namespace mips64 |
| 331 | } // namespace art |