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

Unified Diff: runtime/vm/intermediate_language_ia32.cc

Issue 10592028: Improve inlining of bit_and operation for Mint and Smi in new compilers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/intermediate_language_ia32.cc
===================================================================
--- runtime/vm/intermediate_language_ia32.cc (revision 8949)
+++ runtime/vm/intermediate_language_ia32.cc (working copy)
@@ -551,7 +551,6 @@
}
-
void RelationalOpComp::EmitNativeCode(FlowGraphCompiler* compiler) {
if (operands_class_id() == kSmi) {
EmitSmiRelationalOp(compiler, this);
@@ -1486,36 +1485,96 @@
}
+static RawFunction* GetTargetForReceiverClassId(const ICData& ic_data,
+ intptr_t receiver_class_id) {
+ Function& target = Function::Handle();
+ for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) {
+ GrowableArray<intptr_t> class_ids;
+ ic_data.GetCheckAt(i, &class_ids, &target);
+ if (class_ids[0] == receiver_class_id) {
+ return target.raw();
+ }
+ }
+ UNREACHABLE();
+ return Function::null();
+}
+
+
static void EmitMintBinaryOp(FlowGraphCompiler* compiler, BinaryOpComp* comp) {
// TODO(regis): For now, we only support Token::kBIT_AND for a Mint or Smi
- // receiver and a Smi argument.
+ // receiver and a Mint or Smi argument. We fall back to the run time call if
+ // both receiver and argument are Mint or if one of them is Mint and the other
+ // is a negative Smi.
Register left = comp->locs()->in(0).reg();
Register right = comp->locs()->in(1).reg();
Register result = comp->locs()->out().reg();
Register temp = comp->locs()->temp(0).reg();
ASSERT(left == result);
+ ASSERT(comp->op_kind() == Token::kBIT_AND);
Label* deopt = compiler->AddDeoptStub(comp->instance_call()->cid(),
comp->instance_call()->token_index(),
comp->instance_call()->try_index(),
kDeoptMintBinaryOp,
temp,
right);
- __ testl(right, Immediate(kSmiTagMask)); // Argument must be Smi.
- __ j(NOT_ZERO, deopt);
- __ testl(left, Immediate(kSmiTagMask)); // Receiver can be Smi.
- Label two_smi;
- __ j(ZERO, &two_smi);
- __ CompareClassId(left, kMint, temp); // Receiver must be Mint.
- __ j(NOT_EQUAL, deopt);
+ Label mint_static_call, smi_static_call, non_smi, smi_smi, done;
+ __ testl(left, Immediate(kSmiTagMask)); // Is receiver Smi?
+ __ j(NOT_ZERO, &non_smi);
+ __ testl(right, Immediate(kSmiTagMask)); // Is argument Smi?
+ __ j(ZERO, &smi_smi);
+ __ CompareClassId(right, kMint, temp); // Is argument Mint?
+ __ j(NOT_EQUAL, deopt); // Argument neither Smi nor Mint.
+ __ cmpl(left, Immediate(0));
+ __ j(LESS, &smi_static_call); // Negative Smi receiver, Mint argument.
- ASSERT(comp->op_kind() == Token::kBIT_AND);
+ // Positive Smi receiver, Mint argument.
+ // Load lower argument Mint word, convert to Smi. It is OK to loose bits.
+ __ movl(right, FieldAddress(right, Mint::value_offset()));
+ __ SmiTag(right);
+ __ andl(result, right);
+ __ jmp(&done);
- // Load lower Mint word, convert to Smi. It is OK to loose bits.
- ASSERT(result == left);
+ __ Bind(&non_smi); // Receiver is non-Smi.
+ __ CompareClassId(left, kMint, temp); // Is receiver Mint?
+ __ j(NOT_EQUAL, deopt); // Receiver neither Smi nor Mint.
+ __ testl(right, Immediate(kSmiTagMask)); // Is argument Smi?
+ __ j(NOT_ZERO, &mint_static_call); // Mint receiver, non-Smi argument.
+ __ cmpl(right, Immediate(0));
+ __ j(LESS, &mint_static_call); // Mint receiver, negative Smi argument.
+
+ // Mint receiver, positive Smi argument.
+ // Load lower receiver Mint word, convert to Smi. It is OK to loose bits.
__ movl(result, FieldAddress(left, Mint::value_offset()));
__ SmiTag(result);
- __ Bind(&two_smi);
+ __ Bind(&smi_smi);
__ andl(result, right);
+ __ jmp(&done);
+
+ __ Bind(&smi_static_call);
+ {
+ Function& target = Function::ZoneHandle(
+ GetTargetForReceiverClassId(*comp->ic_data(), kSmi));
+ compiler->GenerateStaticCall(comp->instance_call()->cid(),
+ comp->instance_call()->token_index(),
+ comp->instance_call()->try_index(),
+ target,
+ comp->instance_call()->ArgumentCount(),
+ comp->instance_call()->argument_names());
+ }
+ __ jmp(&done);
+
+ __ Bind(&mint_static_call);
+ {
+ Function& target = Function::ZoneHandle(
+ GetTargetForReceiverClassId(*comp->ic_data(), kMint));
+ compiler->GenerateStaticCall(comp->instance_call()->cid(),
+ comp->instance_call()->token_index(),
+ comp->instance_call()->try_index(),
+ target,
+ comp->instance_call()->ArgumentCount(),
+ comp->instance_call()->argument_names());
+ }
+ __ Bind(&done);
}
@@ -1806,7 +1865,6 @@
__ Bind(&done);
}
-
} // namespace dart
#undef __

Powered by Google App Engine
This is Rietveld 408576698