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

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

Issue 2258493004: DBC: Fixes typed data bugs. Adds unboxed int32 instructions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 4 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
« no previous file with comments | « runtime/vm/intermediate_language_dbc.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 <setjmp.h> // NOLINT 5 #include <setjmp.h> // NOLINT
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #if defined(TARGET_ARCH_DBC) 9 #if defined(TARGET_ARCH_DBC)
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 DART_FORCE_INLINE static RawCode* FrameCode(RawObject** FP) { 242 DART_FORCE_INLINE static RawCode* FrameCode(RawObject** FP) {
243 ASSERT(GetClassId(FP[kPcMarkerSlotFromFp]) == kCodeCid); 243 ASSERT(GetClassId(FP[kPcMarkerSlotFromFp]) == kCodeCid);
244 return static_cast<RawCode*>(FP[kPcMarkerSlotFromFp]); 244 return static_cast<RawCode*>(FP[kPcMarkerSlotFromFp]);
245 } 245 }
246 246
247 247
248 DART_FORCE_INLINE static void SetFrameCode(RawObject** FP, RawCode* code) { 248 DART_FORCE_INLINE static void SetFrameCode(RawObject** FP, RawCode* code) {
249 ASSERT(GetClassId(code) == kCodeCid); 249 ASSERT(GetClassId(code) == kCodeCid);
250 FP[kPcMarkerSlotFromFp] = code; 250 FP[kPcMarkerSlotFromFp] = code;
251 } 251 }
252
253 DART_FORCE_INLINE static uint8_t* GetTypedData(
254 RawObject* obj, RawObject* index, intptr_t scale) {
255 ASSERT(RawObject::IsTypedDataClassId(obj->GetClassId()));
256 RawTypedData* array = reinterpret_cast<RawTypedData*>(obj);
257 const intptr_t byte_offset = Smi::Value(RAW_CAST(Smi, index));
258 ASSERT(byte_offset >= 0);
259 ASSERT(((byte_offset + (1 << scale)) >> scale) <=
260 Smi::Value(array->ptr()->length_));
261 return array->ptr()->data() + byte_offset;
262 }
252 }; 263 };
253 264
254 265
255 DART_FORCE_INLINE static uint32_t* SavedCallerPC(RawObject** FP) { 266 DART_FORCE_INLINE static uint32_t* SavedCallerPC(RawObject** FP) {
256 return reinterpret_cast<uint32_t*>(FP[kSavedCallerPcSlotFromFp]); 267 return reinterpret_cast<uint32_t*>(FP[kSavedCallerPcSlotFromFp]);
257 } 268 }
258 269
259 270
260 DART_FORCE_INLINE static RawFunction* FrameFunction(RawObject** FP) { 271 DART_FORCE_INLINE static RawFunction* FrameFunction(RawObject** FP) {
261 RawFunction* function = static_cast<RawFunction*>(FP[kFunctionSlotFromFp]); 272 RawFunction* function = static_cast<RawFunction*>(FP[kFunctionSlotFromFp]);
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 (rhs >= kBitsPerWord) ? (kBitsPerWord - 1) : rhs; 1761 (rhs >= kBitsPerWord) ? (kBitsPerWord - 1) : rhs;
1751 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]) >> kSmiTagSize; 1762 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]) >> kSmiTagSize;
1752 *reinterpret_cast<intptr_t*>(&FP[rA]) = 1763 *reinterpret_cast<intptr_t*>(&FP[rA]) =
1753 (lhs >> shift_amount) << kSmiTagSize; 1764 (lhs >> shift_amount) << kSmiTagSize;
1754 pc++; 1765 pc++;
1755 } 1766 }
1756 DISPATCH(); 1767 DISPATCH();
1757 } 1768 }
1758 1769
1759 { 1770 {
1760 BYTECODE(ShrImm, A_B_C); 1771 BYTECODE(ShlImm, A_B_C);
1761 const uint8_t shift = rC; 1772 const uint8_t shift = rC;
1762 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]) >> kSmiTagSize; 1773 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]);
1763 *reinterpret_cast<intptr_t*>(&FP[rA]) = (lhs >> shift) << kSmiTagSize; 1774 FP[rA] = reinterpret_cast<RawObject*>(lhs << shift);
1764 DISPATCH(); 1775 DISPATCH();
1765 } 1776 }
1766 1777
1767 { 1778 {
1768 BYTECODE(Min, A_B_C); 1779 BYTECODE(Min, A_B_C);
1769 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]); 1780 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]);
1770 const intptr_t rhs = reinterpret_cast<intptr_t>(FP[rC]); 1781 const intptr_t rhs = reinterpret_cast<intptr_t>(FP[rC]);
1771 FP[rA] = reinterpret_cast<RawObject*>((lhs < rhs) ? lhs : rhs); 1782 FP[rA] = reinterpret_cast<RawObject*>((lhs < rhs) ? lhs : rhs);
1772 DISPATCH(); 1783 DISPATCH();
1773 } 1784 }
1774 1785
1775 { 1786 {
1776 BYTECODE(Max, A_B_C); 1787 BYTECODE(Max, A_B_C);
1777 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]); 1788 const intptr_t lhs = reinterpret_cast<intptr_t>(FP[rB]);
1778 const intptr_t rhs = reinterpret_cast<intptr_t>(FP[rC]); 1789 const intptr_t rhs = reinterpret_cast<intptr_t>(FP[rC]);
1779 FP[rA] = reinterpret_cast<RawObject*>((lhs > rhs) ? lhs : rhs); 1790 FP[rA] = reinterpret_cast<RawObject*>((lhs > rhs) ? lhs : rhs);
1780 DISPATCH(); 1791 DISPATCH();
1781 } 1792 }
1782 1793
1794 {
1795 BYTECODE(UnboxInt32, A_B_C);
1796 const intptr_t box_cid = SimulatorHelpers::GetClassId(FP[rB]);
1797 const bool may_truncate = rC == 1;
1798 if (box_cid == kSmiCid) {
1799 const intptr_t value = reinterpret_cast<intptr_t>(FP[rB]) >> kSmiTagSize;
1800 const int32_t value32 = static_cast<int32_t>(value);
1801 if (may_truncate || (value == static_cast<intptr_t>(value32))) {
1802 FP[rA] = reinterpret_cast<RawObject*>(value);
1803 pc++;
1804 }
1805 } else if (box_cid == kMintCid) {
1806 RawMint* mint = RAW_CAST(Mint, FP[rB]);
1807 const int64_t value = mint->ptr()->value_;
1808 const int32_t value32 = static_cast<int32_t>(value);
1809 if (may_truncate || (value == static_cast<int64_t>(value32))) {
1810 FP[rA] = reinterpret_cast<RawObject*>(value);
1811 pc++;
1812 }
1813 }
1814 DISPATCH();
1815 }
1816
1783 #if defined(ARCH_IS_64_BIT) 1817 #if defined(ARCH_IS_64_BIT)
1784 { 1818 {
1785 BYTECODE(WriteIntoDouble, A_D); 1819 BYTECODE(WriteIntoDouble, A_D);
1786 const double value = bit_cast<double, RawObject*>(FP[rD]); 1820 const double value = bit_cast<double, RawObject*>(FP[rD]);
1787 RawDouble* box = RAW_CAST(Double, *SP--); 1821 RawDouble* box = RAW_CAST(Double, *SP--);
1788 box->ptr()->value_ = value; 1822 box->ptr()->value_ = value;
1789 FP[rA] = box; 1823 FP[rA] = box;
1790 DISPATCH(); 1824 DISPATCH();
1791 } 1825 }
1792 1826
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 { 1958 {
1925 BYTECODE(DMax, A_B_C); 1959 BYTECODE(DMax, A_B_C);
1926 const double lhs = bit_cast<double, RawObject*>(FP[rB]); 1960 const double lhs = bit_cast<double, RawObject*>(FP[rB]);
1927 const double rhs = bit_cast<double, RawObject*>(FP[rC]); 1961 const double rhs = bit_cast<double, RawObject*>(FP[rC]);
1928 FP[rA] = bit_cast<RawObject*, double>(fmax(lhs, rhs)); 1962 FP[rA] = bit_cast<RawObject*, double>(fmax(lhs, rhs));
1929 DISPATCH(); 1963 DISPATCH();
1930 } 1964 }
1931 1965
1932 { 1966 {
1933 BYTECODE(LoadIndexedFloat64, A_B_C); 1967 BYTECODE(LoadIndexedFloat64, A_B_C);
1934 ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); 1968 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 3);
1935 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); 1969 *reinterpret_cast<uint64_t*>(&FP[rA]) = *reinterpret_cast<uint64_t*>(data);
1936 RawSmi* index = RAW_CAST(Smi, FP[rC]);
1937 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
1938 double* data = reinterpret_cast<double*>(array->ptr()->data());
1939 FP[rA] = bit_cast<RawObject*, double>(data[Smi::Value(index)]);
1940 DISPATCH(); 1970 DISPATCH();
1941 } 1971 }
1942 1972
1943 { 1973 {
1944 BYTECODE(StoreIndexedFloat64, A_B_C); 1974 BYTECODE(StoreIndexedFloat64, A_B_C);
1945 ASSERT(RawObject::IsTypedDataClassId(FP[rA]->GetClassId())); 1975 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 3);
1946 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rA]); 1976 *reinterpret_cast<uint64_t*>(data) = reinterpret_cast<uint64_t>(FP[rC]);
1947 RawSmi* index = RAW_CAST(Smi, FP[rB]); 1977 DISPATCH();
1948 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); 1978 }
1949 double* data = reinterpret_cast<double*>(array->ptr()->data()); 1979
1950 data[Smi::Value(index)] = bit_cast<double, RawObject*>(FP[rC]); 1980 {
1981 BYTECODE(BoxInt32, A_D);
1982 // Casts sign-extend high 32 bits from low 32 bits.
1983 const intptr_t value = reinterpret_cast<intptr_t>(FP[rD]);
1984 const int32_t value32 = static_cast<int32_t>(value);
1985 FP[rA] = Smi::New(static_cast<intptr_t>(value32));
1986 DISPATCH();
1987 }
1988
1989 {
1990 BYTECODE(BoxUint32, A_D);
1991 // Casts to zero out high 32 bits.
1992 const uintptr_t value = reinterpret_cast<uintptr_t>(FP[rD]);
1993 const uint32_t value32 = static_cast<uint32_t>(value);
1994 FP[rA] = Smi::New(static_cast<intptr_t>(value32));
1951 DISPATCH(); 1995 DISPATCH();
1952 } 1996 }
1953 #else // defined(ARCH_IS_64_BIT) 1997 #else // defined(ARCH_IS_64_BIT)
1954 { 1998 {
1955 BYTECODE(WriteIntoDouble, A_D); 1999 BYTECODE(WriteIntoDouble, A_D);
1956 UNIMPLEMENTED(); 2000 UNIMPLEMENTED();
1957 DISPATCH(); 2001 DISPATCH();
1958 } 2002 }
1959 2003
1960 { 2004 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 BYTECODE(LoadIndexedFloat64, A_B_C); 2101 BYTECODE(LoadIndexedFloat64, A_B_C);
2058 UNREACHABLE(); 2102 UNREACHABLE();
2059 DISPATCH(); 2103 DISPATCH();
2060 } 2104 }
2061 2105
2062 { 2106 {
2063 BYTECODE(StoreIndexedFloat64, A_B_C); 2107 BYTECODE(StoreIndexedFloat64, A_B_C);
2064 UNREACHABLE(); 2108 UNREACHABLE();
2065 DISPATCH(); 2109 DISPATCH();
2066 } 2110 }
2111
2112 {
2113 BYTECODE(BoxInt32, A_D);
2114 UNREACHABLE();
2115 DISPATCH();
2116 }
2117
2118 {
2119 BYTECODE(BoxUint32, A_D);
2120 UNREACHABLE();
2121 DISPATCH();
2122 }
2067 #endif // defined(ARCH_IS_64_BIT) 2123 #endif // defined(ARCH_IS_64_BIT)
2068 2124
2069 // Return and return like instructions (Instrinsic). 2125 // Return and return like instructions (Instrinsic).
2070 { 2126 {
2071 RawObject* result; // result to return to the caller. 2127 RawObject* result; // result to return to the caller.
2072 2128
2073 BYTECODE(Intrinsic, A); 2129 BYTECODE(Intrinsic, A);
2074 // Try invoking intrinsic handler. If it succeeds (returns true) 2130 // Try invoking intrinsic handler. If it succeeds (returns true)
2075 // then just return the value it returned to the caller. 2131 // then just return the value it returned to the caller.
2076 result = null_value; 2132 result = null_value;
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 RawArray* array = RAW_CAST(Array, FP[rA]); 2903 RawArray* array = RAW_CAST(Array, FP[rA]);
2848 RawSmi* index = RAW_CAST(Smi, FP[rB]); 2904 RawSmi* index = RAW_CAST(Smi, FP[rB]);
2849 RawObject* value = FP[rC]; 2905 RawObject* value = FP[rC];
2850 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); 2906 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2851 array->StorePointer(array->ptr()->data() + Smi::Value(index), value); 2907 array->StorePointer(array->ptr()->data() + Smi::Value(index), value);
2852 DISPATCH(); 2908 DISPATCH();
2853 } 2909 }
2854 2910
2855 { 2911 {
2856 BYTECODE(StoreIndexedUint8, A_B_C); 2912 BYTECODE(StoreIndexedUint8, A_B_C);
2857 ASSERT(RawObject::IsTypedDataClassId(FP[rA]->GetClassId())); 2913 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 0);
2858 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rA]); 2914 *data = static_cast<uint8_t>(Smi::Value(RAW_CAST(Smi, FP[rC])));
2859 RawSmi* index = RAW_CAST(Smi, FP[rB]);
2860 RawSmi* value = RAW_CAST(Smi, FP[rC]);
2861 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2862 uint8_t* data = reinterpret_cast<uint8_t*>(array->ptr()->data());
2863 data[Smi::Value(index)] = static_cast<uint8_t>(Smi::Value(value));
2864 DISPATCH(); 2915 DISPATCH();
2865 } 2916 }
2866 2917
2867 { 2918 {
2868 BYTECODE(StoreIndexedExternalUint8, A_B_C); 2919 BYTECODE(StoreIndexedExternalUint8, A_B_C);
2869 uint8_t* array = reinterpret_cast<uint8_t*>(FP[rA]); 2920 uint8_t* array = reinterpret_cast<uint8_t*>(FP[rA]);
2870 RawSmi* index = RAW_CAST(Smi, FP[rB]); 2921 RawSmi* index = RAW_CAST(Smi, FP[rB]);
2871 RawSmi* value = RAW_CAST(Smi, FP[rC]); 2922 RawSmi* value = RAW_CAST(Smi, FP[rC]);
2872 array[Smi::Value(index)] = static_cast<uint8_t>(Smi::Value(value)); 2923 array[Smi::Value(index)] = static_cast<uint8_t>(Smi::Value(value));
2873 DISPATCH(); 2924 DISPATCH();
2874 } 2925 }
2875 2926
2876 { 2927 {
2928 BYTECODE(StoreIndexedUint32, A_B_C);
2929 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 2);
2930 const uintptr_t value = reinterpret_cast<uintptr_t>(FP[rC]);
2931 *reinterpret_cast<uint32_t*>(data) = static_cast<uint32_t>(value);
2932 DISPATCH();
2933 }
2934
2935 {
2877 BYTECODE(LoadIndexed, A_B_C); 2936 BYTECODE(LoadIndexed, A_B_C);
2878 RawArray* array = RAW_CAST(Array, FP[rB]); 2937 RawArray* array = RAW_CAST(Array, FP[rB]);
2879 RawSmi* index = RAW_CAST(Smi, FP[rC]); 2938 RawSmi* index = RAW_CAST(Smi, FP[rC]);
2880 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); 2939 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2881 FP[rA] = array->ptr()->data()[Smi::Value(index)]; 2940 FP[rA] = array->ptr()->data()[Smi::Value(index)];
2882 DISPATCH(); 2941 DISPATCH();
2883 } 2942 }
2884 2943
2885 { 2944 {
2886 BYTECODE(LoadIndexedUint8, A_B_C); 2945 BYTECODE(LoadIndexedUint8, A_B_C);
2887 ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); 2946 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 0);
2888 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); 2947 FP[rA] = Smi::New(*data);
2889 RawSmi* index = RAW_CAST(Smi, FP[rC]);
2890 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2891 uint8_t* data = reinterpret_cast<uint8_t*>(array->ptr()->data());
2892 FP[rA] = Smi::New(data[Smi::Value(index)]);
2893 DISPATCH(); 2948 DISPATCH();
2894 } 2949 }
2895 2950
2896 { 2951 {
2897 BYTECODE(LoadIndexedInt8, A_B_C); 2952 BYTECODE(LoadIndexedInt8, A_B_C);
2898 ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); 2953 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 0);
2899 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); 2954 FP[rA] = Smi::New(*reinterpret_cast<int8_t*>(data));
2900 RawSmi* index = RAW_CAST(Smi, FP[rC]);
2901 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2902 int8_t* data = reinterpret_cast<int8_t*>(array->ptr()->data());
2903 FP[rA] = Smi::New(data[Smi::Value(index)]);
2904 DISPATCH(); 2955 DISPATCH();
2905 } 2956 }
2906 2957
2958 {
2959 BYTECODE(LoadIndexedUint32, A_B_C);
2960 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 2);
2961 FP[rA] = reinterpret_cast<RawObject*>(*reinterpret_cast<uintptr_t*>(data));
2962 DISPATCH();
2963 }
2964
2965 {
2966 BYTECODE(LoadIndexedInt32, A_B_C);
2967 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 2);
2968 FP[rA] = reinterpret_cast<RawObject*>(*reinterpret_cast<intptr_t*>(data));
2969 DISPATCH();
2970 }
2971
2907 { 2972 {
2908 BYTECODE(LoadIndexedExternalUint8, A_B_C); 2973 BYTECODE(LoadIndexedExternalUint8, A_B_C);
2909 uint8_t* data = reinterpret_cast<uint8_t*>(FP[rB]); 2974 uint8_t* data = reinterpret_cast<uint8_t*>(FP[rB]);
2910 RawSmi* index = RAW_CAST(Smi, FP[rC]); 2975 RawSmi* index = RAW_CAST(Smi, FP[rC]);
2911 FP[rA] = Smi::New(data[Smi::Value(index)]); 2976 FP[rA] = Smi::New(data[Smi::Value(index)]);
2912 DISPATCH(); 2977 DISPATCH();
2913 } 2978 }
2914 2979
2915 { 2980 {
2916 BYTECODE(LoadIndexedExternalInt8, A_B_C); 2981 BYTECODE(LoadIndexedExternalInt8, A_B_C);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 pc_ = pc; 3181 pc_ = pc;
3117 special_[kExceptionSpecialIndex] = raw_exception; 3182 special_[kExceptionSpecialIndex] = raw_exception;
3118 special_[kStacktraceSpecialIndex] = raw_stacktrace; 3183 special_[kStacktraceSpecialIndex] = raw_stacktrace;
3119 buf->Longjmp(); 3184 buf->Longjmp();
3120 UNREACHABLE(); 3185 UNREACHABLE();
3121 } 3186 }
3122 3187
3123 } // namespace dart 3188 } // namespace dart
3124 3189
3125 #endif // defined TARGET_ARCH_DBC 3190 #endif // defined TARGET_ARCH_DBC
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language_dbc.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698