| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const intptr_t kNumTemps = 0; | 266 const intptr_t kNumTemps = 0; |
| 267 LocationSummary* locs = | 267 LocationSummary* locs = |
| 268 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); | 268 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); |
| 269 locs->set_in(0, Location::RegisterLocation(ECX)); | 269 locs->set_in(0, Location::RegisterLocation(ECX)); |
| 270 locs->set_in(1, Location::RegisterLocation(EDX)); | 270 locs->set_in(1, Location::RegisterLocation(EDX)); |
| 271 locs->set_out(Location::RegisterLocation(EAX)); | 271 locs->set_out(Location::RegisterLocation(EAX)); |
| 272 return locs; | 272 return locs; |
| 273 } | 273 } |
| 274 | 274 |
| 275 | 275 |
| 276 // Optional integer arguments can often be null. Null is not collected |
| 277 // by IC data. TODO(srdjan): Shall we collect null classes in ICData as well? |
| 278 static void EmitSmiEqualityCompare(FlowGraphCompiler* compiler, |
| 279 EqualityCompareComp* comp) { |
| 280 Register left = comp->locs()->in(0).reg(); |
| 281 Register right = comp->locs()->in(1).reg(); |
| 282 Register temp = comp->locs()->temp(0).reg(); |
| 283 Label* deopt = compiler->AddDeoptStub(comp->deopt_id(), |
| 284 comp->token_pos(), |
| 285 comp->try_index(), |
| 286 kDeoptSmiCompareSmi, |
| 287 left, |
| 288 right); |
| 289 __ movl(temp, left); |
| 290 __ orl(temp, right); |
| 291 __ testl(temp, Immediate(kSmiTagMask)); |
| 292 __ j(NOT_ZERO, deopt); |
| 293 __ cmpl(left, right); |
| 294 Register result = comp->locs()->out().reg(); |
| 295 Label load_true, done; |
| 296 __ j(TokenKindToSmiCondition(comp->kind()), &load_true, Assembler::kNearJump); |
| 297 __ LoadObject(result, compiler->bool_false()); |
| 298 __ jmp(&done, Assembler::kNearJump); |
| 299 __ Bind(&load_true); |
| 300 __ LoadObject(result, compiler->bool_true()); |
| 301 __ Bind(&done); |
| 302 } |
| 303 |
| 304 |
| 305 // TODO(srdjan): Add support for mixed Smi/Double equality |
| 306 // (see LoadDoubleOrSmiToXmm). |
| 307 static void EmitDoubleEqualityCompare(FlowGraphCompiler* compiler, |
| 308 EqualityCompareComp* comp) { |
| 309 Register left = comp->locs()->in(0).reg(); |
| 310 Register right = comp->locs()->in(1).reg(); |
| 311 Register temp = comp->locs()->temp(0).reg(); |
| 312 Label* deopt = compiler->AddDeoptStub(comp->deopt_id(), |
| 313 comp->token_pos(), |
| 314 comp->try_index(), |
| 315 kDeoptDoubleCompareDouble, |
| 316 left, |
| 317 right); |
| 318 Label done, is_false, is_true; |
| 319 __ CompareClassId(left, kDouble, temp); |
| 320 __ j(NOT_EQUAL, deopt); |
| 321 __ CompareClassId(right, kDouble, temp); |
| 322 __ j(NOT_EQUAL, deopt); |
| 323 __ movsd(XMM0, FieldAddress(left, Double::value_offset())); |
| 324 __ movsd(XMM1, FieldAddress(right, Double::value_offset())); |
| 325 compiler->EmitDoubleCompareBool(TokenKindToSmiCondition(comp->kind()), |
| 326 XMM0, XMM1, |
| 327 comp->locs()->out().reg()); |
| 328 } |
| 329 |
| 330 |
| 276 static void EmitEqualityAsInstanceCall(FlowGraphCompiler* compiler, | 331 static void EmitEqualityAsInstanceCall(FlowGraphCompiler* compiler, |
| 277 EqualityCompareComp* comp) { | 332 EqualityCompareComp* comp) { |
| 278 compiler->AddCurrentDescriptor(PcDescriptors::kDeopt, | 333 compiler->AddCurrentDescriptor(PcDescriptors::kDeopt, |
| 279 comp->deopt_id(), | 334 comp->deopt_id(), |
| 280 comp->token_pos(), | 335 comp->token_pos(), |
| 281 comp->try_index()); | 336 comp->try_index()); |
| 282 const String& operator_name = String::ZoneHandle(Symbols::New("==")); | 337 const String& operator_name = String::ZoneHandle(Symbols::New("==")); |
| 283 const int kNumberOfArguments = 2; | 338 const int kNumberOfArguments = 2; |
| 284 const Array& kNoArgumentNames = Array::Handle(); | 339 const Array& kNoArgumentNames = Array::Handle(); |
| 285 const int kNumArgumentsChecked = 2; | 340 const int kNumArgumentsChecked = 2; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 __ jmp(&done); | 488 __ jmp(&done); |
| 434 __ Bind(&non_null_compare); // Receiver is not null. | 489 __ Bind(&non_null_compare); // Receiver is not null. |
| 435 __ pushl(left); | 490 __ pushl(left); |
| 436 __ pushl(right); | 491 __ pushl(right); |
| 437 EmitEqualityAsPolymorphicCall(compiler, ic_data, locs, branch, kind, | 492 EmitEqualityAsPolymorphicCall(compiler, ic_data, locs, branch, kind, |
| 438 deopt_id, token_pos, try_index); | 493 deopt_id, token_pos, try_index); |
| 439 __ Bind(&done); | 494 __ Bind(&done); |
| 440 } | 495 } |
| 441 | 496 |
| 442 | 497 |
| 498 void EqualityCompareComp::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 499 if (receiver_class_id() == kSmi) { |
| 500 EmitSmiEqualityCompare(compiler, this); |
| 501 return; |
| 502 } |
| 503 if (receiver_class_id() == kDouble) { |
| 504 EmitDoubleEqualityCompare(compiler, this); |
| 505 return; |
| 506 } |
| 507 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) { |
| 508 EmitGenericEqualityCompare(compiler, *locs(), kind(), NULL, *ic_data(), |
| 509 deopt_id(), token_pos(), try_index()); |
| 510 } else { |
| 511 Register left = locs()->in(0).reg(); |
| 512 Register right = locs()->in(1).reg(); |
| 513 __ pushl(left); |
| 514 __ pushl(right); |
| 515 EmitEqualityAsInstanceCall(compiler, this); |
| 516 } |
| 517 } |
| 518 |
| 519 |
| 520 LocationSummary* RelationalOpComp::MakeLocationSummary() const { |
| 521 if ((operands_class_id() == kSmi) || (operands_class_id() == kDouble)) { |
| 522 const intptr_t kNumInputs = 2; |
| 523 const intptr_t kNumTemps = 1; |
| 524 LocationSummary* summary = |
| 525 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 526 summary->set_in(0, Location::RequiresRegister()); |
| 527 summary->set_in(1, Location::RequiresRegister()); |
| 528 summary->set_out(Location::RequiresRegister()); |
| 529 summary->set_temp(0, Location::RequiresRegister()); |
| 530 return summary; |
| 531 } |
| 532 ASSERT(operands_class_id() == kObject); |
| 533 return MakeCallSummary(); |
| 534 } |
| 535 |
| 536 |
| 443 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler, | 537 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler, |
| 444 const LocationSummary& locs, | 538 const LocationSummary& locs, |
| 445 Token::Kind kind, | 539 Token::Kind kind, |
| 446 BranchInstr* branch, | 540 BranchInstr* branch, |
| 447 intptr_t deopt_id, | 541 intptr_t deopt_id, |
| 448 intptr_t token_pos, | 542 intptr_t token_pos, |
| 449 intptr_t try_index) { | 543 intptr_t try_index) { |
| 450 Register left = locs.in(0).reg(); | 544 Register left = locs.in(0).reg(); |
| 451 Register right = locs.in(1).reg(); | 545 Register right = locs.in(1).reg(); |
| 452 Register temp = locs.temp(0).reg(); | 546 Register temp = locs.temp(0).reg(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 if (branch != NULL) { | 612 if (branch != NULL) { |
| 519 compiler->EmitDoubleCompareBranch( | 613 compiler->EmitDoubleCompareBranch( |
| 520 true_condition, XMM0, XMM1, branch); | 614 true_condition, XMM0, XMM1, branch); |
| 521 } else { | 615 } else { |
| 522 compiler->EmitDoubleCompareBool( | 616 compiler->EmitDoubleCompareBool( |
| 523 true_condition, XMM0, XMM1, locs.out().reg()); | 617 true_condition, XMM0, XMM1, locs.out().reg()); |
| 524 } | 618 } |
| 525 } | 619 } |
| 526 | 620 |
| 527 | 621 |
| 528 void EqualityCompareComp::EmitNativeCode(FlowGraphCompiler* compiler) { | |
| 529 if (receiver_class_id() == kSmi) { | |
| 530 EmitSmiComparisonOp(compiler, *locs(), kind(), NULL, // No branch. | |
| 531 deopt_id(), token_pos(), try_index()); | |
| 532 return; | |
| 533 } | |
| 534 if (receiver_class_id() == kDouble) { | |
| 535 EmitDoubleComparisonOp(compiler, *locs(), kind(), NULL, // No branch. | |
| 536 deopt_id(), token_pos(), try_index()); | |
| 537 return; | |
| 538 } | |
| 539 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) { | |
| 540 EmitGenericEqualityCompare(compiler, *locs(), kind(), NULL, *ic_data(), | |
| 541 deopt_id(), token_pos(), try_index()); | |
| 542 } else { | |
| 543 Register left = locs()->in(0).reg(); | |
| 544 Register right = locs()->in(1).reg(); | |
| 545 __ pushl(left); | |
| 546 __ pushl(right); | |
| 547 EmitEqualityAsInstanceCall(compiler, this); | |
| 548 } | |
| 549 } | |
| 550 | |
| 551 | |
| 552 LocationSummary* RelationalOpComp::MakeLocationSummary() const { | |
| 553 if ((operands_class_id() == kSmi) || (operands_class_id() == kDouble)) { | |
| 554 const intptr_t kNumInputs = 2; | |
| 555 const intptr_t kNumTemps = 1; | |
| 556 LocationSummary* summary = | |
| 557 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | |
| 558 summary->set_in(0, Location::RequiresRegister()); | |
| 559 summary->set_in(1, Location::RequiresRegister()); | |
| 560 summary->set_out(Location::RequiresRegister()); | |
| 561 summary->set_temp(0, Location::RequiresRegister()); | |
| 562 return summary; | |
| 563 } | |
| 564 ASSERT(operands_class_id() == kObject); | |
| 565 return MakeCallSummary(); | |
| 566 } | |
| 567 | |
| 568 | |
| 569 void RelationalOpComp::EmitNativeCode(FlowGraphCompiler* compiler) { | 622 void RelationalOpComp::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 570 if (operands_class_id() == kSmi) { | 623 if (operands_class_id() == kSmi) { |
| 571 EmitSmiComparisonOp(compiler, *locs(), kind(), NULL, | 624 EmitSmiComparisonOp(compiler, *locs(), kind(), NULL, |
| 572 deopt_id(), token_pos(), try_index()); | 625 deopt_id(), token_pos(), try_index()); |
| 573 return; | 626 return; |
| 574 } | 627 } |
| 575 if (operands_class_id() == kDouble) { | 628 if (operands_class_id() == kDouble) { |
| 576 EmitDoubleComparisonOp(compiler, *locs(), kind(), NULL, | 629 EmitDoubleComparisonOp(compiler, *locs(), kind(), NULL, |
| 577 deopt_id(), token_pos(), try_index()); | 630 deopt_id(), token_pos(), try_index()); |
| 578 return; | 631 return; |
| (...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2070 ASSERT(locs()->out().reg() == EAX); | 2123 ASSERT(locs()->out().reg() == EAX); |
| 2071 __ CompareObject(locs()->out().reg(), compiler->bool_true()); | 2124 __ CompareObject(locs()->out().reg(), compiler->bool_true()); |
| 2072 EmitBranchOnCondition(compiler, branch_condition); | 2125 EmitBranchOnCondition(compiler, branch_condition); |
| 2073 } | 2126 } |
| 2074 | 2127 |
| 2075 } // namespace dart | 2128 } // namespace dart |
| 2076 | 2129 |
| 2077 #undef __ | 2130 #undef __ |
| 2078 | 2131 |
| 2079 #endif // defined TARGET_ARCH_X64 | 2132 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |