Index: runtime/vm/intermediate_language_ia32.cc |
=================================================================== |
--- runtime/vm/intermediate_language_ia32.cc (revision 12258) |
+++ runtime/vm/intermediate_language_ia32.cc (working copy) |
@@ -864,22 +864,48 @@ |
} |
+static bool CanBeIndexImmediate(Value* index) { |
Vyacheslav Egorov (Google)
2012/09/12 12:55:06
CanBeImmediateIndex?
Florian Schneider
2012/09/12 13:28:35
Done.
|
+ if (!index->definition()->IsConstant()) return false; |
+ const Object& constant = index->definition()->AsConstant()->value(); |
+ const Smi& smi_const = Smi::Cast(constant); |
+ 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 int32_t RawSmi(const Object& constant) { |
Vyacheslav Egorov (Google)
2012/09/12 12:55:06
I don't like that the name clashes with RawSmi cla
srdjan
2012/09/12 12:56:16
RawSmi is the name of the raw smi object. I would
Florian Schneider
2012/09/12 13:28:35
Removed and replaced with Smi::Cast(...) instead.
|
+ ASSERT(constant.IsSmi()); |
+ return reinterpret_cast<int32_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 2. |
ASSERT(kSmiTagShift == 1); |
- __ movl(result, FieldAddress(array, index, TIMES_2, sizeof(RawArray))); |
+ if (locs()->in(1).IsRegister()) { |
+ Register index = locs()->in(1).reg(); |
+ __ movl(result, FieldAddress(array, index, TIMES_2, sizeof(RawArray))); |
+ } else { |
+ int32_t disp = RawSmi(locs()->in(1).constant()) * 2 + sizeof(RawArray); |
Vyacheslav Egorov (Google)
2012/09/12 12:55:06
How about just Smi::Cast(locs()->in(1).constant())
srdjan
2012/09/12 12:56:16
You could get also Smi::Value(...)do * 4.
Florian Schneider
2012/09/12 13:28:35
Done. Using Smi::Value() * kWordSize.
|
+ __ movl(result, FieldAddress(array, disp)); |
+ } |
} |
@@ -889,28 +915,37 @@ |
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 2. |
ASSERT(kSmiTagShift == 1); |
+ FieldAddress field_address = locs()->in(1).IsConstant() |
+ ? FieldAddress(array, |
+ RawSmi(locs()->in(1).constant()) * 2 + sizeof(RawArray)) |
Vyacheslav Egorov (Google)
2012/09/12 12:55:06
see above.
Florian Schneider
2012/09/12 13:28:35
Done.
|
+ : FieldAddress(array, locs()->in(1).reg(), TIMES_2, sizeof(RawArray)); |
+ |
if (this->value()->NeedsStoreBuffer()) { |
- __ StoreIntoObject(array, |
- FieldAddress(array, index, TIMES_2, sizeof(RawArray)), |
- value); |
+ Register value = locs()->in(2).reg(); |
+ __ StoreIntoObject(array, field_address, value); |
} else { |
- __ StoreIntoObjectNoBarrier(array, |
- FieldAddress(array, index, TIMES_2, sizeof(RawArray)), |
- value); |
+ if (locs()->in(2).IsConstant()) { |
+ const Object& constant = locs()->in(2).constant(); |
+ __ StoreIntoObjectNoBarrier(array, field_address, constant); |
+ } else { |
+ Register value = locs()->in(2).reg(); |
+ __ StoreIntoObjectNoBarrier(array, field_address, value); |
+ } |
} |
} |