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 | |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 254 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 255 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 256 | LocationSummary::kNoCall, |
| 257 | kIntrinsified); |
| 258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 259 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 260 | } |
| 261 | |
| 262 | static void MathAbsFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 263 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 264 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 265 | |
| 266 | if (is64bit) { |
| 267 | __ AbsD(out, in); |
| 268 | } else { |
| 269 | __ AbsS(out, in); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // double java.lang.Math.abs(double) |
| 274 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsDouble(HInvoke* invoke) { |
| 275 | CreateFPToFPLocations(arena_, invoke); |
| 276 | } |
| 277 | |
| 278 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsDouble(HInvoke* invoke) { |
| 279 | MathAbsFP(invoke->GetLocations(), true, GetAssembler()); |
| 280 | } |
| 281 | |
| 282 | // float java.lang.Math.abs(float) |
| 283 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsFloat(HInvoke* invoke) { |
| 284 | CreateFPToFPLocations(arena_, invoke); |
| 285 | } |
| 286 | |
| 287 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsFloat(HInvoke* invoke) { |
| 288 | MathAbsFP(invoke->GetLocations(), false, GetAssembler()); |
| 289 | } |
| 290 | |
| 291 | static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) { |
| 292 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 293 | LocationSummary::kNoCall, |
| 294 | kIntrinsified); |
| 295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 296 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 297 | } |
| 298 | |
| 299 | static void GenAbsInteger(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) { |
| 300 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 301 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 302 | |
| 303 | if (is64bit) { |
| 304 | __ Dsra32(AT, in, 31); |
| 305 | __ Xor(out, in, AT); |
| 306 | __ Dsubu(out, out, AT); |
| 307 | } else { |
| 308 | __ Sra(AT, in, 31); |
| 309 | __ Xor(out, in, AT); |
| 310 | __ Subu(out, out, AT); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // int java.lang.Math.abs(int) |
| 315 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsInt(HInvoke* invoke) { |
| 316 | CreateIntToInt(arena_, invoke); |
| 317 | } |
| 318 | |
| 319 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsInt(HInvoke* invoke) { |
| 320 | GenAbsInteger(invoke->GetLocations(), false, GetAssembler()); |
| 321 | } |
| 322 | |
| 323 | // long java.lang.Math.abs(long) |
| 324 | void IntrinsicLocationsBuilderMIPS64::VisitMathAbsLong(HInvoke* invoke) { |
| 325 | CreateIntToInt(arena_, invoke); |
| 326 | } |
| 327 | |
| 328 | void IntrinsicCodeGeneratorMIPS64::VisitMathAbsLong(HInvoke* invoke) { |
| 329 | GenAbsInteger(invoke->GetLocations(), true, GetAssembler()); |
| 330 | } |
| 331 | |
| 332 | static void GenMinMaxFP(LocationSummary* locations, |
| 333 | bool is_min, |
| 334 | bool is_double, |
| 335 | Mips64Assembler* assembler) { |
| 336 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 337 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 338 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 339 | |
| 340 | if (is_double) { |
| 341 | if (is_min) { |
| 342 | __ MinD(out, lhs, rhs); |
| 343 | } else { |
| 344 | __ MaxD(out, lhs, rhs); |
| 345 | } |
| 346 | } else { |
| 347 | if (is_min) { |
| 348 | __ MinS(out, lhs, rhs); |
| 349 | } else { |
| 350 | __ MaxS(out, lhs, rhs); |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 356 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 357 | LocationSummary::kNoCall, |
| 358 | kIntrinsified); |
| 359 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 360 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 361 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 362 | } |
| 363 | |
| 364 | // double java.lang.Math.min(double, double) |
| 365 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 366 | CreateFPFPToFPLocations(arena_, invoke); |
| 367 | } |
| 368 | |
| 369 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 370 | GenMinMaxFP(invoke->GetLocations(), true, true, GetAssembler()); |
| 371 | } |
| 372 | |
| 373 | // float java.lang.Math.min(float, float) |
| 374 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 375 | CreateFPFPToFPLocations(arena_, invoke); |
| 376 | } |
| 377 | |
| 378 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 379 | GenMinMaxFP(invoke->GetLocations(), true, false, GetAssembler()); |
| 380 | } |
| 381 | |
| 382 | // double java.lang.Math.max(double, double) |
| 383 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 384 | CreateFPFPToFPLocations(arena_, invoke); |
| 385 | } |
| 386 | |
| 387 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 388 | GenMinMaxFP(invoke->GetLocations(), false, true, GetAssembler()); |
| 389 | } |
| 390 | |
| 391 | // float java.lang.Math.max(float, float) |
| 392 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 393 | CreateFPFPToFPLocations(arena_, invoke); |
| 394 | } |
| 395 | |
| 396 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 397 | GenMinMaxFP(invoke->GetLocations(), false, false, GetAssembler()); |
| 398 | } |
| 399 | |
| 400 | static void GenMinMax(LocationSummary* locations, |
| 401 | bool is_min, |
| 402 | Mips64Assembler* assembler) { |
| 403 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 404 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 405 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 406 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 407 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 408 | // conditional move instruction which only changes the target |
| 409 | // (output) register if the condition is true (MIPS prior to r6 had |
| 410 | // MOVF, MOVT, and MOVZ). The SELEQZ and SELNEZ instructions always |
| 411 | // change the target (output) register. If the condition is true the |
| 412 | // output register gets the contents of the "rs" register; otherwise, |
| 413 | // the output register is set to zero. One consequence of this is |
| 414 | // that to implement something like "rd = c==0 ? rs : rt" MIPS64r6 |
| 415 | // needs to use a pair of SELEQZ/SELNEZ instructions. After |
| 416 | // executing this pair of instructions one of the output registers |
| 417 | // from the pair will necessarily contain zero. Then the code ORs the |
| 418 | // output registers from the SELEQZ/SELNEZ instructions to get the |
| 419 | // final result. |
| 420 | // |
| 421 | // The initial test to see if the output register is same as the |
| 422 | // first input register is needed to make sure that value in the |
| 423 | // first input register isn't clobbered before we've finished |
| 424 | // computing the output value. The logic in the corresponding else |
| 425 | // clause performs the same task but makes sure the second input |
| 426 | // register isn't clobbered in the event that it's the same register |
| 427 | // as the output register; the else clause also handles the case |
| 428 | // where the output register is distinct from both the first, and the |
| 429 | // second input registers. |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 430 | if (out == lhs) { |
| 431 | __ Slt(AT, rhs, lhs); |
| 432 | if (is_min) { |
| 433 | __ Seleqz(out, lhs, AT); |
| 434 | __ Selnez(AT, rhs, AT); |
| 435 | } else { |
| 436 | __ Selnez(out, lhs, AT); |
| 437 | __ Seleqz(AT, rhs, AT); |
| 438 | } |
| 439 | } else { |
| 440 | __ Slt(AT, lhs, rhs); |
| 441 | if (is_min) { |
| 442 | __ Seleqz(out, rhs, AT); |
| 443 | __ Selnez(AT, lhs, AT); |
| 444 | } else { |
| 445 | __ Selnez(out, rhs, AT); |
| 446 | __ Seleqz(AT, lhs, AT); |
| 447 | } |
| 448 | } |
| 449 | __ Or(out, out, AT); |
| 450 | } |
| 451 | |
| 452 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 453 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 454 | LocationSummary::kNoCall, |
| 455 | kIntrinsified); |
| 456 | locations->SetInAt(0, Location::RequiresRegister()); |
| 457 | locations->SetInAt(1, Location::RequiresRegister()); |
| 458 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 459 | } |
| 460 | |
| 461 | // int java.lang.Math.min(int, int) |
| 462 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinIntInt(HInvoke* invoke) { |
| 463 | CreateIntIntToIntLocations(arena_, invoke); |
| 464 | } |
| 465 | |
| 466 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinIntInt(HInvoke* invoke) { |
| 467 | GenMinMax(invoke->GetLocations(), true, GetAssembler()); |
| 468 | } |
| 469 | |
| 470 | // long java.lang.Math.min(long, long) |
| 471 | void IntrinsicLocationsBuilderMIPS64::VisitMathMinLongLong(HInvoke* invoke) { |
| 472 | CreateIntIntToIntLocations(arena_, invoke); |
| 473 | } |
| 474 | |
| 475 | void IntrinsicCodeGeneratorMIPS64::VisitMathMinLongLong(HInvoke* invoke) { |
| 476 | GenMinMax(invoke->GetLocations(), true, GetAssembler()); |
| 477 | } |
| 478 | |
| 479 | // int java.lang.Math.max(int, int) |
| 480 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 481 | CreateIntIntToIntLocations(arena_, invoke); |
| 482 | } |
| 483 | |
| 484 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 485 | GenMinMax(invoke->GetLocations(), false, GetAssembler()); |
| 486 | } |
| 487 | |
| 488 | // long java.lang.Math.max(long, long) |
| 489 | void IntrinsicLocationsBuilderMIPS64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 490 | CreateIntIntToIntLocations(arena_, invoke); |
| 491 | } |
| 492 | |
| 493 | void IntrinsicCodeGeneratorMIPS64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 494 | GenMinMax(invoke->GetLocations(), false, GetAssembler()); |
| 495 | } |
| 496 | |
| 497 | // double java.lang.Math.sqrt(double) |
| 498 | void IntrinsicLocationsBuilderMIPS64::VisitMathSqrt(HInvoke* invoke) { |
| 499 | CreateFPToFPLocations(arena_, invoke); |
| 500 | } |
| 501 | |
| 502 | void IntrinsicCodeGeneratorMIPS64::VisitMathSqrt(HInvoke* invoke) { |
| 503 | LocationSummary* locations = invoke->GetLocations(); |
| 504 | Mips64Assembler* assembler = GetAssembler(); |
| 505 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 506 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 507 | |
| 508 | __ SqrtD(out, in); |
| 509 | } |
| 510 | |
| 511 | static void CreateFPToFP(ArenaAllocator* arena, HInvoke* invoke) { |
| 512 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 513 | LocationSummary::kNoCall, |
| 514 | kIntrinsified); |
| 515 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 516 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 517 | } |
| 518 | |
| 519 | // double java.lang.Math.rint(double) |
| 520 | void IntrinsicLocationsBuilderMIPS64::VisitMathRint(HInvoke* invoke) { |
| 521 | CreateFPToFP(arena_, invoke); |
| 522 | } |
| 523 | |
| 524 | void IntrinsicCodeGeneratorMIPS64::VisitMathRint(HInvoke* invoke) { |
| 525 | LocationSummary* locations = invoke->GetLocations(); |
| 526 | Mips64Assembler* assembler = GetAssembler(); |
| 527 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 528 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 529 | |
| 530 | __ RintD(out, in); |
| 531 | } |
| 532 | |
| 533 | // double java.lang.Math.floor(double) |
| 534 | void IntrinsicLocationsBuilderMIPS64::VisitMathFloor(HInvoke* invoke) { |
| 535 | CreateFPToFP(arena_, invoke); |
| 536 | } |
| 537 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 538 | const constexpr uint16_t kFPLeaveUnchanged = kPositiveZero | |
| 539 | kPositiveInfinity | |
| 540 | kNegativeZero | |
| 541 | kNegativeInfinity | |
| 542 | kQuietNaN | |
| 543 | kSignalingNaN; |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 544 | |
| 545 | void IntrinsicCodeGeneratorMIPS64::VisitMathFloor(HInvoke* invoke) { |
| 546 | LocationSummary* locations = invoke->GetLocations(); |
| 547 | Mips64Assembler* assembler = GetAssembler(); |
| 548 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 549 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 550 | |
| 551 | Label done; |
| 552 | |
| 553 | // double floor(double in) { |
| 554 | // if in.isNaN || in.isInfinite || in.isZero { |
| 555 | // return in; |
| 556 | // } |
| 557 | __ ClassD(out, in); |
| 558 | __ Dmfc1(AT, out); |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 559 | __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 560 | __ MovD(out, in); |
| 561 | __ Bnezc(AT, &done); |
| 562 | |
| 563 | // Long outLong = floor(in); |
| 564 | // if outLong == Long.MAX_VALUE { |
| 565 | // // floor() has almost certainly returned a value which |
| 566 | // // can't be successfully represented as a signed 64-bit |
| 567 | // // number. Java expects that the input value will be |
| 568 | // // returned in these cases. |
| 569 | // // There is also a small probability that floor(in) |
| 570 | // // correctly truncates the input value to Long.MAX_VALUE. In |
| 571 | // // that case, this exception handling code still does the |
| 572 | // // correct thing. |
| 573 | // return in; |
| 574 | // } |
| 575 | __ FloorLD(out, in); |
| 576 | __ Dmfc1(AT, out); |
| 577 | __ MovD(out, in); |
| 578 | __ LoadConst64(TMP, kPrimLongMax); |
| 579 | __ Beqc(AT, TMP, &done); |
| 580 | |
| 581 | // double out = outLong; |
| 582 | // return out; |
| 583 | __ Dmtc1(AT, out); |
| 584 | __ Cvtdl(out, out); |
| 585 | __ Bind(&done); |
| 586 | // } |
| 587 | } |
| 588 | |
| 589 | // double java.lang.Math.ceil(double) |
| 590 | void IntrinsicLocationsBuilderMIPS64::VisitMathCeil(HInvoke* invoke) { |
| 591 | CreateFPToFP(arena_, invoke); |
| 592 | } |
| 593 | |
| 594 | void IntrinsicCodeGeneratorMIPS64::VisitMathCeil(HInvoke* invoke) { |
| 595 | LocationSummary* locations = invoke->GetLocations(); |
| 596 | Mips64Assembler* assembler = GetAssembler(); |
| 597 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 598 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 599 | |
| 600 | Label done; |
| 601 | |
| 602 | // double ceil(double in) { |
| 603 | // if in.isNaN || in.isInfinite || in.isZero { |
| 604 | // return in; |
| 605 | // } |
| 606 | __ ClassD(out, in); |
| 607 | __ Dmfc1(AT, out); |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 608 | __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 609 | __ MovD(out, in); |
| 610 | __ Bnezc(AT, &done); |
| 611 | |
| 612 | // Long outLong = ceil(in); |
| 613 | // if outLong == Long.MAX_VALUE { |
| 614 | // // ceil() has almost certainly returned a value which |
| 615 | // // can't be successfully represented as a signed 64-bit |
| 616 | // // number. Java expects that the input value will be |
| 617 | // // returned in these cases. |
| 618 | // // There is also a small probability that ceil(in) |
| 619 | // // correctly rounds up the input value to Long.MAX_VALUE. In |
| 620 | // // that case, this exception handling code still does the |
| 621 | // // correct thing. |
| 622 | // return in; |
| 623 | // } |
| 624 | __ CeilLD(out, in); |
| 625 | __ Dmfc1(AT, out); |
| 626 | __ MovD(out, in); |
| 627 | __ LoadConst64(TMP, kPrimLongMax); |
| 628 | __ Beqc(AT, TMP, &done); |
| 629 | |
| 630 | // double out = outLong; |
| 631 | // return out; |
| 632 | __ Dmtc1(AT, out); |
| 633 | __ Cvtdl(out, out); |
| 634 | __ Bind(&done); |
| 635 | // } |
| 636 | } |
| 637 | |
Chris Larsen | 70fb1f4 | 2015-09-04 10:15:27 -0700 | [diff] [blame] | 638 | // byte libcore.io.Memory.peekByte(long address) |
| 639 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 640 | CreateIntToIntLocations(arena_, invoke); |
| 641 | } |
| 642 | |
| 643 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 644 | Mips64Assembler* assembler = GetAssembler(); |
| 645 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 646 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 647 | |
| 648 | __ Lb(out, adr, 0); |
| 649 | } |
| 650 | |
| 651 | // short libcore.io.Memory.peekShort(long address) |
| 652 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 653 | CreateIntToIntLocations(arena_, invoke); |
| 654 | } |
| 655 | |
| 656 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 657 | Mips64Assembler* assembler = GetAssembler(); |
| 658 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 659 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 660 | |
| 661 | __ Lh(out, adr, 0); |
| 662 | } |
| 663 | |
| 664 | // int libcore.io.Memory.peekInt(long address) |
| 665 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 666 | CreateIntToIntLocations(arena_, invoke); |
| 667 | } |
| 668 | |
| 669 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 670 | Mips64Assembler* assembler = GetAssembler(); |
| 671 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 672 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 673 | |
| 674 | __ Lw(out, adr, 0); |
| 675 | } |
| 676 | |
| 677 | // long libcore.io.Memory.peekLong(long address) |
| 678 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 679 | CreateIntToIntLocations(arena_, invoke); |
| 680 | } |
| 681 | |
| 682 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 683 | Mips64Assembler* assembler = GetAssembler(); |
| 684 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 685 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 686 | |
| 687 | __ Ld(out, adr, 0); |
| 688 | } |
| 689 | |
| 690 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 691 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 692 | LocationSummary::kNoCall, |
| 693 | kIntrinsified); |
| 694 | locations->SetInAt(0, Location::RequiresRegister()); |
| 695 | locations->SetInAt(1, Location::RequiresRegister()); |
| 696 | } |
| 697 | |
| 698 | // void libcore.io.Memory.pokeByte(long address, byte value) |
| 699 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 700 | CreateIntIntToVoidLocations(arena_, invoke); |
| 701 | } |
| 702 | |
| 703 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 704 | Mips64Assembler* assembler = GetAssembler(); |
| 705 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 706 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 707 | |
| 708 | __ Sb(val, adr, 0); |
| 709 | } |
| 710 | |
| 711 | // void libcore.io.Memory.pokeShort(long address, short value) |
| 712 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 713 | CreateIntIntToVoidLocations(arena_, invoke); |
| 714 | } |
| 715 | |
| 716 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 717 | Mips64Assembler* assembler = GetAssembler(); |
| 718 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 719 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 720 | |
| 721 | __ Sh(val, adr, 0); |
| 722 | } |
| 723 | |
| 724 | // void libcore.io.Memory.pokeInt(long address, int value) |
| 725 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 726 | CreateIntIntToVoidLocations(arena_, invoke); |
| 727 | } |
| 728 | |
| 729 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 730 | Mips64Assembler* assembler = GetAssembler(); |
| 731 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 732 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 733 | |
| 734 | __ Sw(val, adr, 00); |
| 735 | } |
| 736 | |
| 737 | // void libcore.io.Memory.pokeLong(long address, long value) |
| 738 | void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 739 | CreateIntIntToVoidLocations(arena_, invoke); |
| 740 | } |
| 741 | |
| 742 | void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 743 | Mips64Assembler* assembler = GetAssembler(); |
| 744 | GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>(); |
| 745 | GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>(); |
| 746 | |
| 747 | __ Sd(val, adr, 0); |
| 748 | } |
| 749 | |
Chris Larsen | 49e5539 | 2015-09-04 16:04:03 -0700 | [diff] [blame] | 750 | // Thread java.lang.Thread.currentThread() |
| 751 | void IntrinsicLocationsBuilderMIPS64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 752 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 753 | LocationSummary::kNoCall, |
| 754 | kIntrinsified); |
| 755 | locations->SetOut(Location::RequiresRegister()); |
| 756 | } |
| 757 | |
| 758 | void IntrinsicCodeGeneratorMIPS64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 759 | Mips64Assembler* assembler = GetAssembler(); |
| 760 | GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>(); |
| 761 | |
| 762 | __ LoadFromOffset(kLoadUnsignedWord, |
| 763 | out, |
| 764 | TR, |
| 765 | Thread::PeerOffset<kMips64PointerSize>().Int32Value()); |
| 766 | } |
| 767 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 768 | // Unimplemented intrinsics. |
| 769 | |
| 770 | #define UNIMPLEMENTED_INTRINSIC(Name) \ |
| 771 | void IntrinsicLocationsBuilderMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 772 | } \ |
| 773 | void IntrinsicCodeGeneratorMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 774 | } |
| 775 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 776 | UNIMPLEMENTED_INTRINSIC(MathRoundDouble) |
| 777 | UNIMPLEMENTED_INTRINSIC(MathRoundFloat) |
Chris Larsen | 0b7ac98 | 2015-09-04 12:54:28 -0700 | [diff] [blame] | 778 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 779 | UNIMPLEMENTED_INTRINSIC(UnsafeGet) |
| 780 | UNIMPLEMENTED_INTRINSIC(UnsafeGetVolatile) |
| 781 | UNIMPLEMENTED_INTRINSIC(UnsafeGetLong) |
| 782 | UNIMPLEMENTED_INTRINSIC(UnsafeGetLongVolatile) |
| 783 | UNIMPLEMENTED_INTRINSIC(UnsafeGetObject) |
| 784 | UNIMPLEMENTED_INTRINSIC(UnsafeGetObjectVolatile) |
| 785 | UNIMPLEMENTED_INTRINSIC(UnsafePut) |
| 786 | UNIMPLEMENTED_INTRINSIC(UnsafePutOrdered) |
| 787 | UNIMPLEMENTED_INTRINSIC(UnsafePutVolatile) |
| 788 | UNIMPLEMENTED_INTRINSIC(UnsafePutObject) |
| 789 | UNIMPLEMENTED_INTRINSIC(UnsafePutObjectOrdered) |
| 790 | UNIMPLEMENTED_INTRINSIC(UnsafePutObjectVolatile) |
| 791 | UNIMPLEMENTED_INTRINSIC(UnsafePutLong) |
| 792 | UNIMPLEMENTED_INTRINSIC(UnsafePutLongOrdered) |
| 793 | UNIMPLEMENTED_INTRINSIC(UnsafePutLongVolatile) |
| 794 | UNIMPLEMENTED_INTRINSIC(UnsafeCASInt) |
| 795 | UNIMPLEMENTED_INTRINSIC(UnsafeCASLong) |
| 796 | UNIMPLEMENTED_INTRINSIC(UnsafeCASObject) |
| 797 | UNIMPLEMENTED_INTRINSIC(StringCharAt) |
| 798 | UNIMPLEMENTED_INTRINSIC(StringCompareTo) |
| 799 | UNIMPLEMENTED_INTRINSIC(StringEquals) |
| 800 | UNIMPLEMENTED_INTRINSIC(StringIndexOf) |
| 801 | UNIMPLEMENTED_INTRINSIC(StringIndexOfAfter) |
| 802 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromBytes) |
| 803 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromChars) |
| 804 | UNIMPLEMENTED_INTRINSIC(StringNewStringFromString) |
| 805 | UNIMPLEMENTED_INTRINSIC(LongRotateLeft) |
| 806 | UNIMPLEMENTED_INTRINSIC(LongRotateRight) |
| 807 | UNIMPLEMENTED_INTRINSIC(LongNumberOfTrailingZeros) |
| 808 | UNIMPLEMENTED_INTRINSIC(IntegerRotateLeft) |
| 809 | UNIMPLEMENTED_INTRINSIC(IntegerRotateRight) |
| 810 | UNIMPLEMENTED_INTRINSIC(IntegerNumberOfTrailingZeros) |
| 811 | |
| 812 | UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent) |
| 813 | UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck) |
| 814 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar) |
| 815 | |
| 816 | #undef UNIMPLEMENTED_INTRINSIC |
| 817 | |
| 818 | #undef __ |
| 819 | |
| 820 | } // namespace mips64 |
| 821 | } // namespace art |