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

Unified Diff: runtime/vm/intermediate_language_x64.cc

Issue 10933045: Add immediate operand support for indexed operations. (Closed) Base URL: http://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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/intermediate_language_x64.cc
===================================================================
--- runtime/vm/intermediate_language_x64.cc (revision 12258)
+++ runtime/vm/intermediate_language_x64.cc (working copy)
@@ -880,22 +880,49 @@
}
+static bool CanBeIndexImmediate(Value* index) {
+ if (!index->definition()->IsConstant()) return false;
+ const Object& constant = index->definition()->AsConstant()->value();
+ const Smi& smi_const = Smi::Cast(constant);
srdjan 2012/09/12 12:56:16 The reason why this works is because this code mus
Florian Schneider 2012/09/12 13:28:35 Yes, and when optimizing we generate a smi-check f
+ int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray);
+ return Utils::IsInt(32, disp);
+}
+
+
LocationSummary* LoadIndexedInstr::MakeLocationSummary() const {
const intptr_t kNumInputs = 2;
- return LocationSummary::Make(kNumInputs,
- Location::RequiresRegister(),
- LocationSummary::kNoCall);
+ const intptr_t kNumTemps = 0;
+ LocationSummary* locs =
+ new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
+ locs->set_in(0, Location::RequiresRegister());
+ locs->set_in(1, CanBeIndexImmediate(index())
+ ? Location::RegisterOrConstant(index())
+ : Location::RequiresRegister());
+ locs->set_out(Location::RequiresRegister());
+ return locs;
}
+static int64_t RawSmi(const Object& constant) {
+ ASSERT(constant.IsSmi());
+ return reinterpret_cast<int64_t>(constant.raw());
+}
+
+
void LoadIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
Register array = locs()->in(0).reg();
- Register index = locs()->in(1).reg();
Register result = locs()->out().reg();
// Note that index is Smi, i.e, times 4.
ASSERT(kSmiTagShift == 1);
- __ movq(result, FieldAddress(array, index, TIMES_4, sizeof(RawArray)));
+ if (locs()->in(1).IsRegister()) {
+ Register index = locs()->in(1).reg();
+ __ movq(result, FieldAddress(array, index, TIMES_4, sizeof(RawArray)));
+ } else {
+ int64_t disp = RawSmi(locs()->in(1).constant()) * 4 + sizeof(RawArray);
+ ASSERT(Utils::IsInt(32, disp));
+ __ movq(result, FieldAddress(array, static_cast<int32_t>(disp)));
+ }
}
@@ -905,28 +932,39 @@
LocationSummary* locs =
new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
locs->set_in(0, Location::RequiresRegister());
- locs->set_in(1, Location::RequiresRegister());
- locs->set_in(2, value()->NeedsStoreBuffer() ? Location::WritableRegister()
- : Location::RequiresRegister());
+ locs->set_in(1, CanBeIndexImmediate(index())
+ ? Location::RegisterOrConstant(index())
+ : Location::RequiresRegister());
+ locs->set_in(2, value()->NeedsStoreBuffer()
+ ? Location::WritableRegister()
+ : Location::RegisterOrConstant(value()));
return locs;
}
void StoreIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
Register array = locs()->in(0).reg();
- Register index = locs()->in(1).reg();
- Register value = locs()->in(2).reg();
// Note that index is Smi, i.e, times 4.
ASSERT(kSmiTagShift == 1);
+ FieldAddress field_address = locs()->in(1).IsConstant()
+ ? FieldAddress(
+ array,
+ static_cast<int32_t>(
+ RawSmi(locs()->in(1).constant()) * 4 + sizeof(RawArray)))
+ : FieldAddress(array, locs()->in(1).reg(), TIMES_4, sizeof(RawArray));
+
if (this->value()->NeedsStoreBuffer()) {
- __ StoreIntoObject(array,
- FieldAddress(array, index, TIMES_4, sizeof(RawArray)),
- value);
+ Register value = locs()->in(2).reg();
+ __ StoreIntoObject(array, field_address, value);
} else {
- __ StoreIntoObjectNoBarrier(array,
- FieldAddress(array, index, TIMES_4, sizeof(RawArray)),
- value);
+ if (locs()->in(2).IsConstant()) {
+ const Object& constant = locs()->in(2).constant();
+ __ StoreObject(field_address, constant);
+ } else {
+ Register value = locs()->in(2).reg();
+ __ StoreIntoObjectNoBarrier(array, field_address, value);
+ }
}
}
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/intermediate_language_ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698