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

Side by Side Diff: src/interpreter/bytecode-array-iterator.cc

Issue 1783483002: [interpreter] Add support for scalable operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Additional test for debugger stepping and wider constant array builder test. 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 #include "src/interpreter/bytecode-array-iterator.h" 5 #include "src/interpreter/bytecode-array-iterator.h"
6 6
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 namespace interpreter { 11 namespace interpreter {
12 12
13 BytecodeArrayIterator::BytecodeArrayIterator( 13 BytecodeArrayIterator::BytecodeArrayIterator(
14 Handle<BytecodeArray> bytecode_array) 14 Handle<BytecodeArray> bytecode_array)
15 : bytecode_array_(bytecode_array), bytecode_offset_(0) {} 15 : bytecode_array_(bytecode_array),
16 16 bytecode_offset_(0),
17 operand_scale_(OperandScale::k1X),
18 prefix_offset_(0) {
19 update_operand_scale();
20 }
17 21
18 void BytecodeArrayIterator::Advance() { 22 void BytecodeArrayIterator::Advance() {
19 bytecode_offset_ += Bytecodes::Size(current_bytecode()); 23 bytecode_offset_ += current_bytecode_size();
24 update_operand_scale();
20 } 25 }
21 26
27 void BytecodeArrayIterator::update_operand_scale() {
28 if (!done()) {
29 uint8_t current_byte = bytecode_array()->get(bytecode_offset_);
30 Bytecode current_bytecode = Bytecodes::FromByte(current_byte);
31 if (Bytecodes::IsPrefixScalingBytecode(current_bytecode)) {
32 operand_scale_ =
33 Bytecodes::PrefixBytecodeToOperandScale(current_bytecode);
34 prefix_offset_ = 1;
35 } else {
36 operand_scale_ = OperandScale::k1X;
37 prefix_offset_ = 0;
38 }
39 }
40 }
22 41
23 bool BytecodeArrayIterator::done() const { 42 bool BytecodeArrayIterator::done() const {
24 return bytecode_offset_ >= bytecode_array()->length(); 43 return bytecode_offset_ >= bytecode_array()->length();
25 } 44 }
26 45
27
28 Bytecode BytecodeArrayIterator::current_bytecode() const { 46 Bytecode BytecodeArrayIterator::current_bytecode() const {
29 DCHECK(!done()); 47 DCHECK(!done());
30 uint8_t current_byte = bytecode_array()->get(bytecode_offset_); 48 uint8_t current_byte =
31 return interpreter::Bytecodes::FromByte(current_byte); 49 bytecode_array()->get(bytecode_offset_ + current_prefix_offset());
50 Bytecode current_bytecode = Bytecodes::FromByte(current_byte);
51 DCHECK(!Bytecodes::IsPrefixScalingBytecode(current_bytecode));
52 return current_bytecode;
32 } 53 }
33 54
34
35 int BytecodeArrayIterator::current_bytecode_size() const { 55 int BytecodeArrayIterator::current_bytecode_size() const {
36 return Bytecodes::Size(current_bytecode()); 56 return current_prefix_offset() +
57 Bytecodes::Size(current_bytecode(), current_operand_scale());
37 } 58 }
38 59
39 60 uint32_t BytecodeArrayIterator::GetUnsignedOperand(
40 uint32_t BytecodeArrayIterator::GetRawOperand(int operand_index, 61 int operand_index, OperandType operand_type) const {
41 OperandType operand_type) const {
42 DCHECK_GE(operand_index, 0); 62 DCHECK_GE(operand_index, 0);
43 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode())); 63 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode()));
44 DCHECK_EQ(operand_type, 64 DCHECK_EQ(operand_type,
45 Bytecodes::GetOperandType(current_bytecode(), operand_index)); 65 Bytecodes::GetOperandType(current_bytecode(), operand_index));
66 DCHECK(Bytecodes::IsUnsignedOperandType(operand_type));
46 uint8_t* operand_start = 67 uint8_t* operand_start =
47 bytecode_array()->GetFirstBytecodeAddress() + bytecode_offset_ + 68 bytecode_array()->GetFirstBytecodeAddress() + bytecode_offset_ +
48 Bytecodes::GetOperandOffset(current_bytecode(), operand_index); 69 current_prefix_offset() +
49 switch (Bytecodes::SizeOfOperand(operand_type)) { 70 Bytecodes::GetOperandOffset(current_bytecode(), operand_index,
71 current_operand_scale());
72 switch (Bytecodes::SizeOfOperand(operand_type, current_operand_scale())) {
rmcilroy 2016/03/17 17:30:49 I think you could use DecodeUnsignedOperand here t
oth 2016/03/21 09:16:53 Done.
50 case OperandSize::kByte: 73 case OperandSize::kByte:
51 return static_cast<uint32_t>(*operand_start); 74 return static_cast<uint32_t>(*operand_start);
52 case OperandSize::kShort: 75 case OperandSize::kShort:
53 return ReadUnalignedUInt16(operand_start); 76 return ReadUnalignedUInt16(operand_start);
77 case OperandSize::kQuad:
78 return ReadUnalignedUInt32(operand_start);
54 case OperandSize::kNone: 79 case OperandSize::kNone:
55 UNREACHABLE(); 80 UNREACHABLE();
56 } 81 }
57 return 0; 82 return 0;
58 } 83 }
59 84
60 85 int32_t BytecodeArrayIterator::GetSignedOperand(
61 int8_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const { 86 int operand_index, OperandType operand_type) const {
62 uint32_t operand = GetRawOperand(operand_index, OperandType::kImm8); 87 DCHECK_GE(operand_index, 0);
63 return static_cast<int8_t>(operand); 88 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode()));
89 DCHECK_EQ(operand_type,
90 Bytecodes::GetOperandType(current_bytecode(), operand_index));
91 DCHECK(!Bytecodes::IsUnsignedOperandType(operand_type));
92 uint8_t* operand_start =
93 bytecode_array()->GetFirstBytecodeAddress() + bytecode_offset_ +
94 current_prefix_offset() +
95 Bytecodes::GetOperandOffset(current_bytecode(), operand_index,
96 current_operand_scale());
97 switch (Bytecodes::SizeOfOperand(operand_type, current_operand_scale())) {
rmcilroy 2016/03/17 17:30:49 I think you could use DecodeSignedOperand here to
oth 2016/03/21 09:16:53 Yep, got all these before getting this far in the
98 case OperandSize::kByte:
99 return static_cast<int8_t>(*operand_start);
100 case OperandSize::kShort:
101 return static_cast<int16_t>(ReadUnalignedUInt16(operand_start));
102 case OperandSize::kQuad:
103 return static_cast<int32_t>(ReadUnalignedUInt32(operand_start));
104 case OperandSize::kNone:
105 UNREACHABLE();
106 }
107 return 0;
64 } 108 }
65 109
66 int BytecodeArrayIterator::GetRegisterCountOperand(int operand_index) const { 110 uint32_t BytecodeArrayIterator::GetFlagOperand(int operand_index) const {
67 OperandSize size = 111 DCHECK(Bytecodes::GetOperandType(current_bytecode(), operand_index) ==
68 Bytecodes::GetOperandSize(current_bytecode(), operand_index); 112 OperandType::kFlag8);
69 OperandType type = (size == OperandSize::kByte) ? OperandType::kRegCount8 113 return GetUnsignedOperand(operand_index, OperandType::kFlag8);
70 : OperandType::kRegCount16;
71 uint32_t operand = GetRawOperand(operand_index, type);
72 return static_cast<int>(operand);
73 } 114 }
74 115
116 int32_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const {
117 DCHECK(Bytecodes::GetOperandType(current_bytecode(), operand_index) ==
118 OperandType::kImm);
119 return GetSignedOperand(operand_index, OperandType::kImm);
120 }
75 121
76 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { 122 uint32_t BytecodeArrayIterator::GetRegisterCountOperand(
123 int operand_index) const {
124 DCHECK(Bytecodes::GetOperandType(current_bytecode(), operand_index) ==
rmcilroy 2016/03/17 17:30:49 DCHECK_EQ
oth 2016/03/21 09:16:53 Done.
125 OperandType::kRegCount);
126 return GetUnsignedOperand(operand_index, OperandType::kRegCount);
127 }
128
129 uint32_t BytecodeArrayIterator::GetIndexOperand(int operand_index) const {
77 OperandType operand_type = 130 OperandType operand_type =
78 Bytecodes::GetOperandType(current_bytecode(), operand_index); 131 Bytecodes::GetOperandType(current_bytecode(), operand_index);
79 DCHECK(operand_type == OperandType::kIdx8 || 132 DCHECK(operand_type == OperandType::kIdx);
rmcilroy 2016/03/17 17:30:49 DCHECK_EQ
oth 2016/03/21 09:16:53 Done.
80 operand_type == OperandType::kIdx16); 133 return GetUnsignedOperand(operand_index, operand_type);
81 uint32_t operand = GetRawOperand(operand_index, operand_type);
82 return static_cast<int>(operand);
83 } 134 }
84 135
85
86 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { 136 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const {
87 OperandType operand_type = 137 OperandType operand_type =
88 Bytecodes::GetOperandType(current_bytecode(), operand_index); 138 Bytecodes::GetOperandType(current_bytecode(), operand_index);
89 DCHECK(Bytecodes::IsRegisterOperandType(operand_type)); 139 DCHECK(Bytecodes::IsRegisterOperandType(operand_type));
90 uint32_t operand = GetRawOperand(operand_index, operand_type); 140 int32_t operand = GetSignedOperand(operand_index, operand_type);
91 Register reg; 141 Register reg = Register::FromOperand(operand);
92 switch (Bytecodes::GetOperandSize(current_bytecode(), operand_index)) {
93 case OperandSize::kByte:
94 reg = Register::FromOperand(static_cast<uint8_t>(operand));
95 break;
96 case OperandSize::kShort:
97 reg = Register::FromWideOperand(static_cast<uint16_t>(operand));
98 break;
99 case OperandSize::kNone:
100 UNREACHABLE();
101 reg = Register::invalid_value();
102 break;
103 }
104 DCHECK_GE(reg.index(), 142 DCHECK_GE(reg.index(),
105 Register::FromParameterIndex(0, bytecode_array()->parameter_count()) 143 Register::FromParameterIndex(0, bytecode_array()->parameter_count())
106 .index()); 144 .index());
107 DCHECK(reg.index() < bytecode_array()->register_count() || 145 DCHECK(reg.index() < bytecode_array()->register_count() ||
108 (reg.index() == 0 && 146 (reg.index() == 0 &&
109 Bytecodes::IsMaybeRegisterOperandType( 147 Bytecodes::IsMaybeRegisterOperandType(
110 Bytecodes::GetOperandType(current_bytecode(), operand_index)))); 148 Bytecodes::GetOperandType(current_bytecode(), operand_index))));
111 return reg; 149 return reg;
112 } 150 }
113 151
114 int BytecodeArrayIterator::GetRegisterOperandRange(int operand_index) const { 152 int BytecodeArrayIterator::GetRegisterOperandRange(int operand_index) const {
115 interpreter::OperandType operand_type = 153 interpreter::OperandType operand_type =
116 Bytecodes::GetOperandType(current_bytecode(), operand_index); 154 Bytecodes::GetOperandType(current_bytecode(), operand_index);
117 DCHECK(Bytecodes::IsRegisterOperandType(operand_type)); 155 DCHECK(Bytecodes::IsRegisterOperandType(operand_type));
118 switch (operand_type) { 156 switch (operand_type) {
119 case OperandType::kRegPair8: 157 case OperandType::kRegPair:
120 case OperandType::kRegPair16: 158 case OperandType::kRegOutPair:
121 case OperandType::kRegOutPair8:
122 case OperandType::kRegOutPair16:
123 return 2; 159 return 2;
124 case OperandType::kRegOutTriple8: 160 case OperandType::kRegOutTriple:
125 case OperandType::kRegOutTriple16:
126 return 3; 161 return 3;
127 default: { 162 default: {
128 if (operand_index + 1 != 163 if (operand_index + 1 !=
129 Bytecodes::NumberOfOperands(current_bytecode())) { 164 Bytecodes::NumberOfOperands(current_bytecode())) {
130 OperandType next_operand_type = 165 OperandType next_operand_type =
131 Bytecodes::GetOperandType(current_bytecode(), operand_index + 1); 166 Bytecodes::GetOperandType(current_bytecode(), operand_index + 1);
132 if (Bytecodes::IsRegisterCountOperandType(next_operand_type)) { 167 if (OperandType::kRegCount == next_operand_type) {
133 return GetRegisterCountOperand(operand_index + 1); 168 return GetRegisterCountOperand(operand_index + 1);
134 } 169 }
135 } 170 }
136 return 1; 171 return 1;
137 } 172 }
138 } 173 }
139 } 174 }
140 175
176 uint32_t BytecodeArrayIterator::GetRuntimeIdOperand(int operand_index) const {
177 OperandType operand_type =
178 Bytecodes::GetOperandType(current_bytecode(), operand_index);
179 DCHECK(operand_type == OperandType::kRuntimeId);
180 return GetUnsignedOperand(operand_index, operand_type);
181 }
182
141 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( 183 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand(
142 int operand_index) const { 184 int operand_index) const {
143 return FixedArray::get(bytecode_array()->constant_pool(), 185 return FixedArray::get(bytecode_array()->constant_pool(),
144 GetIndexOperand(operand_index), 186 GetIndexOperand(operand_index),
145 bytecode_array()->GetIsolate()); 187 bytecode_array()->GetIsolate());
146 } 188 }
147 189
148 190
149 int BytecodeArrayIterator::GetJumpTargetOffset() const { 191 int BytecodeArrayIterator::GetJumpTargetOffset() const {
150 Bytecode bytecode = current_bytecode(); 192 Bytecode bytecode = current_bytecode();
151 if (interpreter::Bytecodes::IsJumpImmediate(bytecode)) { 193 if (interpreter::Bytecodes::IsJumpImmediate(bytecode)) {
152 int relative_offset = GetImmediateOperand(0); 194 int relative_offset = GetImmediateOperand(0);
153 return current_offset() + relative_offset; 195 return current_offset() + relative_offset + current_prefix_offset();
154 } else if (interpreter::Bytecodes::IsJumpConstant(bytecode) || 196 } else if (interpreter::Bytecodes::IsJumpConstant(bytecode)) {
155 interpreter::Bytecodes::IsJumpConstantWide(bytecode)) {
156 Smi* smi = Smi::cast(*GetConstantForIndexOperand(0)); 197 Smi* smi = Smi::cast(*GetConstantForIndexOperand(0));
157 return current_offset() + smi->value(); 198 return current_offset() + smi->value() + current_prefix_offset();
158 } else { 199 } else {
159 UNREACHABLE(); 200 UNREACHABLE();
160 return kMinInt; 201 return kMinInt;
161 } 202 }
162 } 203 }
163 204
164 } // namespace interpreter 205 } // namespace interpreter
165 } // namespace internal 206 } // namespace internal
166 } // namespace v8 207 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698