Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Side by Side Diff: runtime/vm/intermediate_language_ia32.cc

Issue 10918097: Allow smi comparisons to have constant operands. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 HasICData() && ic_data()->AllTargetsHaveSameOwner(kInstanceCid); 264 HasICData() && ic_data()->AllTargetsHaveSameOwner(kInstanceCid);
265 if (receiver_class_id() == kDoubleCid) { 265 if (receiver_class_id() == kDoubleCid) {
266 const intptr_t kNumTemps = 0; 266 const intptr_t kNumTemps = 0;
267 LocationSummary* locs = 267 LocationSummary* locs =
268 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 268 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
269 locs->set_in(0, Location::RequiresXmmRegister()); 269 locs->set_in(0, Location::RequiresXmmRegister());
270 locs->set_in(1, Location::RequiresXmmRegister()); 270 locs->set_in(1, Location::RequiresXmmRegister());
271 locs->set_out(Location::RequiresRegister()); 271 locs->set_out(Location::RequiresRegister());
272 return locs; 272 return locs;
273 } 273 }
274 if ((receiver_class_id() == kSmiCid) || is_checked_strict_equal) { 274 if (receiver_class_id() == kSmiCid) {
275 const intptr_t kNumTemps = 0;
276 LocationSummary* locs =
277 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
278 locs->set_in(0, Location::RegisterOrConstant(left()));
279 locs->set_in(1, Location::RegisterOrConstant(right()));
280 locs->set_out(Location::RequiresRegister());
281 return locs;
282 }
283 if (is_checked_strict_equal) {
275 const intptr_t kNumTemps = 1; 284 const intptr_t kNumTemps = 1;
276 LocationSummary* locs = 285 LocationSummary* locs =
277 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 286 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
278 locs->set_in(0, Location::RequiresRegister()); 287 locs->set_in(0, Location::RequiresRegister());
279 locs->set_in(1, Location::RequiresRegister()); 288 locs->set_in(1, Location::RequiresRegister());
280 locs->set_temp(0, Location::RequiresRegister()); 289 locs->set_temp(0, Location::RequiresRegister());
281 locs->set_out(Location::RequiresRegister()); 290 locs->set_out(Location::RequiresRegister());
282 return locs; 291 return locs;
283 } 292 }
284 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) { 293 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 __ jmp(&done); 554 __ jmp(&done);
546 __ Bind(&non_null_compare); // Receiver is not null. 555 __ Bind(&non_null_compare); // Receiver is not null.
547 __ pushl(left); 556 __ pushl(left);
548 __ pushl(right); 557 __ pushl(right);
549 EmitEqualityAsPolymorphicCall(compiler, ic_data, locs, branch, kind, 558 EmitEqualityAsPolymorphicCall(compiler, ic_data, locs, branch, kind,
550 deopt_id, token_pos); 559 deopt_id, token_pos);
551 __ Bind(&done); 560 __ Bind(&done);
552 } 561 }
553 562
554 563
564 Immediate SmiConstantToImmediate(const Object& constant) {
565 ASSERT(constant.IsSmi());
566 return Immediate(reinterpret_cast<int32_t>(constant.raw()));
567 }
568
569
555 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler, 570 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler,
556 const LocationSummary& locs, 571 const LocationSummary& locs,
557 Token::Kind kind, 572 Token::Kind kind,
558 BranchInstr* branch) { 573 BranchInstr* branch) {
559 Register left = locs.in(0).reg(); 574 Location left = locs.in(0);
560 Register right = locs.in(1).reg(); 575 Location right = locs.in(1);
561 576
562 Condition true_condition = TokenKindToSmiCondition(kind); 577 Condition true_condition = TokenKindToSmiCondition(kind);
563 __ cmpl(left, right); 578
579 if (left.IsConstant() && right.IsConstant()) {
580 // TODO(vegorov): should be eliminated earlier by constant propagation.
581 const bool result = FlowGraphCompiler::EvaluateCondition(
582 true_condition,
583 Smi::Cast(left.constant()).Value(),
584 Smi::Cast(right.constant()).Value());
585
586 if (branch != NULL) {
587 branch->EmitBranchOnValue(compiler, result);
588 } else {
589 __ LoadObject(locs.out().reg(), result ? compiler->bool_true()
590 : compiler->bool_false());
591 }
592
Florian Schneider 2012/09/06 13:17:30 Remove new line here?
Vyacheslav Egorov (Google) 2012/09/06 13:24:44 It makes code easier to read.
593 return;
594 }
595
596 if (left.IsConstant()) {
597 __ cmpl(right.reg(), SmiConstantToImmediate(left.constant()));
srdjan 2012/09/06 13:32:55 I wonder if we should add assembly instruction tha
598 true_condition = FlowGraphCompiler::FlipCondition(true_condition);
599 } else if (right.IsConstant()) {
600 __ cmpl(left.reg(), SmiConstantToImmediate(right.constant()));
601 } else {
602 __ cmpl(left.reg(), right.reg());
603 }
564 604
565 if (branch != NULL) { 605 if (branch != NULL) {
566 branch->EmitBranchOnCondition(compiler, true_condition); 606 branch->EmitBranchOnCondition(compiler, true_condition);
567 } else { 607 } else {
568 Register result = locs.out().reg(); 608 Register result = locs.out().reg();
569 Label done, is_true; 609 Label done, is_true;
570 __ j(true_condition, &is_true); 610 __ j(true_condition, &is_true);
571 __ LoadObject(result, compiler->bool_false()); 611 __ LoadObject(result, compiler->bool_false());
572 __ jmp(&done); 612 __ jmp(&done);
573 __ Bind(&is_true); 613 __ Bind(&is_true);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 Token::kEQ, // kNE reverse occurs at branch. 717 Token::kEQ, // kNE reverse occurs at branch.
678 locs()); 718 locs());
679 Condition branch_condition = (kind() == Token::kNE) ? NOT_EQUAL : EQUAL; 719 Condition branch_condition = (kind() == Token::kNE) ? NOT_EQUAL : EQUAL;
680 __ CompareObject(EAX, compiler->bool_true()); 720 __ CompareObject(EAX, compiler->bool_true());
681 branch->EmitBranchOnCondition(compiler, branch_condition); 721 branch->EmitBranchOnCondition(compiler, branch_condition);
682 } 722 }
683 723
684 724
685 LocationSummary* RelationalOpInstr::MakeLocationSummary() const { 725 LocationSummary* RelationalOpInstr::MakeLocationSummary() const {
686 const intptr_t kNumInputs = 2; 726 const intptr_t kNumInputs = 2;
727 const intptr_t kNumTemps = 0;
687 if (operands_class_id() == kDoubleCid) { 728 if (operands_class_id() == kDoubleCid) {
688 const intptr_t kNumTemps = 0;
689 LocationSummary* summary = 729 LocationSummary* summary =
690 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 730 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
691 summary->set_in(0, Location::RequiresXmmRegister()); 731 summary->set_in(0, Location::RequiresXmmRegister());
692 summary->set_in(1, Location::RequiresXmmRegister()); 732 summary->set_in(1, Location::RequiresXmmRegister());
693 summary->set_out(Location::RequiresRegister()); 733 summary->set_out(Location::RequiresRegister());
694 return summary; 734 return summary;
695 } else if (operands_class_id() == kSmiCid) { 735 } else if (operands_class_id() == kSmiCid) {
696 const intptr_t kNumTemps = 1;
697 LocationSummary* summary = 736 LocationSummary* summary =
698 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 737 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
699 summary->set_in(0, Location::RequiresRegister()); 738 summary->set_in(0, Location::RegisterOrConstant(left()));
700 summary->set_in(1, Location::RequiresRegister()); 739 summary->set_in(1, Location::RegisterOrConstant(right()));
701 summary->set_out(Location::RequiresRegister()); 740 summary->set_out(Location::RequiresRegister());
702 summary->set_temp(0, Location::RequiresRegister());
703 return summary; 741 return summary;
704 } 742 }
705 const intptr_t kNumTemps = 0;
706 LocationSummary* locs = 743 LocationSummary* locs =
707 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); 744 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall);
708 // Pick arbitrary fixed input registers because this is a call. 745 // Pick arbitrary fixed input registers because this is a call.
709 locs->set_in(0, Location::RegisterLocation(EAX)); 746 locs->set_in(0, Location::RegisterLocation(EAX));
710 locs->set_in(1, Location::RegisterLocation(ECX)); 747 locs->set_in(1, Location::RegisterLocation(ECX));
711 locs->set_out(Location::RegisterLocation(EAX)); 748 locs->set_out(Location::RegisterLocation(EAX));
712 return locs; 749 return locs;
713 } 750 }
714 751
715 752
(...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 __ j(ABOVE_EQUAL, deopt); 2283 __ j(ABOVE_EQUAL, deopt);
2247 } 2284 }
2248 } 2285 }
2249 2286
2250 2287
2251 } // namespace dart 2288 } // namespace dart
2252 2289
2253 #undef __ 2290 #undef __
2254 2291
2255 #endif // defined TARGET_ARCH_X64 2292 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698