Chromium Code Reviews| Index: runtime/vm/simulator_dbc.cc |
| diff --git a/runtime/vm/simulator_dbc.cc b/runtime/vm/simulator_dbc.cc |
| index ff9b6fd23251dbea459851a0579598095085914e..d66324141e32e39abd386bbcbd9394acda6aff93 100644 |
| --- a/runtime/vm/simulator_dbc.cc |
| +++ b/runtime/vm/simulator_dbc.cc |
| @@ -249,6 +249,17 @@ class SimulatorHelpers { |
| ASSERT(GetClassId(code) == kCodeCid); |
| FP[kPcMarkerSlotFromFp] = code; |
| } |
| + |
| + DART_FORCE_INLINE static uint8_t* GetTypedData( |
| + RawObject* obj, RawObject* index, intptr_t scale) { |
| + ASSERT(RawObject::IsTypedDataClassId(obj->GetClassId())); |
| + RawTypedData* array = reinterpret_cast<RawTypedData*>(obj); |
| + const intptr_t byte_offset = Smi::Value(RAW_CAST(Smi, index)); |
| + ASSERT(byte_offset >= 0); |
| + ASSERT(((byte_offset + (1 << scale)) >> scale) <= |
| + Smi::Value(array->ptr()->length_)); |
| + return array->ptr()->data() + byte_offset; |
| + } |
| }; |
| @@ -1757,10 +1768,10 @@ RawObject* Simulator::Call(const Code& code, |
| } |
| { |
| - BYTECODE(ShrImm, A_B_C); |
| + BYTECODE(ShlImm, A_B_C); |
| const uint8_t shift = rC; |
| - const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]) >> kSmiTagSize; |
| - *reinterpret_cast<intptr_t*>(&FP[rA]) = (lhs >> shift) << kSmiTagSize; |
| + const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]); |
| + FP[rA] = reinterpret_cast<RawObject*>(lhs << shift); |
| DISPATCH(); |
| } |
| @@ -1780,6 +1791,29 @@ RawObject* Simulator::Call(const Code& code, |
| DISPATCH(); |
| } |
| + { |
| + BYTECODE(UnboxInt32, A_B_C); |
| + const intptr_t box_cid = SimulatorHelpers::GetClassId(FP[rB]); |
| + const bool may_truncate = rC == 1; |
| + if (box_cid == kSmiCid) { |
| + const intptr_t value = reinterpret_cast<intptr_t>(FP[rB]) >> kSmiTagSize; |
| + const int32_t value32 = static_cast<int32_t>(value); |
| + if (may_truncate || (value == static_cast<intptr_t>(value32))) { |
| + FP[rA] = reinterpret_cast<RawObject*>(value); |
| + pc++; |
| + } |
| + } else if (box_cid == kMintCid) { |
| + RawMint* mint = RAW_CAST(Mint, FP[rB]); |
| + const int64_t value = mint->ptr()->value_; |
| + const int32_t value32 = static_cast<int32_t>(value); |
| + if (may_truncate || (value == static_cast<int64_t>(value32))) { |
| + FP[rA] = reinterpret_cast<RawObject*>(value); |
| + pc++; |
| + } |
| + } |
| + DISPATCH(); |
| + } |
| + |
| #if defined(ARCH_IS_64_BIT) |
| { |
| BYTECODE(WriteIntoDouble, A_D); |
| @@ -1931,23 +1965,29 @@ RawObject* Simulator::Call(const Code& code, |
| { |
| BYTECODE(LoadIndexedFloat64, A_B_C); |
| - ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); |
| - RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); |
| - RawSmi* index = RAW_CAST(Smi, FP[rC]); |
| - ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); |
| - double* data = reinterpret_cast<double*>(array->ptr()->data()); |
| - FP[rA] = bit_cast<RawObject*, double>(data[Smi::Value(index)]); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 3); |
| + *reinterpret_cast<uint64_t*>(&FP[rA]) = *reinterpret_cast<uint64_t*>(data); |
| DISPATCH(); |
| } |
| { |
| BYTECODE(StoreIndexedFloat64, A_B_C); |
| - ASSERT(RawObject::IsTypedDataClassId(FP[rA]->GetClassId())); |
| - RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rA]); |
| - RawSmi* index = RAW_CAST(Smi, FP[rB]); |
| - ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); |
| - double* data = reinterpret_cast<double*>(array->ptr()->data()); |
| - data[Smi::Value(index)] = bit_cast<double, RawObject*>(FP[rC]); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 3); |
| + *reinterpret_cast<uint64_t*>(data) = reinterpret_cast<uint64_t>(FP[rC]); |
| + DISPATCH(); |
| + } |
| + |
| + { |
| + BYTECODE(BoxInt32, A_D); |
| + const intptr_t value = reinterpret_cast<intptr_t>(FP[rD]); |
| + FP[rA] = reinterpret_cast<RawObject*>((value << 32) >> (32 - kSmiTagSize)); |
|
Florian Schneider
2016/08/19 21:39:06
Why is shifting left by 32 and right by 31 necessa
zra
2016/08/19 22:16:04
Both the x64 and arm64 implementations zero or sig
|
| + DISPATCH(); |
| + } |
| + |
| + { |
| + BYTECODE(BoxUint32, A_D); |
| + const uintptr_t value = reinterpret_cast<uintptr_t>(FP[rD]); |
| + FP[rA] = reinterpret_cast<RawObject*>((value << 32) >> (32 - kSmiTagSize)); |
|
Florian Schneider
2016/08/19 21:39:05
Maybe add a local helper SmiTagInt32(intptr_t valu
zra
2016/08/19 22:16:04
Decided to do casting instead of shifting.
|
| DISPATCH(); |
| } |
| #else // defined(ARCH_IS_64_BIT) |
| @@ -2064,6 +2104,18 @@ RawObject* Simulator::Call(const Code& code, |
| UNREACHABLE(); |
| DISPATCH(); |
| } |
| + |
| + { |
| + BYTECODE(BoxInt32, A_D); |
| + UNREACHABLE(); |
| + DISPATCH(); |
| + } |
| + |
| + { |
| + BYTECODE(BoxUint32, A_D); |
| + UNREACHABLE(); |
| + DISPATCH(); |
| + } |
| #endif // defined(ARCH_IS_64_BIT) |
| // Return and return like instructions (Instrinsic). |
| @@ -2854,13 +2906,8 @@ RawObject* Simulator::Call(const Code& code, |
| { |
| BYTECODE(StoreIndexedUint8, A_B_C); |
| - ASSERT(RawObject::IsTypedDataClassId(FP[rA]->GetClassId())); |
| - RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rA]); |
| - RawSmi* index = RAW_CAST(Smi, FP[rB]); |
| - RawSmi* value = RAW_CAST(Smi, FP[rC]); |
| - ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); |
| - uint8_t* data = reinterpret_cast<uint8_t*>(array->ptr()->data()); |
| - data[Smi::Value(index)] = static_cast<uint8_t>(Smi::Value(value)); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 0); |
| + *data = static_cast<uint8_t>(Smi::Value(RAW_CAST(Smi, FP[rC]))); |
| DISPATCH(); |
| } |
| @@ -2874,6 +2921,14 @@ RawObject* Simulator::Call(const Code& code, |
| } |
| { |
| + BYTECODE(StoreIndexedUint32, A_B_C); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 2); |
| + const uintptr_t value = reinterpret_cast<uintptr_t>(FP[rC]); |
| + *reinterpret_cast<uint32_t*>(data) = static_cast<uint32_t>(value); |
| + DISPATCH(); |
| + } |
| + |
| + { |
| BYTECODE(LoadIndexed, A_B_C); |
| RawArray* array = RAW_CAST(Array, FP[rB]); |
| RawSmi* index = RAW_CAST(Smi, FP[rC]); |
| @@ -2884,23 +2939,29 @@ RawObject* Simulator::Call(const Code& code, |
| { |
| BYTECODE(LoadIndexedUint8, A_B_C); |
| - ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); |
| - RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); |
| - RawSmi* index = RAW_CAST(Smi, FP[rC]); |
| - ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); |
| - uint8_t* data = reinterpret_cast<uint8_t*>(array->ptr()->data()); |
| - FP[rA] = Smi::New(data[Smi::Value(index)]); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 0); |
| + FP[rA] = Smi::New(*data); |
| DISPATCH(); |
| } |
| { |
| BYTECODE(LoadIndexedInt8, A_B_C); |
| - ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); |
| - RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); |
| - RawSmi* index = RAW_CAST(Smi, FP[rC]); |
| - ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); |
| - int8_t* data = reinterpret_cast<int8_t*>(array->ptr()->data()); |
| - FP[rA] = Smi::New(data[Smi::Value(index)]); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 0); |
| + FP[rA] = Smi::New(*reinterpret_cast<int8_t*>(data)); |
| + DISPATCH(); |
| + } |
| + |
| + { |
| + BYTECODE(LoadIndexedUint32, A_B_C); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 2); |
| + FP[rA] = reinterpret_cast<RawObject*>(*reinterpret_cast<uintptr_t*>(data)); |
| + DISPATCH(); |
| + } |
| + |
| + { |
| + BYTECODE(LoadIndexedInt32, A_B_C); |
| + uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 2); |
| + FP[rA] = reinterpret_cast<RawObject*>(*reinterpret_cast<intptr_t*>(data)); |
| DISPATCH(); |
| } |