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

Side by Side Diff: src/interpreter/bytecodes.h

Issue 1370893002: [Interpreter] Add support for short (16 bit) operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 2 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-traits.h ('k') | src/interpreter/bytecodes.cc » ('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_BYTECODES_H_ 5 #ifndef V8_INTERPRETER_BYTECODES_H_
6 #define V8_INTERPRETER_BYTECODES_H_ 6 #define V8_INTERPRETER_BYTECODES_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 9
10 // Clients of this interface shouldn't depend on lots of interpreter internals. 10 // Clients of this interface shouldn't depend on lots of interpreter internals.
11 // Do not include anything from src/interpreter here! 11 // Do not include anything from src/interpreter here!
12 #include "src/utils.h" 12 #include "src/utils.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 namespace interpreter { 16 namespace interpreter {
17 17
18 // The list of operand types used by bytecodes. 18 // The list of operand types used by bytecodes.
19 #define OPERAND_TYPE_LIST(V) \ 19 #define OPERAND_TYPE_LIST(V) \
20 V(None) \ 20 \
21 V(Count) \ 21 /* None operand. */ \
22 V(Imm8) \ 22 V(None, OperandSize::kNone) \
23 V(Idx) \ 23 \
24 V(Reg) 24 /* Byte operands. */ \
25 V(Count8, OperandSize::kByte) \
26 V(Imm8, OperandSize::kByte) \
27 V(Idx8, OperandSize::kByte) \
28 V(Reg8, OperandSize::kByte) \
29 \
30 /* Short operands. */ \
31 V(Idx16, OperandSize::kShort)
25 32
26 // The list of bytecodes which are interpreted by the interpreter. 33 // The list of bytecodes which are interpreted by the interpreter.
27 #define BYTECODE_LIST(V) \ 34 #define BYTECODE_LIST(V) \
28 \ 35 \
29 /* Loading the accumulator */ \ 36 /* Loading the accumulator */ \
30 V(LdaZero, OperandType::kNone) \ 37 V(LdaZero, OperandType::kNone) \
31 V(LdaSmi8, OperandType::kImm8) \ 38 V(LdaSmi8, OperandType::kImm8) \
32 V(LdaConstant, OperandType::kIdx) \ 39 V(LdaConstant, OperandType::kIdx8) \
33 V(LdaUndefined, OperandType::kNone) \ 40 V(LdaUndefined, OperandType::kNone) \
34 V(LdaNull, OperandType::kNone) \ 41 V(LdaNull, OperandType::kNone) \
35 V(LdaTheHole, OperandType::kNone) \ 42 V(LdaTheHole, OperandType::kNone) \
36 V(LdaTrue, OperandType::kNone) \ 43 V(LdaTrue, OperandType::kNone) \
37 V(LdaFalse, OperandType::kNone) \ 44 V(LdaFalse, OperandType::kNone) \
38 \ 45 \
39 /* Load globals */ \ 46 /* Load globals */ \
40 V(LdaGlobal, OperandType::kIdx) \ 47 V(LdaGlobal, OperandType::kIdx8) \
41 \ 48 \
42 /* Register-accumulator transfers */ \ 49 /* Reg8ister-accumulator transfers */ \
43 V(Ldar, OperandType::kReg) \ 50 V(Ldar, OperandType::kReg8) \
44 V(Star, OperandType::kReg) \ 51 V(Star, OperandType::kReg8) \
45 \ 52 \
46 /* LoadIC operations */ \ 53 /* LoadIC operations */ \
47 V(LoadIC, OperandType::kReg, OperandType::kIdx) \ 54 V(LoadIC, OperandType::kReg8, OperandType::kIdx8) \
48 V(KeyedLoadIC, OperandType::kReg, OperandType::kIdx) \ 55 V(KeyedLoadIC, OperandType::kReg8, OperandType::kIdx8) \
49 \ 56 \
50 /* StoreIC operations */ \ 57 /* StoreIC operations */ \
51 V(StoreIC, OperandType::kReg, OperandType::kReg, OperandType::kIdx) \ 58 V(StoreIC, OperandType::kReg8, OperandType::kReg8, OperandType::kIdx8) \
52 V(KeyedStoreIC, OperandType::kReg, OperandType::kReg, OperandType::kIdx) \ 59 V(KeyedStoreIC, OperandType::kReg8, OperandType::kReg8, OperandType::kIdx8) \
53 \ 60 \
54 /* Binary Operators */ \ 61 /* Binary Operators */ \
55 V(Add, OperandType::kReg) \ 62 V(Add, OperandType::kReg8) \
56 V(Sub, OperandType::kReg) \ 63 V(Sub, OperandType::kReg8) \
57 V(Mul, OperandType::kReg) \ 64 V(Mul, OperandType::kReg8) \
58 V(Div, OperandType::kReg) \ 65 V(Div, OperandType::kReg8) \
59 V(Mod, OperandType::kReg) \ 66 V(Mod, OperandType::kReg8) \
60 \ 67 \
61 /* Call operations. */ \ 68 /* Call operations. */ \
62 V(Call, OperandType::kReg, OperandType::kReg, OperandType::kCount) \ 69 V(Call, OperandType::kReg8, OperandType::kReg8, OperandType::kCount8) \
63 \ 70 \
64 /* Test Operators */ \ 71 /* Test Operators */ \
65 V(TestEqual, OperandType::kReg) \ 72 V(TestEqual, OperandType::kReg8) \
66 V(TestNotEqual, OperandType::kReg) \ 73 V(TestNotEqual, OperandType::kReg8) \
67 V(TestEqualStrict, OperandType::kReg) \ 74 V(TestEqualStrict, OperandType::kReg8) \
68 V(TestNotEqualStrict, OperandType::kReg) \ 75 V(TestNotEqualStrict, OperandType::kReg8) \
69 V(TestLessThan, OperandType::kReg) \ 76 V(TestLessThan, OperandType::kReg8) \
70 V(TestGreaterThan, OperandType::kReg) \ 77 V(TestGreaterThan, OperandType::kReg8) \
71 V(TestLessThanOrEqual, OperandType::kReg) \ 78 V(TestLessThanOrEqual, OperandType::kReg8) \
72 V(TestGreaterThanOrEqual, OperandType::kReg) \ 79 V(TestGreaterThanOrEqual, OperandType::kReg8) \
73 V(TestInstanceOf, OperandType::kReg) \ 80 V(TestInstanceOf, OperandType::kReg8) \
74 V(TestIn, OperandType::kReg) \ 81 V(TestIn, OperandType::kReg8) \
75 \ 82 \
76 /* Cast operators */ \ 83 /* Cast operators */ \
77 V(ToBoolean, OperandType::kNone) \ 84 V(ToBoolean, OperandType::kNone) \
78 \ 85 \
79 /* Control Flow */ \ 86 /* Control Flow */ \
80 V(Jump, OperandType::kImm8) \ 87 V(Jump, OperandType::kImm8) \
81 V(JumpConstant, OperandType::kIdx) \ 88 V(JumpConstant, OperandType::kIdx8) \
82 V(JumpIfTrue, OperandType::kImm8) \ 89 V(JumpIfTrue, OperandType::kImm8) \
83 V(JumpIfTrueConstant, OperandType::kIdx) \ 90 V(JumpIfTrueConstant, OperandType::kIdx8) \
84 V(JumpIfFalse, OperandType::kImm8) \ 91 V(JumpIfFalse, OperandType::kImm8) \
85 V(JumpIfFalseConstant, OperandType::kIdx) \ 92 V(JumpIfFalseConstant, OperandType::kIdx8) \
86 V(Return, OperandType::kNone) 93 V(Return, OperandType::kNone)
87 94
88 95
96 // Enumeration of the size classes of operand types used by bytecodes.
97 enum class OperandSize : uint8_t {
98 kNone = 0,
99 kByte = 1,
100 kShort = 2,
101 };
102
103
89 // Enumeration of operand types used by bytecodes. 104 // Enumeration of operand types used by bytecodes.
90 enum class OperandType : uint8_t { 105 enum class OperandType : uint8_t {
91 #define DECLARE_OPERAND_TYPE(Name) k##Name, 106 #define DECLARE_OPERAND_TYPE(Name, _) k##Name,
92 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) 107 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE)
93 #undef DECLARE_OPERAND_TYPE 108 #undef DECLARE_OPERAND_TYPE
94 #define COUNT_OPERAND_TYPES(x) +1 109 #define COUNT_OPERAND_TYPES(x, _) +1
95 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will 110 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will
96 // evaluate to the same value as the last operand. 111 // evaluate to the same value as the last operand.
97 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES) 112 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES)
98 #undef COUNT_OPERAND_TYPES 113 #undef COUNT_OPERAND_TYPES
99 }; 114 };
100 115
101 116
102 // Enumeration of interpreter bytecodes. 117 // Enumeration of interpreter bytecodes.
103 enum class Bytecode : uint8_t { 118 enum class Bytecode : uint8_t {
104 #define DECLARE_BYTECODE(Name, ...) k##Name, 119 #define DECLARE_BYTECODE(Name, ...) k##Name,
105 BYTECODE_LIST(DECLARE_BYTECODE) 120 BYTECODE_LIST(DECLARE_BYTECODE)
106 #undef DECLARE_BYTECODE 121 #undef DECLARE_BYTECODE
107 #define COUNT_BYTECODE(x, ...) +1 122 #define COUNT_BYTECODE(x, ...) +1
108 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will 123 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will
109 // evaluate to the same value as the last real bytecode. 124 // evaluate to the same value as the last real bytecode.
110 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) 125 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE)
111 #undef COUNT_BYTECODE 126 #undef COUNT_BYTECODE
112 }; 127 };
113 128
114 129
115 // An interpreter register which is located in the function's register file 130 // An interpreter Reg8ister which is located in the function's Reg8ister file
116 // in its stack-frame. Register hold parameters, this, and expression values. 131 // in its stack-frame. Reg8ister hold parameters, this, and expression values.
117 class Register { 132 class Register {
118 public: 133 public:
119 static const int kMaxRegisterIndex = 127; 134 static const int kMaxRegisterIndex = 127;
120 static const int kMinRegisterIndex = -128; 135 static const int kMinRegisterIndex = -128;
121 136
122 Register() : index_(kIllegalIndex) {} 137 Register() : index_(kIllegalIndex) {}
123 138
124 explicit Register(int index) : index_(index) { 139 explicit Register(int index) : index_(index) {
125 DCHECK_LE(index_, kMaxRegisterIndex); 140 DCHECK_LE(index_, kMaxRegisterIndex);
126 DCHECK_GE(index_, kMinRegisterIndex); 141 DCHECK_GE(index_, kMinRegisterIndex);
(...skipping 23 matching lines...) Expand all
150 165
151 166
152 class Bytecodes { 167 class Bytecodes {
153 public: 168 public:
154 // Returns string representation of |bytecode|. 169 // Returns string representation of |bytecode|.
155 static const char* ToString(Bytecode bytecode); 170 static const char* ToString(Bytecode bytecode);
156 171
157 // Returns string representation of |operand_type|. 172 // Returns string representation of |operand_type|.
158 static const char* OperandTypeToString(OperandType operand_type); 173 static const char* OperandTypeToString(OperandType operand_type);
159 174
175 // Returns string representation of |operand_size|.
176 static const char* OperandSizeToString(OperandSize operand_size);
177
160 // Returns byte value of bytecode. 178 // Returns byte value of bytecode.
161 static uint8_t ToByte(Bytecode bytecode); 179 static uint8_t ToByte(Bytecode bytecode);
162 180
163 // Returns bytecode for |value|. 181 // Returns bytecode for |value|.
164 static Bytecode FromByte(uint8_t value); 182 static Bytecode FromByte(uint8_t value);
165 183
166 // Returns the number of operands expected by |bytecode|. 184 // Returns the number of operands expected by |bytecode|.
167 static int NumberOfOperands(Bytecode bytecode); 185 static int NumberOfOperands(Bytecode bytecode);
168 186
169 // Return the i-th operand of |bytecode|. 187 // Return the i-th operand of |bytecode|.
170 static OperandType GetOperandType(Bytecode bytecode, int i); 188 static OperandType GetOperandType(Bytecode bytecode, int i);
171 189
190 // Return the size of the i-th operand of |bytecode|.
191 static OperandSize GetOperandSize(Bytecode bytecode, int i);
192
193 // Returns the offset of the i-th operand of |bytecode| relative to the start
194 // of the bytecode.
195 static int GetOperandOffset(Bytecode bytecode, int i);
196
172 // Returns the size of the bytecode including its operands. 197 // Returns the size of the bytecode including its operands.
173 static int Size(Bytecode bytecode); 198 static int Size(Bytecode bytecode);
174 199
175 // The maximum number of operands across all bytecodes. 200 // Returns the size of |operand|.
176 static int MaximumNumberOfOperands(); 201 static OperandSize SizeOfOperand(OperandType operand);
177
178 // Maximum size of a bytecode and its operands.
179 static int MaximumSize();
180 202
181 // Return true if the bytecode is a jump or a conditional jump taking 203 // Return true if the bytecode is a jump or a conditional jump taking
182 // an immediate byte operand (OperandType::kImm8). 204 // an immediate byte operand (OperandType::kImm8).
183 static bool IsJump(Bytecode bytecode); 205 static bool IsJump(Bytecode bytecode);
184 206
185 // Return true if the bytecode is a jump or conditional jump taking a 207 // Return true if the bytecode is a jump or conditional jump taking a
186 // constant pool entry (OperandType::kIdx). 208 // constant pool entry (OperandType::kIdx).
187 static bool IsJumpConstant(Bytecode bytecode); 209 static bool IsJumpConstant(Bytecode bytecode);
188 210
211 // Converts bytes[0] and bytes[1] to a 16 bit 'short' operand value.
212 static uint16_t ShortOperandFromBytes(const uint8_t* bytes);
213
214 // Converts 16 bit 'short' |operand| into bytes_out[0] and bytes_out[1].
215 static void ShortOperandToBytes(uint16_t operand, uint8_t* bytes_out);
216
189 // Decode a single bytecode and operands to |os|. 217 // Decode a single bytecode and operands to |os|.
190 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, 218 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start,
191 int number_of_parameters); 219 int number_of_parameters);
192 220
193 private: 221 private:
194 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); 222 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes);
195 }; 223 };
196 224
197 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); 225 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode);
198 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); 226 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type);
227 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_type);
199 228
200 } // namespace interpreter 229 } // namespace interpreter
201 } // namespace internal 230 } // namespace internal
202 } // namespace v8 231 } // namespace v8
203 232
204 #endif // V8_INTERPRETER_BYTECODES_H_ 233 #endif // V8_INTERPRETER_BYTECODES_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-traits.h ('k') | src/interpreter/bytecodes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698