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

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: Re-generate golden files. 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
« no previous file with comments | « src/interpreter/bytecode-register-allocator.cc ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <OperandTypeInfo>
20 struct OperandTypeInfoTraits {
21 static const bool kIsScalable = false;
22 static const bool kIsUnsigned = false;
23 static const OperandSize kUnscaledSize = OperandSize::kNone;
24 };
25
26 #define DECLARE_OPERAND_TYPE_INFO(Name, Scalable, Unsigned, BaseSize) \
27 template <> \
28 struct OperandTypeInfoTraits<OperandTypeInfo::k##Name> { \
29 static const bool kIsScalable = Scalable; \
30 static const bool kIsUnsigned = Unsigned; \
31 static const OperandSize kUnscaledSize = BaseSize; \
32 };
33 OPERAND_TYPE_INFO_LIST(DECLARE_OPERAND_TYPE_INFO)
34 #undef DECLARE_OPERAND_TYPE_INFO
35
19 template <OperandType> 36 template <OperandType>
20 struct OperandTraits {}; 37 struct OperandTraits {
38 typedef OperandTypeInfoTraits<OperandTypeInfo::kNone> TypeInfo;
39 };
21 40
22 #define DECLARE_OPERAND_SIZE(Name, Size) \ 41 #define DECLARE_OPERAND_TYPE_TRAITS(Name, InfoType) \
23 template <> \ 42 template <> \
24 struct OperandTraits<OperandType::k##Name> { \ 43 struct OperandTraits<OperandType::k##Name> { \
25 static const OperandSize kSizeType = Size; \ 44 typedef OperandTypeInfoTraits<InfoType> TypeInfo; \
26 static const int kSize = static_cast<int>(Size); \
27 }; 45 };
28 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE) 46 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE_TRAITS)
29 #undef DECLARE_OPERAND_SIZE 47 #undef DECLARE_OPERAND_TYPE_TRAITS
30 48
31 template <OperandType> 49 template <OperandType>
32 struct RegisterOperandTraits { 50 struct RegisterOperandTraits {
33 static const int kIsRegisterOperand = 0; 51 static const int kIsRegisterOperand = 0;
34 }; 52 };
35 53
36 #define DECLARE_REGISTER_OPERAND(Name, _) \ 54 #define DECLARE_REGISTER_OPERAND(Name, _) \
37 template <> \ 55 template <> \
38 struct RegisterOperandTraits<OperandType::k##Name> { \ 56 struct RegisterOperandTraits<OperandType::k##Name> { \
39 static const int kIsRegisterOperand = 1; \ 57 static const int kIsRegisterOperand = 1; \
40 }; 58 };
41 REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND) 59 REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND)
42 #undef DECLARE_REGISTER_OPERAND 60 #undef DECLARE_REGISTER_OPERAND
43 61
44 template <OperandType... Args> 62 template <OperandType... Args>
45 struct BytecodeTraits {}; 63 struct BytecodeTraits {};
46 64
47 template <OperandType operand_0, OperandType operand_1, OperandType operand_2, 65 template <OperandType operand_0, OperandType operand_1, OperandType operand_2,
48 OperandType operand_3> 66 OperandType operand_3>
49 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3, 67 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3,
50 OPERAND_TERM> { 68 OPERAND_TERM> {
51 static OperandType GetOperandType(int i) { 69 static OperandType GetOperandType(int i) {
52 DCHECK(0 <= i && i < kOperandCount); 70 DCHECK(0 <= i && i < kOperandCount);
53 const OperandType kOperands[] = {operand_0, operand_1, operand_2, 71 const OperandType kOperands[] = {operand_0, operand_1, operand_2,
54 operand_3}; 72 operand_3};
55 return kOperands[i]; 73 return kOperands[i];
56 } 74 }
57 75
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> 76 template <OperandType ot>
79 static inline bool HasAnyOperandsOfType() { 77 static inline bool HasAnyOperandsOfType() {
80 return operand_0 == ot || operand_1 == ot || operand_2 == ot || 78 return operand_0 == ot || operand_1 == ot || operand_2 == ot ||
81 operand_3 == ot; 79 operand_3 == ot;
82 } 80 }
83 81
82 static inline bool IsScalable() {
83 return (OperandTraits<operand_0>::TypeInfo::kIsScalable |
84 OperandTraits<operand_1>::TypeInfo::kIsScalable |
85 OperandTraits<operand_2>::TypeInfo::kIsScalable |
86 OperandTraits<operand_3>::TypeInfo::kIsScalable);
87 }
88
84 static const int kOperandCount = 4; 89 static const int kOperandCount = 4;
85 static const int kRegisterOperandCount = 90 static const int kRegisterOperandCount =
86 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 91 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
87 RegisterOperandTraits<operand_1>::kIsRegisterOperand + 92 RegisterOperandTraits<operand_1>::kIsRegisterOperand +
88 RegisterOperandTraits<operand_2>::kIsRegisterOperand + 93 RegisterOperandTraits<operand_2>::kIsRegisterOperand +
89 RegisterOperandTraits<operand_3>::kIsRegisterOperand; 94 RegisterOperandTraits<operand_3>::kIsRegisterOperand;
90 static const int kRegisterOperandBitmap = 95 static const int kRegisterOperandBitmap =
91 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 96 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
92 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + 97 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) +
93 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2) + 98 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2) +
94 (RegisterOperandTraits<operand_3>::kIsRegisterOperand << 3); 99 (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 }; 100 };
99 101
100 template <OperandType operand_0, OperandType operand_1, OperandType operand_2> 102 template <OperandType operand_0, OperandType operand_1, OperandType operand_2>
101 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> { 103 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> {
102 static inline OperandType GetOperandType(int i) { 104 static inline OperandType GetOperandType(int i) {
103 DCHECK(0 <= i && i <= 2); 105 DCHECK(0 <= i && i <= 2);
104 const OperandType kOperands[] = {operand_0, operand_1, operand_2}; 106 const OperandType kOperands[] = {operand_0, operand_1, operand_2};
105 return kOperands[i]; 107 return kOperands[i];
106 } 108 }
107 109
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> 110 template <OperandType ot>
127 static inline bool HasAnyOperandsOfType() { 111 static inline bool HasAnyOperandsOfType() {
128 return operand_0 == ot || operand_1 == ot || operand_2 == ot; 112 return operand_0 == ot || operand_1 == ot || operand_2 == ot;
129 } 113 }
130 114
115 static inline bool IsScalable() {
116 return (OperandTraits<operand_0>::TypeInfo::kIsScalable |
117 OperandTraits<operand_1>::TypeInfo::kIsScalable |
118 OperandTraits<operand_2>::TypeInfo::kIsScalable);
119 }
120
131 static const int kOperandCount = 3; 121 static const int kOperandCount = 3;
132 static const int kRegisterOperandCount = 122 static const int kRegisterOperandCount =
133 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 123 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
134 RegisterOperandTraits<operand_1>::kIsRegisterOperand + 124 RegisterOperandTraits<operand_1>::kIsRegisterOperand +
135 RegisterOperandTraits<operand_2>::kIsRegisterOperand; 125 RegisterOperandTraits<operand_2>::kIsRegisterOperand;
136 static const int kRegisterOperandBitmap = 126 static const int kRegisterOperandBitmap =
137 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 127 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
138 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + 128 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) +
139 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2); 129 (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 }; 130 };
144 131
145 template <OperandType operand_0, OperandType operand_1> 132 template <OperandType operand_0, OperandType operand_1>
146 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> { 133 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> {
147 static inline OperandType GetOperandType(int i) { 134 static inline OperandType GetOperandType(int i) {
148 DCHECK(0 <= i && i < kOperandCount); 135 DCHECK(0 <= i && i < kOperandCount);
149 const OperandType kOperands[] = {operand_0, operand_1}; 136 const OperandType kOperands[] = {operand_0, operand_1};
150 return kOperands[i]; 137 return kOperands[i];
151 } 138 }
152 139
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> 140 template <OperandType ot>
170 static inline bool HasAnyOperandsOfType() { 141 static inline bool HasAnyOperandsOfType() {
171 return operand_0 == ot || operand_1 == ot; 142 return operand_0 == ot || operand_1 == ot;
172 } 143 }
173 144
145 static inline bool IsScalable() {
146 return (OperandTraits<operand_0>::TypeInfo::kIsScalable |
147 OperandTraits<operand_1>::TypeInfo::kIsScalable);
148 }
149
174 static const int kOperandCount = 2; 150 static const int kOperandCount = 2;
175 static const int kRegisterOperandCount = 151 static const int kRegisterOperandCount =
176 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 152 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
177 RegisterOperandTraits<operand_1>::kIsRegisterOperand; 153 RegisterOperandTraits<operand_1>::kIsRegisterOperand;
178 static const int kRegisterOperandBitmap = 154 static const int kRegisterOperandBitmap =
179 RegisterOperandTraits<operand_0>::kIsRegisterOperand + 155 RegisterOperandTraits<operand_0>::kIsRegisterOperand +
180 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1); 156 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1);
181 static const int kSize =
182 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize;
183 }; 157 };
184 158
185 template <OperandType operand_0> 159 template <OperandType operand_0>
186 struct BytecodeTraits<operand_0, OPERAND_TERM> { 160 struct BytecodeTraits<operand_0, OPERAND_TERM> {
187 static inline OperandType GetOperandType(int i) { 161 static inline OperandType GetOperandType(int i) {
188 DCHECK(i == 0); 162 DCHECK(i == 0);
189 return operand_0; 163 return operand_0;
190 } 164 }
191 165
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> 166 template <OperandType ot>
203 static inline bool HasAnyOperandsOfType() { 167 static inline bool HasAnyOperandsOfType() {
204 return operand_0 == ot; 168 return operand_0 == ot;
205 } 169 }
206 170
171 static inline bool IsScalable() {
172 return OperandTraits<operand_0>::TypeInfo::kIsScalable;
173 }
174
207 static const int kOperandCount = 1; 175 static const int kOperandCount = 1;
208 static const int kRegisterOperandCount = 176 static const int kRegisterOperandCount =
209 RegisterOperandTraits<operand_0>::kIsRegisterOperand; 177 RegisterOperandTraits<operand_0>::kIsRegisterOperand;
210 static const int kRegisterOperandBitmap = 178 static const int kRegisterOperandBitmap =
211 RegisterOperandTraits<operand_0>::kIsRegisterOperand; 179 RegisterOperandTraits<operand_0>::kIsRegisterOperand;
212 static const int kSize = 1 + OperandTraits<operand_0>::kSize;
213 }; 180 };
214 181
215 template <> 182 template <>
216 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> { 183 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> {
217 static inline OperandType GetOperandType(int i) { 184 static inline OperandType GetOperandType(int i) {
218 UNREACHABLE(); 185 UNREACHABLE();
219 return OperandType::kNone; 186 return OperandType::kNone;
220 } 187 }
221 188
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> 189 template <OperandType ot>
233 static inline bool HasAnyOperandsOfType() { 190 static inline bool HasAnyOperandsOfType() {
234 return false; 191 return false;
235 } 192 }
236 193
194 static inline bool IsScalable() { return false; }
195
237 static const int kOperandCount = 0; 196 static const int kOperandCount = 0;
238 static const int kRegisterOperandCount = 0; 197 static const int kRegisterOperandCount = 0;
239 static const int kRegisterOperandBitmap = 0; 198 static const int kRegisterOperandBitmap = 0;
240 static const int kSize = 1 + OperandTraits<OperandType::kNone>::kSize;
241 }; 199 };
242 200
201 template <bool>
202 struct OperandScaler {
203 static int Multiply(int size, int operand_scale) { return 0; }
204 };
205
206 template <>
207 struct OperandScaler<false> {
208 static int Multiply(int size, int operand_scale) { return size; }
209 };
210
211 template <>
212 struct OperandScaler<true> {
213 static int Multiply(int size, int operand_scale) {
214 return size * operand_scale;
215 }
216 };
217
218 static OperandSize ScaledOperandSize(OperandType operand_type,
219 OperandScale operand_scale) {
220 switch (operand_type) {
221 #define CASE(Name, TypeInfo) \
222 case OperandType::k##Name: { \
223 OperandSize base_size = OperandTypeInfoTraits<TypeInfo>::kUnscaledSize; \
224 int size = \
225 OperandScaler<OperandTypeInfoTraits<TypeInfo>::kIsScalable>::Multiply( \
226 static_cast<int>(base_size), static_cast<int>(operand_scale)); \
227 OperandSize operand_size = static_cast<OperandSize>(size); \
228 DCHECK(operand_size == OperandSize::kByte || \
229 operand_size == OperandSize::kShort || \
230 operand_size == OperandSize::kQuad); \
231 return operand_size; \
232 }
233 OPERAND_TYPE_LIST(CASE)
234 #undef CASE
235 }
236 UNREACHABLE();
237 return OperandSize::kNone;
238 }
239
243 } // namespace interpreter 240 } // namespace interpreter
244 } // namespace internal 241 } // namespace internal
245 } // namespace v8 242 } // namespace v8
246 243
247 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_ 244 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-register-allocator.cc ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698