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

Side by Side Diff: src/interpreter/interpreter-assembler.cc

Issue 1783483002: [interpreter] Add support for scalable operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Minor comment tweaks. 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/interpreter-assembler.h" 5 #include "src/interpreter/interpreter-assembler.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/frames.h" 10 #include "src/frames.h"
11 #include "src/interface-descriptors.h" 11 #include "src/interface-descriptors.h"
12 #include "src/interpreter/bytecodes.h" 12 #include "src/interpreter/bytecodes.h"
13 #include "src/interpreter/interpreter.h" 13 #include "src/interpreter/interpreter.h"
14 #include "src/machine-type.h" 14 #include "src/machine-type.h"
15 #include "src/macro-assembler.h" 15 #include "src/macro-assembler.h"
16 #include "src/zone.h" 16 #include "src/zone.h"
17 17
18 namespace v8 { 18 namespace v8 {
19 namespace internal { 19 namespace internal {
20 namespace interpreter { 20 namespace interpreter {
21 21
22 using compiler::Node; 22 using compiler::Node;
23 23
24 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone, 24 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone,
25 Bytecode bytecode) 25 Bytecode bytecode,
26 OperandScale operand_scale)
26 : compiler::CodeStubAssembler(isolate, zone, 27 : compiler::CodeStubAssembler(isolate, zone,
27 InterpreterDispatchDescriptor(isolate), 28 InterpreterDispatchDescriptor(isolate),
28 Code::ComputeFlags(Code::BYTECODE_HANDLER), 29 Code::ComputeFlags(Code::BYTECODE_HANDLER),
29 Bytecodes::ToString(bytecode), 0), 30 Bytecodes::ToString(bytecode), 0),
30 bytecode_(bytecode), 31 bytecode_(bytecode),
32 operand_scale_(operand_scale),
31 accumulator_(this, MachineRepresentation::kTagged), 33 accumulator_(this, MachineRepresentation::kTagged),
32 context_(this, MachineRepresentation::kTagged), 34 context_(this, MachineRepresentation::kTagged),
33 bytecode_array_(this, MachineRepresentation::kTagged), 35 bytecode_array_(this, MachineRepresentation::kTagged),
34 disable_stack_check_across_call_(false), 36 disable_stack_check_across_call_(false),
35 stack_pointer_before_call_(nullptr) { 37 stack_pointer_before_call_(nullptr) {
36 accumulator_.Bind( 38 accumulator_.Bind(
37 Parameter(InterpreterDispatchDescriptor::kAccumulatorParameter)); 39 Parameter(InterpreterDispatchDescriptor::kAccumulatorParameter));
38 context_.Bind(Parameter(InterpreterDispatchDescriptor::kContextParameter)); 40 context_.Bind(Parameter(InterpreterDispatchDescriptor::kContextParameter));
39 bytecode_array_.Bind( 41 bytecode_array_.Bind(
40 Parameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter)); 42 Parameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Node* InterpreterAssembler::RegisterLocation(Node* reg_index) { 79 Node* InterpreterAssembler::RegisterLocation(Node* reg_index) {
78 return IntPtrAdd(RegisterFileRawPointer(), RegisterFrameOffset(reg_index)); 80 return IntPtrAdd(RegisterFileRawPointer(), RegisterFrameOffset(reg_index));
79 } 81 }
80 82
81 Node* InterpreterAssembler::LoadRegister(int offset) { 83 Node* InterpreterAssembler::LoadRegister(int offset) {
82 return Load(MachineType::AnyTagged(), RegisterFileRawPointer(), 84 return Load(MachineType::AnyTagged(), RegisterFileRawPointer(),
83 IntPtrConstant(offset)); 85 IntPtrConstant(offset));
84 } 86 }
85 87
86 Node* InterpreterAssembler::LoadRegister(Register reg) { 88 Node* InterpreterAssembler::LoadRegister(Register reg) {
87 return LoadRegister(reg.ToOperand() << kPointerSizeLog2); 89 return LoadRegister(IntPtrConstant(-reg.index()));
88 } 90 }
89 91
90 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) { 92 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) {
91 return WordShl(index, kPointerSizeLog2); 93 return WordShl(index, kPointerSizeLog2);
92 } 94 }
93 95
94 Node* InterpreterAssembler::LoadRegister(Node* reg_index) { 96 Node* InterpreterAssembler::LoadRegister(Node* reg_index) {
95 return Load(MachineType::AnyTagged(), RegisterFileRawPointer(), 97 return Load(MachineType::AnyTagged(), RegisterFileRawPointer(),
96 RegisterFrameOffset(reg_index)); 98 RegisterFrameOffset(reg_index));
97 } 99 }
98 100
99 Node* InterpreterAssembler::StoreRegister(Node* value, int offset) { 101 Node* InterpreterAssembler::StoreRegister(Node* value, int offset) {
100 return StoreNoWriteBarrier(MachineRepresentation::kTagged, 102 return StoreNoWriteBarrier(MachineRepresentation::kTagged,
101 RegisterFileRawPointer(), IntPtrConstant(offset), 103 RegisterFileRawPointer(), IntPtrConstant(offset),
102 value); 104 value);
103 } 105 }
104 106
105 Node* InterpreterAssembler::StoreRegister(Node* value, Register reg) { 107 Node* InterpreterAssembler::StoreRegister(Node* value, Register reg) {
106 return StoreRegister(value, reg.ToOperand() << kPointerSizeLog2); 108 return StoreRegister(value, IntPtrConstant(-reg.index()));
107 } 109 }
108 110
109 Node* InterpreterAssembler::StoreRegister(Node* value, Node* reg_index) { 111 Node* InterpreterAssembler::StoreRegister(Node* value, Node* reg_index) {
110 return StoreNoWriteBarrier(MachineRepresentation::kTagged, 112 return StoreNoWriteBarrier(MachineRepresentation::kTagged,
111 RegisterFileRawPointer(), 113 RegisterFileRawPointer(),
112 RegisterFrameOffset(reg_index), value); 114 RegisterFrameOffset(reg_index), value);
113 } 115 }
114 116
115 Node* InterpreterAssembler::NextRegister(Node* reg_index) { 117 Node* InterpreterAssembler::NextRegister(Node* reg_index) {
116 // Register indexes are negative, so the next index is minus one. 118 // Register indexes are negative, so the next index is minus one.
117 return IntPtrAdd(reg_index, IntPtrConstant(-1)); 119 return IntPtrAdd(reg_index, IntPtrConstant(-1));
118 } 120 }
119 121
120 Node* InterpreterAssembler::BytecodeOperand(int operand_index) { 122 Node* InterpreterAssembler::OperandOffset(int operand_index) {
121 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_)); 123 return IntPtrConstant(
122 DCHECK_EQ(OperandSize::kByte, 124 Bytecodes::GetOperandOffset(bytecode_, operand_index, operand_scale()));
123 Bytecodes::GetOperandSize(bytecode_, operand_index));
124 return Load(
125 MachineType::Uint8(), BytecodeArrayTaggedPointer(),
126 IntPtrAdd(BytecodeOffset(), IntPtrConstant(Bytecodes::GetOperandOffset(
127 bytecode_, operand_index))));
128 } 125 }
129 126
130 Node* InterpreterAssembler::BytecodeOperandSignExtended(int operand_index) { 127 Node* InterpreterAssembler::BytecodeOperandUnsignedByte(int operand_index) {
131 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_)); 128 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_));
132 DCHECK_EQ(OperandSize::kByte, 129 DCHECK_EQ(OperandSize::kByte, Bytecodes::GetOperandSize(
133 Bytecodes::GetOperandSize(bytecode_, operand_index)); 130 bytecode_, operand_index, operand_scale()));
134 Node* load = Load( 131 Node* operand_offset = OperandOffset(operand_index);
135 MachineType::Int8(), BytecodeArrayTaggedPointer(), 132 return Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(),
136 IntPtrAdd(BytecodeOffset(), IntPtrConstant(Bytecodes::GetOperandOffset( 133 IntPtrAdd(BytecodeOffset(), operand_offset));
137 bytecode_, operand_index)))); 134 }
135
136 Node* InterpreterAssembler::BytecodeOperandSignedByte(int operand_index) {
137 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_));
138 DCHECK_EQ(OperandSize::kByte, Bytecodes::GetOperandSize(
139 bytecode_, operand_index, operand_scale()));
140 Node* operand_offset = OperandOffset(operand_index);
141 Node* load = Load(MachineType::Int8(), BytecodeArrayTaggedPointer(),
142 IntPtrAdd(BytecodeOffset(), operand_offset));
143
138 // Ensure that we sign extend to full pointer size 144 // Ensure that we sign extend to full pointer size
139 if (kPointerSize == 8) { 145 if (kPointerSize == 8) {
140 load = ChangeInt32ToInt64(load); 146 load = ChangeInt32ToInt64(load);
141 } 147 }
142 return load; 148 return load;
143 } 149 }
144 150
145 Node* InterpreterAssembler::BytecodeOperandShort(int operand_index) { 151 compiler::Node* InterpreterAssembler::BytecodeReadUnalignedBytes(
146 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_)); 152 int relative_offset, int count, MachineType msb_type) {
147 DCHECK_EQ(OperandSize::kShort, 153 static const int kMaxCount = 4;
148 Bytecodes::GetOperandSize(bytecode_, operand_index)); 154 DCHECK(msb_type == MachineType::Int8() || msb_type == MachineType::Uint8());
149 if (TargetSupportsUnalignedAccess()) { 155 DCHECK(count <= kMaxCount);
150 return Load( 156
151 MachineType::Uint16(), BytecodeArrayTaggedPointer(),
152 IntPtrAdd(BytecodeOffset(), IntPtrConstant(Bytecodes::GetOperandOffset(
153 bytecode_, operand_index))));
154 } else {
155 int offset = Bytecodes::GetOperandOffset(bytecode_, operand_index);
156 Node* first_byte =
157 Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(),
158 IntPtrAdd(BytecodeOffset(), IntPtrConstant(offset)));
159 Node* second_byte =
160 Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(),
161 IntPtrAdd(BytecodeOffset(), IntPtrConstant(offset + 1)));
162 #if V8_TARGET_LITTLE_ENDIAN 157 #if V8_TARGET_LITTLE_ENDIAN
163 return WordOr(WordShl(second_byte, kBitsPerByte), first_byte); 158 const int kStep = -1;
159 int msb_offset = count - 1;
164 #elif V8_TARGET_BIG_ENDIAN 160 #elif V8_TARGET_BIG_ENDIAN
165 return WordOr(WordShl(first_byte, kBitsPerByte), second_byte); 161 const int kStep = 1;
162 int msb_offset = 0;
166 #else 163 #else
167 #error "Unknown Architecture" 164 #error "Unknown Architecture"
168 #endif 165 #endif
166
167 // Read the most signicant bytecode into bytes[0] and then in order
168 // down to least significant in bytes[count - 1].
169 compiler::Node* bytes[kMaxCount];
170 for (int i = 0; i < count; i++) {
171 MachineType machine_type = (i == 0) ? msb_type : MachineType::Uint8();
172 Node* offset = IntPtrConstant(relative_offset + msb_offset + i * kStep);
173 Node* array_offset = IntPtrAdd(BytecodeOffset(), offset);
174 bytes[i] = Load(machine_type, BytecodeArrayTaggedPointer(), array_offset);
175 }
176
177 // Pack LSB to MSB.
178 Node* result = bytes[--count];
179 for (int i = 1; --count >= 0; i++) {
180 Node* shift = Int32Constant(i * kBitsPerByte);
181 Node* value = Word32Shl(bytes[count], shift);
182 result = Word32Or(value, result);
183 }
184 return result;
185 }
186
187 Node* InterpreterAssembler::BytecodeOperandUnsignedShort(int operand_index) {
188 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_));
189 DCHECK_EQ(
190 OperandSize::kShort,
191 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale()));
192 int operand_offset =
193 Bytecodes::GetOperandOffset(bytecode_, operand_index, operand_scale());
194 if (TargetSupportsUnalignedAccess()) {
195 return Load(MachineType::Uint16(), BytecodeArrayTaggedPointer(),
196 IntPtrAdd(BytecodeOffset(), IntPtrConstant(operand_offset)));
197 } else {
198 return BytecodeReadUnalignedBytes(operand_offset, 2, MachineType::Uint8());
169 } 199 }
170 } 200 }
171 201
172 Node* InterpreterAssembler::BytecodeOperandShortSignExtended( 202 Node* InterpreterAssembler::BytecodeOperandSignedShort(int operand_index) {
173 int operand_index) {
174 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_)); 203 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_));
175 DCHECK_EQ(OperandSize::kShort, 204 DCHECK_EQ(
176 Bytecodes::GetOperandSize(bytecode_, operand_index)); 205 OperandSize::kShort,
177 int operand_offset = Bytecodes::GetOperandOffset(bytecode_, operand_index); 206 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale()));
207 int operand_offset =
208 Bytecodes::GetOperandOffset(bytecode_, operand_index, operand_scale());
178 Node* load; 209 Node* load;
179 if (TargetSupportsUnalignedAccess()) { 210 if (TargetSupportsUnalignedAccess()) {
180 load = Load(MachineType::Int16(), BytecodeArrayTaggedPointer(), 211 load = Load(MachineType::Int16(), BytecodeArrayTaggedPointer(),
181 IntPtrAdd(BytecodeOffset(), IntPtrConstant(operand_offset))); 212 IntPtrAdd(BytecodeOffset(), IntPtrConstant(operand_offset)));
182 } else { 213 } else {
183 #if V8_TARGET_LITTLE_ENDIAN 214 load = BytecodeReadUnalignedBytes(operand_offset, 2, MachineType::Int8());
184 Node* hi_byte_offset = IntPtrConstant(operand_offset + 1);
185 Node* lo_byte_offset = IntPtrConstant(operand_offset);
186 #elif V8_TARGET_BIG_ENDIAN
187 Node* hi_byte_offset = IntPtrConstant(operand_offset);
188 Node* lo_byte_offset = IntPtrConstant(operand_offset + 1);
189 #else
190 #error "Unknown Architecture"
191 #endif
192 Node* hi_byte = Load(MachineType::Int8(), BytecodeArrayTaggedPointer(),
193 IntPtrAdd(BytecodeOffset(), hi_byte_offset));
194 Node* lo_byte = Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(),
195 IntPtrAdd(BytecodeOffset(), lo_byte_offset));
196 hi_byte = Word32Shl(hi_byte, Int32Constant(kBitsPerByte));
197 load = Word32Or(hi_byte, lo_byte);
198 } 215 }
199 216
200 // Ensure that we sign extend to full pointer size 217 // Ensure that we sign extend to full pointer size
201 if (kPointerSize == 8) { 218 if (kPointerSize == 8) {
202 load = ChangeInt32ToInt64(load); 219 load = ChangeInt32ToInt64(load);
203 } 220 }
204 return load; 221 return load;
205 } 222 }
206 223
207 Node* InterpreterAssembler::BytecodeOperandCount(int operand_index) { 224 Node* InterpreterAssembler::BytecodeOperandUnsignedQuad(int operand_index) {
208 switch (Bytecodes::GetOperandSize(bytecode_, operand_index)) { 225 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_));
226 DCHECK_EQ(OperandSize::kQuad, Bytecodes::GetOperandSize(
227 bytecode_, operand_index, operand_scale()));
228 int operand_offset =
229 Bytecodes::GetOperandOffset(bytecode_, operand_index, operand_scale());
230 if (TargetSupportsUnalignedAccess()) {
231 return Load(MachineType::Uint32(), BytecodeArrayTaggedPointer(),
232 IntPtrAdd(BytecodeOffset(), IntPtrConstant(operand_offset)));
233 } else {
234 return BytecodeReadUnalignedBytes(operand_offset, 4, MachineType::Uint8());
235 }
236 }
237
238 Node* InterpreterAssembler::BytecodeOperandSignedQuad(int operand_index) {
239 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode_));
240 DCHECK_EQ(OperandSize::kQuad, Bytecodes::GetOperandSize(
241 bytecode_, operand_index, operand_scale()));
242 int operand_offset =
243 Bytecodes::GetOperandOffset(bytecode_, operand_index, operand_scale());
244 Node* load;
245 if (TargetSupportsUnalignedAccess()) {
246 load = Load(MachineType::Int32(), BytecodeArrayTaggedPointer(),
247 IntPtrAdd(BytecodeOffset(), IntPtrConstant(operand_offset)));
248 } else {
249 load = BytecodeReadUnalignedBytes(operand_offset, 4, MachineType::Int8());
250 }
251
252 // Ensure that we sign extend to full pointer size
253 if (kPointerSize == 8) {
254 load = ChangeInt32ToInt64(load);
255 }
256 return load;
257 }
258
259 Node* InterpreterAssembler::BytecodeSignedOperand(int operand_index,
260 OperandSize operand_size) {
261 DCHECK(!Bytecodes::IsUnsignedOperandType(
262 Bytecodes::GetOperandType(bytecode_, operand_index)));
263 switch (operand_size) {
209 case OperandSize::kByte: 264 case OperandSize::kByte:
210 DCHECK_EQ(OperandType::kRegCount8, 265 return BytecodeOperandSignedByte(operand_index);
211 Bytecodes::GetOperandType(bytecode_, operand_index));
212 return BytecodeOperand(operand_index);
213 case OperandSize::kShort: 266 case OperandSize::kShort:
214 DCHECK_EQ(OperandType::kRegCount16, 267 return BytecodeOperandSignedShort(operand_index);
215 Bytecodes::GetOperandType(bytecode_, operand_index)); 268 case OperandSize::kQuad:
216 return BytecodeOperandShort(operand_index); 269 return BytecodeOperandSignedQuad(operand_index);
217 case OperandSize::kNone: 270 case OperandSize::kNone:
218 UNREACHABLE(); 271 UNREACHABLE();
219 } 272 }
220 return nullptr; 273 return nullptr;
221 } 274 }
222 275
223 Node* InterpreterAssembler::BytecodeOperandImm(int operand_index) { 276 Node* InterpreterAssembler::BytecodeUnsignedOperand(int operand_index,
224 DCHECK_EQ(OperandType::kImm8, 277 OperandSize operand_size) {
225 Bytecodes::GetOperandType(bytecode_, operand_index)); 278 DCHECK(Bytecodes::IsUnsignedOperandType(
226 return BytecodeOperandSignExtended(operand_index); 279 Bytecodes::GetOperandType(bytecode_, operand_index)));
227 } 280 switch (operand_size) {
228
229 Node* InterpreterAssembler::BytecodeOperandIdx(int operand_index) {
230 switch (Bytecodes::GetOperandSize(bytecode_, operand_index)) {
231 case OperandSize::kByte: 281 case OperandSize::kByte:
232 DCHECK_EQ(OperandType::kIdx8, 282 return BytecodeOperandUnsignedByte(operand_index);
233 Bytecodes::GetOperandType(bytecode_, operand_index));
234 return BytecodeOperand(operand_index);
235 case OperandSize::kShort: 283 case OperandSize::kShort:
236 DCHECK_EQ(OperandType::kIdx16, 284 return BytecodeOperandUnsignedShort(operand_index);
237 Bytecodes::GetOperandType(bytecode_, operand_index)); 285 case OperandSize::kQuad:
238 return BytecodeOperandShort(operand_index); 286 return BytecodeOperandUnsignedQuad(operand_index);
239 case OperandSize::kNone: 287 case OperandSize::kNone:
240 UNREACHABLE(); 288 UNREACHABLE();
241 } 289 }
242 return nullptr; 290 return nullptr;
243 } 291 }
244 292
293 Node* InterpreterAssembler::BytecodeOperandCount(int operand_index) {
294 DCHECK_EQ(OperandType::kRegCount,
295 Bytecodes::GetOperandType(bytecode_, operand_index));
296 OperandSize operand_size =
297 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
298 return BytecodeUnsignedOperand(operand_index, operand_size);
299 }
300
301 Node* InterpreterAssembler::BytecodeOperandFlag(int operand_index) {
302 DCHECK_EQ(OperandType::kFlag8,
303 Bytecodes::GetOperandType(bytecode_, operand_index));
304 OperandSize operand_size =
305 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
306 DCHECK_EQ(operand_size, OperandSize::kByte);
307 return BytecodeUnsignedOperand(operand_index, operand_size);
308 }
309
310 Node* InterpreterAssembler::BytecodeOperandImm(int operand_index) {
311 DCHECK_EQ(OperandType::kImm,
312 Bytecodes::GetOperandType(bytecode_, operand_index));
313 OperandSize operand_size =
314 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
315 return BytecodeSignedOperand(operand_index, operand_size);
316 }
317
318 Node* InterpreterAssembler::BytecodeOperandIdx(int operand_index) {
319 DCHECK(OperandType::kIdx ==
320 Bytecodes::GetOperandType(bytecode_, operand_index));
321 OperandSize operand_size =
322 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
323 return BytecodeUnsignedOperand(operand_index, operand_size);
324 }
325
245 Node* InterpreterAssembler::BytecodeOperandReg(int operand_index) { 326 Node* InterpreterAssembler::BytecodeOperandReg(int operand_index) {
246 OperandType operand_type = 327 DCHECK(Bytecodes::IsRegisterOperandType(
247 Bytecodes::GetOperandType(bytecode_, operand_index); 328 Bytecodes::GetOperandType(bytecode_, operand_index)));
248 if (Bytecodes::IsRegisterOperandType(operand_type)) { 329 OperandSize operand_size =
249 OperandSize operand_size = Bytecodes::SizeOfOperand(operand_type); 330 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
250 if (operand_size == OperandSize::kByte) { 331 return BytecodeSignedOperand(operand_index, operand_size);
251 return BytecodeOperandSignExtended(operand_index); 332 }
252 } else if (operand_size == OperandSize::kShort) { 333
253 return BytecodeOperandShortSignExtended(operand_index); 334 Node* InterpreterAssembler::BytecodeOperandRuntimeId(int operand_index) {
254 } 335 DCHECK(OperandType::kRuntimeId ==
255 } 336 Bytecodes::GetOperandType(bytecode_, operand_index));
256 UNREACHABLE(); 337 OperandSize operand_size =
257 return nullptr; 338 Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
339 DCHECK_EQ(operand_size, OperandSize::kShort);
340 return BytecodeUnsignedOperand(operand_index, operand_size);
258 } 341 }
259 342
260 Node* InterpreterAssembler::LoadConstantPoolEntry(Node* index) { 343 Node* InterpreterAssembler::LoadConstantPoolEntry(Node* index) {
261 Node* constant_pool = LoadObjectField(BytecodeArrayTaggedPointer(), 344 Node* constant_pool = LoadObjectField(BytecodeArrayTaggedPointer(),
262 BytecodeArray::kConstantPoolOffset); 345 BytecodeArray::kConstantPoolOffset);
263 Node* entry_offset = 346 Node* entry_offset =
264 IntPtrAdd(IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag), 347 IntPtrAdd(IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
265 WordShl(index, kPointerSizeLog2)); 348 WordShl(index, kPointerSizeLog2));
266 return Load(MachineType::AnyTagged(), constant_pool, entry_offset); 349 return Load(MachineType::AnyTagged(), constant_pool, entry_offset);
267 } 350 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 void InterpreterAssembler::JumpIfWordEqual(Node* lhs, Node* rhs, Node* delta) { 508 void InterpreterAssembler::JumpIfWordEqual(Node* lhs, Node* rhs, Node* delta) {
426 JumpConditional(WordEqual(lhs, rhs), delta); 509 JumpConditional(WordEqual(lhs, rhs), delta);
427 } 510 }
428 511
429 void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs, 512 void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs,
430 Node* delta) { 513 Node* delta) {
431 JumpConditional(WordNotEqual(lhs, rhs), delta); 514 JumpConditional(WordNotEqual(lhs, rhs), delta);
432 } 515 }
433 516
434 void InterpreterAssembler::Dispatch() { 517 void InterpreterAssembler::Dispatch() {
435 DispatchTo(Advance(Bytecodes::Size(bytecode_))); 518 DispatchTo(Advance(Bytecodes::Size(bytecode_, operand_scale_)));
436 } 519 }
437 520
438 void InterpreterAssembler::DispatchTo(Node* new_bytecode_offset) { 521 void InterpreterAssembler::DispatchTo(Node* new_bytecode_offset) {
439 Node* target_bytecode = Load( 522 Node* target_bytecode = Load(
440 MachineType::Uint8(), BytecodeArrayTaggedPointer(), new_bytecode_offset); 523 MachineType::Uint8(), BytecodeArrayTaggedPointer(), new_bytecode_offset);
441 if (kPointerSize == 8) { 524 if (kPointerSize == 8) {
442 target_bytecode = ChangeUint32ToUint64(target_bytecode); 525 target_bytecode = ChangeUint32ToUint64(target_bytecode);
443 } 526 }
444 527
445 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion 528 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion
(...skipping 11 matching lines...) Expand all
457 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit); 540 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
458 } 541 }
459 542
460 InterpreterDispatchDescriptor descriptor(isolate()); 543 InterpreterDispatchDescriptor descriptor(isolate());
461 Node* args[] = {GetAccumulator(), RegisterFileRawPointer(), 544 Node* args[] = {GetAccumulator(), RegisterFileRawPointer(),
462 bytecode_offset, BytecodeArrayTaggedPointer(), 545 bytecode_offset, BytecodeArrayTaggedPointer(),
463 DispatchTableRawPointer(), GetContext()}; 546 DispatchTableRawPointer(), GetContext()};
464 TailCall(descriptor, handler, args, 0); 547 TailCall(descriptor, handler, args, 0);
465 } 548 }
466 549
550 void InterpreterAssembler::DispatchWide(OperandScale operand_scale) {
551 // Dispatching a wide bytecode requires treating the prefix
552 // bytecode a base pointer into the dispatch table and dispatching
553 // the bytecode that follows relative to this base.
554 //
555 // Indices 0-255 correspond to bytecodes with operand_scale == 0
556 // Indices 256-511 correspond to bytecodes with operand_scale == 1
557 // Indices 512-767 correspond to bytecodes with operand_scale == 2
558 Node* next_bytecode_offset = Advance(1);
559 Node* next_bytecode = Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(),
560 next_bytecode_offset);
561 if (kPointerSize == 8) {
562 next_bytecode = ChangeUint32ToUint64(next_bytecode);
563 }
564 Node* base_index;
565 switch (operand_scale) {
566 case OperandScale::kDouble:
567 base_index = IntPtrConstant(1 << kBitsPerByte);
568 break;
569 case OperandScale::kQuadruple:
570 base_index = IntPtrConstant(2 << kBitsPerByte);
571 break;
572 default:
573 UNREACHABLE();
574 base_index = nullptr;
575 }
576 Node* target_index = IntPtrAdd(base_index, next_bytecode);
577 Node* target_code_object =
578 Load(MachineType::Pointer(), DispatchTableRawPointer(),
579 WordShl(target_index, kPointerSizeLog2));
580
581 DispatchToBytecodeHandler(target_code_object, next_bytecode_offset);
582 }
583
467 void InterpreterAssembler::InterpreterReturn() { 584 void InterpreterAssembler::InterpreterReturn() {
468 // TODO(rmcilroy): Investigate whether it is worth supporting self 585 // TODO(rmcilroy): Investigate whether it is worth supporting self
469 // optimization of primitive functions like FullCodegen. 586 // optimization of primitive functions like FullCodegen.
470 587
471 // Update profiling count by -BytecodeOffset to simulate backedge to start of 588 // Update profiling count by -BytecodeOffset to simulate backedge to start of
472 // function. 589 // function.
473 Node* profiling_weight = 590 Node* profiling_weight =
474 Int32Sub(Int32Constant(kHeapObjectTag + BytecodeArray::kHeaderSize), 591 Int32Sub(Int32Constant(kHeapObjectTag + BytecodeArray::kHeaderSize),
475 BytecodeOffset()); 592 BytecodeOffset());
476 UpdateInterruptBudget(profiling_weight); 593 UpdateInterruptBudget(profiling_weight);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 V8_TARGET_ARCH_S390 652 V8_TARGET_ARCH_S390
536 return true; 653 return true;
537 #else 654 #else
538 #error "Unknown Architecture" 655 #error "Unknown Architecture"
539 #endif 656 #endif
540 } 657 }
541 658
542 } // namespace interpreter 659 } // namespace interpreter
543 } // namespace internal 660 } // namespace internal
544 } // namespace v8 661 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698