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

Side by Side Diff: src/interpreter/bytecode-traits.h

Issue 1613163002: [interpreter] Wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added tests, fixed off-by-one error in register indicies. Created 4 years, 11 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_INTERPRETER_BYTECODE_TRAITS_H_ 5 #ifndef V8_INTERPRETER_BYTECODE_TRAITS_H_
6 #define V8_INTERPRETER_BYTECODE_TRAITS_H_ 6 #define V8_INTERPRETER_BYTECODE_TRAITS_H_
7 7
8 #include "src/interpreter/bytecodes.h" 8 #include "src/interpreter/bytecodes.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 10 matching lines...) Expand all
21 21
22 #define DECLARE_OPERAND_SIZE(Name, Size) \ 22 #define DECLARE_OPERAND_SIZE(Name, Size) \
23 template <> \ 23 template <> \
24 struct OperandTraits<OperandType::k##Name> { \ 24 struct OperandTraits<OperandType::k##Name> { \
25 static const OperandSize kSizeType = Size; \ 25 static const OperandSize kSizeType = Size; \
26 static const int kSize = static_cast<int>(Size); \ 26 static const int kSize = static_cast<int>(Size); \
27 }; 27 };
28 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE) 28 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE)
29 #undef DECLARE_OPERAND_SIZE 29 #undef DECLARE_OPERAND_SIZE
30 30
31 template <OperandType>
32 struct RegisterOperandTraits {
33 static const int kIsRegisterOperand = 0;
34 };
35
36 #define DECLARE_REGISTER_OPERAND(Name, _) \
37 template <> \
38 struct RegisterOperandTraits<OperandType::k##Name> { \
39 static const int kIsRegisterOperand = 1; \
40 };
41 REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND)
42 #undef DECLARE_REGISTER_OPERAND
31 43
32 template <OperandType... Args> 44 template <OperandType... Args>
33 struct BytecodeTraits {}; 45 struct BytecodeTraits {};
34 46
35 template <OperandType operand_0, OperandType operand_1, OperandType operand_2, 47 template <OperandType operand_0, OperandType operand_1, OperandType operand_2,
36 OperandType operand_3> 48 OperandType operand_3>
37 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3, 49 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3,
38 OPERAND_TERM> { 50 OPERAND_TERM> {
39 static OperandType GetOperandType(int i) { 51 static OperandType GetOperandType(int i) {
40 DCHECK(0 <= i && i < kOperandCount); 52 DCHECK(0 <= i && i < kOperandCount);
(...skipping 15 matching lines...) Expand all
56 static inline int GetOperandOffset(int i) { 68 static inline int GetOperandOffset(int i) {
57 DCHECK(0 <= i && i < kOperandCount); 69 DCHECK(0 <= i && i < kOperandCount);
58 const int kOffset0 = 1; 70 const int kOffset0 = 1;
59 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; 71 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize;
60 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize; 72 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize;
61 const int kOffset3 = kOffset2 + OperandTraits<operand_2>::kSize; 73 const int kOffset3 = kOffset2 + OperandTraits<operand_2>::kSize;
62 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2, kOffset3}; 74 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2, kOffset3};
63 return kOperandOffsets[i]; 75 return kOperandOffsets[i];
64 } 76 }
65 77
78 template <OperandType ot>
79 static inline bool HasAnyOperandsOfType() {
80 return operand_0 == ot || operand_1 == ot || operand_2 == ot ||
81 operand_3 == ot;
82 }
83
66 static const int kOperandCount = 4; 84 static const int kOperandCount = 4;
85 static const int kRegisterOperandCount =
86 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
87 RegisterOperandTraits<operand_1>::kIsRegisterOperand +
88 RegisterOperandTraits<operand_2>::kIsRegisterOperand +
89 RegisterOperandTraits<operand_3>::kIsRegisterOperand;
67 static const int kSize = 90 static const int kSize =
68 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize + 91 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize +
69 OperandTraits<operand_2>::kSize + OperandTraits<operand_3>::kSize; 92 OperandTraits<operand_2>::kSize + OperandTraits<operand_3>::kSize;
70 }; 93 };
71 94
72
73 template <OperandType operand_0, OperandType operand_1, OperandType operand_2> 95 template <OperandType operand_0, OperandType operand_1, OperandType operand_2>
74 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> { 96 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> {
75 static inline OperandType GetOperandType(int i) { 97 static inline OperandType GetOperandType(int i) {
76 DCHECK(0 <= i && i <= 2); 98 DCHECK(0 <= i && i <= 2);
77 const OperandType kOperands[] = {operand_0, operand_1, operand_2}; 99 const OperandType kOperands[] = {operand_0, operand_1, operand_2};
78 return kOperands[i]; 100 return kOperands[i];
79 } 101 }
80 102
81 static inline OperandSize GetOperandSize(int i) { 103 static inline OperandSize GetOperandSize(int i) {
82 DCHECK(0 <= i && i < kOperandCount); 104 DCHECK(0 <= i && i < kOperandCount);
83 const OperandSize kOperandSizes[] = 105 const OperandSize kOperandSizes[] =
84 {OperandTraits<operand_0>::kSizeType, 106 {OperandTraits<operand_0>::kSizeType,
85 OperandTraits<operand_1>::kSizeType, 107 OperandTraits<operand_1>::kSizeType,
86 OperandTraits<operand_2>::kSizeType}; 108 OperandTraits<operand_2>::kSizeType};
87 return kOperandSizes[i]; 109 return kOperandSizes[i];
88 } 110 }
89 111
90 static inline int GetOperandOffset(int i) { 112 static inline int GetOperandOffset(int i) {
91 DCHECK(0 <= i && i < kOperandCount); 113 DCHECK(0 <= i && i < kOperandCount);
92 const int kOffset0 = 1; 114 const int kOffset0 = 1;
93 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; 115 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize;
94 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize; 116 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize;
95 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2}; 117 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2};
96 return kOperandOffsets[i]; 118 return kOperandOffsets[i];
97 } 119 }
98 120
121 template <OperandType ot>
122 static inline bool HasAnyOperandsOfType() {
123 return operand_0 == ot || operand_1 == ot || operand_2 == ot;
124 }
125
99 static const int kOperandCount = 3; 126 static const int kOperandCount = 3;
127 static const int kRegisterOperandCount =
128 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
129 RegisterOperandTraits<operand_1>::kIsRegisterOperand +
130 RegisterOperandTraits<operand_2>::kIsRegisterOperand;
100 static const int kSize = 131 static const int kSize =
101 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize + 132 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize +
102 OperandTraits<operand_2>::kSize; 133 OperandTraits<operand_2>::kSize;
103 }; 134 };
104 135
105 template <OperandType operand_0, OperandType operand_1> 136 template <OperandType operand_0, OperandType operand_1>
106 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> { 137 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> {
107 static inline OperandType GetOperandType(int i) { 138 static inline OperandType GetOperandType(int i) {
108 DCHECK(0 <= i && i < kOperandCount); 139 DCHECK(0 <= i && i < kOperandCount);
109 const OperandType kOperands[] = {operand_0, operand_1}; 140 const OperandType kOperands[] = {operand_0, operand_1};
110 return kOperands[i]; 141 return kOperands[i];
111 } 142 }
112 143
113 static inline OperandSize GetOperandSize(int i) { 144 static inline OperandSize GetOperandSize(int i) {
114 DCHECK(0 <= i && i < kOperandCount); 145 DCHECK(0 <= i && i < kOperandCount);
115 const OperandSize kOperandSizes[] = 146 const OperandSize kOperandSizes[] =
116 {OperandTraits<operand_0>::kSizeType, 147 {OperandTraits<operand_0>::kSizeType,
117 OperandTraits<operand_1>::kSizeType}; 148 OperandTraits<operand_1>::kSizeType};
118 return kOperandSizes[i]; 149 return kOperandSizes[i];
119 } 150 }
120 151
121 static inline int GetOperandOffset(int i) { 152 static inline int GetOperandOffset(int i) {
122 DCHECK(0 <= i && i < kOperandCount); 153 DCHECK(0 <= i && i < kOperandCount);
123 const int kOffset0 = 1; 154 const int kOffset0 = 1;
124 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; 155 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize;
125 const int kOperandOffsets[] = {kOffset0, kOffset1}; 156 const int kOperandOffsets[] = {kOffset0, kOffset1};
126 return kOperandOffsets[i]; 157 return kOperandOffsets[i];
127 } 158 }
128 159
160 template <OperandType ot>
161 static inline bool HasAnyOperandsOfType() {
162 return operand_0 == ot || operand_1 == ot;
163 }
164
129 static const int kOperandCount = 2; 165 static const int kOperandCount = 2;
166 static const int kRegisterOperandCount =
167 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
168 RegisterOperandTraits<operand_1>::kIsRegisterOperand;
130 static const int kSize = 169 static const int kSize =
131 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize; 170 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize;
132 }; 171 };
133 172
134 template <OperandType operand_0> 173 template <OperandType operand_0>
135 struct BytecodeTraits<operand_0, OPERAND_TERM> { 174 struct BytecodeTraits<operand_0, OPERAND_TERM> {
136 static inline OperandType GetOperandType(int i) { 175 static inline OperandType GetOperandType(int i) {
137 DCHECK(i == 0); 176 DCHECK(i == 0);
138 return operand_0; 177 return operand_0;
139 } 178 }
140 179
141 static inline OperandSize GetOperandSize(int i) { 180 static inline OperandSize GetOperandSize(int i) {
142 DCHECK(i == 0); 181 DCHECK(i == 0);
143 return OperandTraits<operand_0>::kSizeType; 182 return OperandTraits<operand_0>::kSizeType;
144 } 183 }
145 184
146 static inline int GetOperandOffset(int i) { 185 static inline int GetOperandOffset(int i) {
147 DCHECK(i == 0); 186 DCHECK(i == 0);
148 return 1; 187 return 1;
149 } 188 }
150 189
190 template <OperandType ot>
191 static inline bool HasAnyOperandsOfType() {
192 return operand_0 == ot;
193 }
194
151 static const int kOperandCount = 1; 195 static const int kOperandCount = 1;
196 static const int kRegisterOperandCount =
197 RegisterOperandTraits<operand_0>::kIsRegisterOperand;
152 static const int kSize = 1 + OperandTraits<operand_0>::kSize; 198 static const int kSize = 1 + OperandTraits<operand_0>::kSize;
153 }; 199 };
154 200
155 template <> 201 template <>
156 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> { 202 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> {
157 static inline OperandType GetOperandType(int i) { 203 static inline OperandType GetOperandType(int i) {
158 UNREACHABLE(); 204 UNREACHABLE();
159 return OperandType::kNone; 205 return OperandType::kNone;
160 } 206 }
161 207
162 static inline OperandSize GetOperandSize(int i) { 208 static inline OperandSize GetOperandSize(int i) {
163 UNREACHABLE(); 209 UNREACHABLE();
164 return OperandSize::kNone; 210 return OperandSize::kNone;
165 } 211 }
166 212
167 static inline int GetOperandOffset(int i) { 213 static inline int GetOperandOffset(int i) {
168 UNREACHABLE(); 214 UNREACHABLE();
169 return 1; 215 return 1;
170 } 216 }
171 217
218 template <OperandType ot>
219 static inline bool HasAnyOperandsOfType() {
220 return false;
221 }
222
172 static const int kOperandCount = 0; 223 static const int kOperandCount = 0;
224 static const int kRegisterOperandCount = 0;
173 static const int kSize = 1 + OperandTraits<OperandType::kNone>::kSize; 225 static const int kSize = 1 + OperandTraits<OperandType::kNone>::kSize;
174 }; 226 };
175 227
176 } // namespace interpreter 228 } // namespace interpreter
177 } // namespace internal 229 } // namespace internal
178 } // namespace v8 230 } // namespace v8
179 231
180 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_ 232 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698