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

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

Issue 1783483002: [interpreter] Add support for scalable operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Operand renaming. Created 4 years, 9 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 {
11 namespace internal { 11 namespace internal {
12 namespace interpreter { 12 namespace interpreter {
13 13
14 // TODO(rmcilroy): consider simplifying this to avoid the template magic. 14 // TODO(rmcilroy): consider simplifying this to avoid the template magic.
15 15
16 // Template helpers to deduce the number of operands each bytecode has. 16 // Template helpers to deduce the number of operands each bytecode has.
17 #define OPERAND_TERM OperandType::kNone, OperandType::kNone, OperandType::kNone 17 #define OPERAND_TERM OperandType::kNone, OperandType::kNone, OperandType::kNone
18 18
19 template <OperandTypeTrait t>
20 struct OperandTypeInfo {
21 static const bool IsScalable = false;
22 };
23
24 template <>
25 struct OperandTypeInfo<OperandTypeTrait::kScalable> {
26 static const bool IsScalable = true;
27 };
28
19 template <OperandType> 29 template <OperandType>
20 struct OperandTraits {}; 30 struct OperandTraits {};
21 31
22 #define DECLARE_OPERAND_SIZE(Name, Size) \ 32 #define DECLARE_OPERAND_SIZE(Name, Size, TypeTrait) \
23 template <> \ 33 template <> \
24 struct OperandTraits<OperandType::k##Name> { \ 34 struct OperandTraits<OperandType::k##Name> { \
25 static const OperandSize kSizeType = Size; \ 35 static const OperandSize kSizeType = Size; \
26 static const int kSize = static_cast<int>(Size); \ 36 static const int kSize = static_cast<int>(Size); \
37 static const bool kScalable = OperandTypeInfo<TypeTrait>::IsScalable; \
27 }; 38 };
28 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE) 39 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE)
29 #undef DECLARE_OPERAND_SIZE 40 #undef DECLARE_OPERAND_SIZE
30 41
31 template <OperandType> 42 template <OperandType>
32 struct RegisterOperandTraits { 43 struct RegisterOperandTraits {
33 static const int kIsRegisterOperand = 0; 44 static const int kIsRegisterOperand = 0;
34 }; 45 };
35 46
36 #define DECLARE_REGISTER_OPERAND(Name, _) \ 47 #define DECLARE_REGISTER_OPERAND(Name, _, __) \
37 template <> \ 48 template <> \
38 struct RegisterOperandTraits<OperandType::k##Name> { \ 49 struct RegisterOperandTraits<OperandType::k##Name> { \
39 static const int kIsRegisterOperand = 1; \ 50 static const int kIsRegisterOperand = 1; \
40 }; 51 };
41 REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND) 52 REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND)
42 #undef DECLARE_REGISTER_OPERAND 53 #undef DECLARE_REGISTER_OPERAND
43 54
44 template <OperandType... Args> 55 template <OperandType... Args>
45 struct BytecodeTraits {}; 56 struct BytecodeTraits {};
46 57
47 template <OperandType operand_0, OperandType operand_1, OperandType operand_2, 58 template <OperandType operand_0, OperandType operand_1, OperandType operand_2,
48 OperandType operand_3> 59 OperandType operand_3>
49 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3, 60 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3,
50 OPERAND_TERM> { 61 OPERAND_TERM> {
51 static OperandType GetOperandType(int i) { 62 static OperandType GetOperandType(int i) {
52 DCHECK(0 <= i && i < kOperandCount); 63 DCHECK(0 <= i && i < kOperandCount);
53 const OperandType kOperands[] = {operand_0, operand_1, operand_2, 64 const OperandType kOperands[] = {operand_0, operand_1, operand_2,
54 operand_3}; 65 operand_3};
55 return kOperands[i]; 66 return kOperands[i];
56 } 67 }
57 68
58 static inline OperandSize GetOperandSize(int i) {
59 DCHECK(0 <= i && i < kOperandCount);
60 const OperandSize kOperandSizes[] =
61 {OperandTraits<operand_0>::kSizeType,
62 OperandTraits<operand_1>::kSizeType,
63 OperandTraits<operand_2>::kSizeType,
64 OperandTraits<operand_3>::kSizeType};
65 return kOperandSizes[i];
66 }
67
68 static inline int GetOperandOffset(int i) {
69 DCHECK(0 <= i && i < kOperandCount);
70 const int kOffset0 = 1;
71 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize;
72 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize;
73 const int kOffset3 = kOffset2 + OperandTraits<operand_2>::kSize;
74 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2, kOffset3};
75 return kOperandOffsets[i];
76 }
77
78 template <OperandType ot> 69 template <OperandType ot>
79 static inline bool HasAnyOperandsOfType() { 70 static inline bool HasAnyOperandsOfType() {
80 return operand_0 == ot || operand_1 == ot || operand_2 == ot || 71 return operand_0 == ot || operand_1 == ot || operand_2 == ot ||
81 operand_3 == ot; 72 operand_3 == ot;
82 } 73 }
83 74
75 static inline bool IsScalable() {
76 return (OperandTraits<operand_0>::kScalable |
77 OperandTraits<operand_1>::kScalable |
78 OperandTraits<operand_2>::kScalable |
79 OperandTraits<operand_3>::kScalable);
80 }
81
84 static const int kOperandCount = 4; 82 static const int kOperandCount = 4;
85 static const int kRegisterOperandCount = 83 static const int kRegisterOperandCount =
86 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 84 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
87 RegisterOperandTraits<operand_1>::kIsRegisterOperand + 85 RegisterOperandTraits<operand_1>::kIsRegisterOperand +
88 RegisterOperandTraits<operand_2>::kIsRegisterOperand + 86 RegisterOperandTraits<operand_2>::kIsRegisterOperand +
89 RegisterOperandTraits<operand_3>::kIsRegisterOperand; 87 RegisterOperandTraits<operand_3>::kIsRegisterOperand;
90 static const int kRegisterOperandBitmap = 88 static const int kRegisterOperandBitmap =
91 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 89 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
92 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + 90 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) +
93 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2) + 91 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2) +
94 (RegisterOperandTraits<operand_3>::kIsRegisterOperand << 3); 92 (RegisterOperandTraits<operand_3>::kIsRegisterOperand << 3);
95 static const int kSize =
96 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize +
97 OperandTraits<operand_2>::kSize + OperandTraits<operand_3>::kSize;
98 }; 93 };
99 94
100 template <OperandType operand_0, OperandType operand_1, OperandType operand_2> 95 template <OperandType operand_0, OperandType operand_1, OperandType operand_2>
101 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> { 96 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> {
102 static inline OperandType GetOperandType(int i) { 97 static inline OperandType GetOperandType(int i) {
103 DCHECK(0 <= i && i <= 2); 98 DCHECK(0 <= i && i <= 2);
104 const OperandType kOperands[] = {operand_0, operand_1, operand_2}; 99 const OperandType kOperands[] = {operand_0, operand_1, operand_2};
105 return kOperands[i]; 100 return kOperands[i];
106 } 101 }
107 102
108 static inline OperandSize GetOperandSize(int i) {
109 DCHECK(0 <= i && i < kOperandCount);
110 const OperandSize kOperandSizes[] =
111 {OperandTraits<operand_0>::kSizeType,
112 OperandTraits<operand_1>::kSizeType,
113 OperandTraits<operand_2>::kSizeType};
114 return kOperandSizes[i];
115 }
116
117 static inline int GetOperandOffset(int i) {
118 DCHECK(0 <= i && i < kOperandCount);
119 const int kOffset0 = 1;
120 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize;
121 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize;
122 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2};
123 return kOperandOffsets[i];
124 }
125
126 template <OperandType ot> 103 template <OperandType ot>
127 static inline bool HasAnyOperandsOfType() { 104 static inline bool HasAnyOperandsOfType() {
128 return operand_0 == ot || operand_1 == ot || operand_2 == ot; 105 return operand_0 == ot || operand_1 == ot || operand_2 == ot;
129 } 106 }
130 107
108 static inline bool IsScalable() {
109 return (OperandTraits<operand_0>::kScalable |
110 OperandTraits<operand_1>::kScalable |
111 OperandTraits<operand_2>::kScalable);
112 }
113
131 static const int kOperandCount = 3; 114 static const int kOperandCount = 3;
132 static const int kRegisterOperandCount = 115 static const int kRegisterOperandCount =
133 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 116 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
134 RegisterOperandTraits<operand_1>::kIsRegisterOperand + 117 RegisterOperandTraits<operand_1>::kIsRegisterOperand +
135 RegisterOperandTraits<operand_2>::kIsRegisterOperand; 118 RegisterOperandTraits<operand_2>::kIsRegisterOperand;
136 static const int kRegisterOperandBitmap = 119 static const int kRegisterOperandBitmap =
137 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 120 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
138 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + 121 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) +
139 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2); 122 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2);
140 static const int kSize =
141 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize +
142 OperandTraits<operand_2>::kSize;
143 }; 123 };
144 124
145 template <OperandType operand_0, OperandType operand_1> 125 template <OperandType operand_0, OperandType operand_1>
146 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> { 126 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> {
147 static inline OperandType GetOperandType(int i) { 127 static inline OperandType GetOperandType(int i) {
148 DCHECK(0 <= i && i < kOperandCount); 128 DCHECK(0 <= i && i < kOperandCount);
149 const OperandType kOperands[] = {operand_0, operand_1}; 129 const OperandType kOperands[] = {operand_0, operand_1};
150 return kOperands[i]; 130 return kOperands[i];
151 } 131 }
152 132
153 static inline OperandSize GetOperandSize(int i) {
154 DCHECK(0 <= i && i < kOperandCount);
155 const OperandSize kOperandSizes[] =
156 {OperandTraits<operand_0>::kSizeType,
157 OperandTraits<operand_1>::kSizeType};
158 return kOperandSizes[i];
159 }
160
161 static inline int GetOperandOffset(int i) {
162 DCHECK(0 <= i && i < kOperandCount);
163 const int kOffset0 = 1;
164 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize;
165 const int kOperandOffsets[] = {kOffset0, kOffset1};
166 return kOperandOffsets[i];
167 }
168
169 template <OperandType ot> 133 template <OperandType ot>
170 static inline bool HasAnyOperandsOfType() { 134 static inline bool HasAnyOperandsOfType() {
171 return operand_0 == ot || operand_1 == ot; 135 return operand_0 == ot || operand_1 == ot;
172 } 136 }
173 137
138 static inline bool IsScalable() {
139 return (OperandTraits<operand_0>::kScalable |
140 OperandTraits<operand_1>::kScalable);
141 }
142
174 static const int kOperandCount = 2; 143 static const int kOperandCount = 2;
175 static const int kRegisterOperandCount = 144 static const int kRegisterOperandCount =
176 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 145 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
177 RegisterOperandTraits<operand_1>::kIsRegisterOperand; 146 RegisterOperandTraits<operand_1>::kIsRegisterOperand;
178 static const int kRegisterOperandBitmap = 147 static const int kRegisterOperandBitmap =
179 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 148 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
180 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1); 149 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1);
181 static const int kSize =
182 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize;
183 }; 150 };
184 151
185 template <OperandType operand_0> 152 template <OperandType operand_0>
186 struct BytecodeTraits<operand_0, OPERAND_TERM> { 153 struct BytecodeTraits<operand_0, OPERAND_TERM> {
187 static inline OperandType GetOperandType(int i) { 154 static inline OperandType GetOperandType(int i) {
188 DCHECK(i == 0); 155 DCHECK(i == 0);
189 return operand_0; 156 return operand_0;
190 } 157 }
191 158
192 static inline OperandSize GetOperandSize(int i) {
193 DCHECK(i == 0);
194 return OperandTraits<operand_0>::kSizeType;
195 }
196
197 static inline int GetOperandOffset(int i) {
198 DCHECK(i == 0);
199 return 1;
200 }
201
202 template <OperandType ot> 159 template <OperandType ot>
203 static inline bool HasAnyOperandsOfType() { 160 static inline bool HasAnyOperandsOfType() {
204 return operand_0 == ot; 161 return operand_0 == ot;
205 } 162 }
206 163
164 static inline bool IsScalable() {
165 return OperandTraits<operand_0>::kScalable;
166 }
167
207 static const int kOperandCount = 1; 168 static const int kOperandCount = 1;
208 static const int kRegisterOperandCount = 169 static const int kRegisterOperandCount =
209 RegisterOperandTraits<operand_0>::kIsRegisterOperand; 170 RegisterOperandTraits<operand_0>::kIsRegisterOperand;
210 static const int kRegisterOperandBitmap = 171 static const int kRegisterOperandBitmap =
211 RegisterOperandTraits<operand_0>::kIsRegisterOperand; 172 RegisterOperandTraits<operand_0>::kIsRegisterOperand;
212 static const int kSize = 1 + OperandTraits<operand_0>::kSize;
213 }; 173 };
214 174
215 template <> 175 template <>
216 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> { 176 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> {
217 static inline OperandType GetOperandType(int i) { 177 static inline OperandType GetOperandType(int i) {
218 UNREACHABLE(); 178 UNREACHABLE();
219 return OperandType::kNone; 179 return OperandType::kNone;
220 } 180 }
221 181
222 static inline OperandSize GetOperandSize(int i) {
223 UNREACHABLE();
224 return OperandSize::kNone;
225 }
226
227 static inline int GetOperandOffset(int i) {
228 UNREACHABLE();
229 return 1;
230 }
231
232 template <OperandType ot> 182 template <OperandType ot>
233 static inline bool HasAnyOperandsOfType() { 183 static inline bool HasAnyOperandsOfType() {
234 return false; 184 return false;
235 } 185 }
236 186
187 static inline bool IsScalable() { return false; }
188
237 static const int kOperandCount = 0; 189 static const int kOperandCount = 0;
238 static const int kRegisterOperandCount = 0; 190 static const int kRegisterOperandCount = 0;
239 static const int kRegisterOperandBitmap = 0; 191 static const int kRegisterOperandBitmap = 0;
240 static const int kSize = 1 + OperandTraits<OperandType::kNone>::kSize;
241 }; 192 };
242 193
243 } // namespace interpreter 194 } // namespace interpreter
244 } // namespace internal 195 } // namespace internal
245 } // namespace v8 196 } // namespace v8
246 197
247 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_ 198 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698