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

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: Cleanup 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 const intptr_t value = reinterpret_cast<intptr_t>(FP[rD]);
1983 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
1984 DISPATCH();
1985 }
1986
1987 {
1988 BYTECODE(BoxUint32, A_D);
1989 const uintptr_t value = reinterpret_cast<uintptr_t>(FP[rD]);
1990 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.
1951 DISPATCH(); 1991 DISPATCH();
1952 } 1992 }
1953 #else // defined(ARCH_IS_64_BIT) 1993 #else // defined(ARCH_IS_64_BIT)
1954 { 1994 {
1955 BYTECODE(WriteIntoDouble, A_D); 1995 BYTECODE(WriteIntoDouble, A_D);
1956 UNIMPLEMENTED(); 1996 UNIMPLEMENTED();
1957 DISPATCH(); 1997 DISPATCH();
1958 } 1998 }
1959 1999
1960 { 2000 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 BYTECODE(LoadIndexedFloat64, A_B_C); 2097 BYTECODE(LoadIndexedFloat64, A_B_C);
2058 UNREACHABLE(); 2098 UNREACHABLE();
2059 DISPATCH(); 2099 DISPATCH();
2060 } 2100 }
2061 2101
2062 { 2102 {
2063 BYTECODE(StoreIndexedFloat64, A_B_C); 2103 BYTECODE(StoreIndexedFloat64, A_B_C);
2064 UNREACHABLE(); 2104 UNREACHABLE();
2065 DISPATCH(); 2105 DISPATCH();
2066 } 2106 }
2107
2108 {
2109 BYTECODE(BoxInt32, A_D);
2110 UNREACHABLE();
2111 DISPATCH();
2112 }
2113
2114 {
2115 BYTECODE(BoxUint32, A_D);
2116 UNREACHABLE();
2117 DISPATCH();
2118 }
2067 #endif // defined(ARCH_IS_64_BIT) 2119 #endif // defined(ARCH_IS_64_BIT)
2068 2120
2069 // Return and return like instructions (Instrinsic). 2121 // Return and return like instructions (Instrinsic).
2070 { 2122 {
2071 RawObject* result; // result to return to the caller. 2123 RawObject* result; // result to return to the caller.
2072 2124
2073 BYTECODE(Intrinsic, A); 2125 BYTECODE(Intrinsic, A);
2074 // Try invoking intrinsic handler. If it succeeds (returns true) 2126 // Try invoking intrinsic handler. If it succeeds (returns true)
2075 // then just return the value it returned to the caller. 2127 // then just return the value it returned to the caller.
2076 result = null_value; 2128 result = null_value;
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 RawArray* array = RAW_CAST(Array, FP[rA]); 2899 RawArray* array = RAW_CAST(Array, FP[rA]);
2848 RawSmi* index = RAW_CAST(Smi, FP[rB]); 2900 RawSmi* index = RAW_CAST(Smi, FP[rB]);
2849 RawObject* value = FP[rC]; 2901 RawObject* value = FP[rC];
2850 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); 2902 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2851 array->StorePointer(array->ptr()->data() + Smi::Value(index), value); 2903 array->StorePointer(array->ptr()->data() + Smi::Value(index), value);
2852 DISPATCH(); 2904 DISPATCH();
2853 } 2905 }
2854 2906
2855 { 2907 {
2856 BYTECODE(StoreIndexedUint8, A_B_C); 2908 BYTECODE(StoreIndexedUint8, A_B_C);
2857 ASSERT(RawObject::IsTypedDataClassId(FP[rA]->GetClassId())); 2909 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 0);
2858 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rA]); 2910 *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(); 2911 DISPATCH();
2865 } 2912 }
2866 2913
2867 { 2914 {
2868 BYTECODE(StoreIndexedExternalUint8, A_B_C); 2915 BYTECODE(StoreIndexedExternalUint8, A_B_C);
2869 uint8_t* array = reinterpret_cast<uint8_t*>(FP[rA]); 2916 uint8_t* array = reinterpret_cast<uint8_t*>(FP[rA]);
2870 RawSmi* index = RAW_CAST(Smi, FP[rB]); 2917 RawSmi* index = RAW_CAST(Smi, FP[rB]);
2871 RawSmi* value = RAW_CAST(Smi, FP[rC]); 2918 RawSmi* value = RAW_CAST(Smi, FP[rC]);
2872 array[Smi::Value(index)] = static_cast<uint8_t>(Smi::Value(value)); 2919 array[Smi::Value(index)] = static_cast<uint8_t>(Smi::Value(value));
2873 DISPATCH(); 2920 DISPATCH();
2874 } 2921 }
2875 2922
2876 { 2923 {
2924 BYTECODE(StoreIndexedUint32, A_B_C);
2925 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rA], FP[rB], 2);
2926 const uintptr_t value = reinterpret_cast<uintptr_t>(FP[rC]);
2927 *reinterpret_cast<uint32_t*>(data) = static_cast<uint32_t>(value);
2928 DISPATCH();
2929 }
2930
2931 {
2877 BYTECODE(LoadIndexed, A_B_C); 2932 BYTECODE(LoadIndexed, A_B_C);
2878 RawArray* array = RAW_CAST(Array, FP[rB]); 2933 RawArray* array = RAW_CAST(Array, FP[rB]);
2879 RawSmi* index = RAW_CAST(Smi, FP[rC]); 2934 RawSmi* index = RAW_CAST(Smi, FP[rC]);
2880 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_)); 2935 ASSERT(SimulatorHelpers::CheckIndex(index, array->ptr()->length_));
2881 FP[rA] = array->ptr()->data()[Smi::Value(index)]; 2936 FP[rA] = array->ptr()->data()[Smi::Value(index)];
2882 DISPATCH(); 2937 DISPATCH();
2883 } 2938 }
2884 2939
2885 { 2940 {
2886 BYTECODE(LoadIndexedUint8, A_B_C); 2941 BYTECODE(LoadIndexedUint8, A_B_C);
2887 ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); 2942 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 0);
2888 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); 2943 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(); 2944 DISPATCH();
2894 } 2945 }
2895 2946
2896 { 2947 {
2897 BYTECODE(LoadIndexedInt8, A_B_C); 2948 BYTECODE(LoadIndexedInt8, A_B_C);
2898 ASSERT(RawObject::IsTypedDataClassId(FP[rB]->GetClassId())); 2949 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 0);
2899 RawTypedData* array = reinterpret_cast<RawTypedData*>(FP[rB]); 2950 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(); 2951 DISPATCH();
2905 } 2952 }
2906 2953
2954 {
2955 BYTECODE(LoadIndexedUint32, A_B_C);
2956 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 2);
2957 FP[rA] = reinterpret_cast<RawObject*>(*reinterpret_cast<uintptr_t*>(data));
2958 DISPATCH();
2959 }
2960
2961 {
2962 BYTECODE(LoadIndexedInt32, A_B_C);
2963 uint8_t* data = SimulatorHelpers::GetTypedData(FP[rB], FP[rC], 2);
2964 FP[rA] = reinterpret_cast<RawObject*>(*reinterpret_cast<intptr_t*>(data));
2965 DISPATCH();
2966 }
2967
2907 { 2968 {
2908 BYTECODE(LoadIndexedExternalUint8, A_B_C); 2969 BYTECODE(LoadIndexedExternalUint8, A_B_C);
2909 uint8_t* data = reinterpret_cast<uint8_t*>(FP[rB]); 2970 uint8_t* data = reinterpret_cast<uint8_t*>(FP[rB]);
2910 RawSmi* index = RAW_CAST(Smi, FP[rC]); 2971 RawSmi* index = RAW_CAST(Smi, FP[rC]);
2911 FP[rA] = Smi::New(data[Smi::Value(index)]); 2972 FP[rA] = Smi::New(data[Smi::Value(index)]);
2912 DISPATCH(); 2973 DISPATCH();
2913 } 2974 }
2914 2975
2915 { 2976 {
2916 BYTECODE(LoadIndexedExternalInt8, A_B_C); 2977 BYTECODE(LoadIndexedExternalInt8, A_B_C);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 pc_ = pc; 3177 pc_ = pc;
3117 special_[kExceptionSpecialIndex] = raw_exception; 3178 special_[kExceptionSpecialIndex] = raw_exception;
3118 special_[kStacktraceSpecialIndex] = raw_stacktrace; 3179 special_[kStacktraceSpecialIndex] = raw_stacktrace;
3119 buf->Longjmp(); 3180 buf->Longjmp();
3120 UNREACHABLE(); 3181 UNREACHABLE();
3121 } 3182 }
3122 3183
3123 } // namespace dart 3184 } // namespace dart
3124 3185
3125 #endif // defined TARGET_ARCH_DBC 3186 #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