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

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

Issue 1613163002: [interpreter] Wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Compilation fixes for gcc/msvc. Created 4 years, 11 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/bytecodes.h" 5 #include "src/interpreter/bytecodes.h"
6 6
7 #include "src/frames.h" 7 #include "src/frames.h"
8 #include "src/interpreter/bytecode-traits.h" 8 #include "src/interpreter/bytecode-traits.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 case OperandSize::kShort: 50 case OperandSize::kShort:
51 return "Short"; 51 return "Short";
52 } 52 }
53 UNREACHABLE(); 53 UNREACHABLE();
54 return ""; 54 return "";
55 } 55 }
56 56
57 57
58 // static 58 // static
59 uint8_t Bytecodes::ToByte(Bytecode bytecode) { 59 uint8_t Bytecodes::ToByte(Bytecode bytecode) {
60 DCHECK(bytecode <= Bytecode::kLast);
60 return static_cast<uint8_t>(bytecode); 61 return static_cast<uint8_t>(bytecode);
61 } 62 }
62 63
63 64
64 // static 65 // static
65 Bytecode Bytecodes::FromByte(uint8_t value) { 66 Bytecode Bytecodes::FromByte(uint8_t value) {
66 Bytecode bytecode = static_cast<Bytecode>(value); 67 Bytecode bytecode = static_cast<Bytecode>(value);
67 DCHECK(bytecode <= Bytecode::kLast); 68 DCHECK(bytecode <= Bytecode::kLast);
68 return bytecode; 69 return bytecode;
69 } 70 }
(...skipping 23 matching lines...) Expand all
93 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::kOperandCount; 94 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::kOperandCount;
94 BYTECODE_LIST(CASE) 95 BYTECODE_LIST(CASE)
95 #undef CASE 96 #undef CASE
96 } 97 }
97 UNREACHABLE(); 98 UNREACHABLE();
98 return 0; 99 return 0;
99 } 100 }
100 101
101 102
102 // static 103 // static
104 int Bytecodes::NumberOfRegisterOperands(Bytecode bytecode) {
105 DCHECK(bytecode <= Bytecode::kLast);
106 switch (bytecode) {
107 #define CASE(Name, ...) \
108 case Bytecode::k##Name: \
109 typedef BytecodeTraits<__VA_ARGS__, OPERAND_TERM> Name##Trait; \
110 return Name##Trait::kRegisterOperandCount;
111 BYTECODE_LIST(CASE)
112 #undef CASE
113 }
114 UNREACHABLE();
115 return false;
116 }
117
118
119 // static
103 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { 120 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) {
104 DCHECK(bytecode <= Bytecode::kLast); 121 DCHECK(bytecode <= Bytecode::kLast);
105 switch (bytecode) { 122 switch (bytecode) {
106 #define CASE(Name, ...) \ 123 #define CASE(Name, ...) \
107 case Bytecode::k##Name: \ 124 case Bytecode::k##Name: \
108 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandType(i); 125 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandType(i);
109 BYTECODE_LIST(CASE) 126 BYTECODE_LIST(CASE)
110 #undef CASE 127 #undef CASE
111 } 128 }
112 UNREACHABLE(); 129 UNREACHABLE();
(...skipping 10 matching lines...) Expand all
123 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandSize(i); 140 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandSize(i);
124 BYTECODE_LIST(CASE) 141 BYTECODE_LIST(CASE)
125 #undef CASE 142 #undef CASE
126 } 143 }
127 UNREACHABLE(); 144 UNREACHABLE();
128 return OperandSize::kNone; 145 return OperandSize::kNone;
129 } 146 }
130 147
131 148
132 // static 149 // static
150 int Bytecodes::GetRegisterOperandBitmap(Bytecode bytecode) {
151 DCHECK(bytecode <= Bytecode::kLast);
152 switch (bytecode) {
153 #define CASE(Name, ...) \
154 case Bytecode::k##Name: \
155 typedef BytecodeTraits<__VA_ARGS__, OPERAND_TERM> Name##Trait; \
156 return Name##Trait::kRegisterOperandBitmap;
157 BYTECODE_LIST(CASE)
158 #undef CASE
159 }
160 UNREACHABLE();
161 return false;
162 }
163
164
165 // static
133 int Bytecodes::GetOperandOffset(Bytecode bytecode, int i) { 166 int Bytecodes::GetOperandOffset(Bytecode bytecode, int i) {
134 DCHECK(bytecode <= Bytecode::kLast); 167 DCHECK(bytecode <= Bytecode::kLast);
135 switch (bytecode) { 168 switch (bytecode) {
136 #define CASE(Name, ...) \ 169 #define CASE(Name, ...) \
137 case Bytecode::k##Name: \ 170 case Bytecode::k##Name: \
138 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandOffset(i); 171 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandOffset(i);
139 BYTECODE_LIST(CASE) 172 BYTECODE_LIST(CASE)
140 #undef CASE 173 #undef CASE
141 } 174 }
142 UNREACHABLE(); 175 UNREACHABLE();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 389
357 static const int kLastParamRegisterIndex = 390 static const int kLastParamRegisterIndex =
358 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; 391 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
359 static const int kFunctionClosureRegisterIndex = 392 static const int kFunctionClosureRegisterIndex =
360 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize; 393 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize;
361 static const int kCurrentContextRegisterIndex = 394 static const int kCurrentContextRegisterIndex =
362 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; 395 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize;
363 static const int kNewTargetRegisterIndex = 396 static const int kNewTargetRegisterIndex =
364 -InterpreterFrameConstants::kNewTargetFromRegisterPointer / kPointerSize; 397 -InterpreterFrameConstants::kNewTargetFromRegisterPointer / kPointerSize;
365 398
399 // The register space is a signed 16-bit space. Register operands
400 // occupy range above 0. Parameter indices are biased with the
401 // negative value kLastParamRegisterIndex for ease of access in the
402 // interpreter.
403 static const int kMaxParameterIndex = kMaxInt16 + kLastParamRegisterIndex;
404 static const int kMaxRegisterIndex = -kMinInt16;
405 static const int kMaxReg8Index = -kMinInt8;
406 static const int kMinReg8Index = -kMaxInt8;
407 static const int kMaxReg16Index = -kMinInt16;
408 static const int kMinReg16Index = -kMaxInt16;
366 409
367 // Registers occupy range 0-127 in 8-bit value leaving 128 unused values. 410 bool Register::is_byte_operand() const {
368 // Parameter indices are biased with the negative value kLastParamRegisterIndex 411 return index_ >= kMinReg8Index && index_ <= kMaxReg8Index;
369 // for ease of access in the interpreter. 412 }
370 static const int kMaxParameterIndex = 128 + kLastParamRegisterIndex; 413
414
415 bool Register::is_short_operand() const {
416 return index_ >= kMinReg16Index && index_ <= kMaxReg16Index;
417 }
371 418
372 419
373 Register Register::FromParameterIndex(int index, int parameter_count) { 420 Register Register::FromParameterIndex(int index, int parameter_count) {
374 DCHECK_GE(index, 0); 421 DCHECK_GE(index, 0);
375 DCHECK_LT(index, parameter_count); 422 DCHECK_LT(index, parameter_count);
376 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); 423 DCHECK_LE(parameter_count, kMaxParameterIndex + 1);
377 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; 424 int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
378 DCHECK_LT(register_index, 0); 425 DCHECK_LT(register_index, 0);
379 DCHECK_GE(register_index, kMinInt8);
380 return Register(register_index); 426 return Register(register_index);
381 } 427 }
382 428
383 429
384 int Register::ToParameterIndex(int parameter_count) const { 430 int Register::ToParameterIndex(int parameter_count) const {
385 DCHECK(is_parameter()); 431 DCHECK(is_parameter());
386 return index() - kLastParamRegisterIndex + parameter_count - 1; 432 return index() - kLastParamRegisterIndex + parameter_count - 1;
387 } 433 }
388 434
389 435
(...skipping 21 matching lines...) Expand all
411 457
412 458
413 bool Register::is_new_target() const { 459 bool Register::is_new_target() const {
414 return index() == kNewTargetRegisterIndex; 460 return index() == kNewTargetRegisterIndex;
415 } 461 }
416 462
417 463
418 int Register::MaxParameterIndex() { return kMaxParameterIndex; } 464 int Register::MaxParameterIndex() { return kMaxParameterIndex; }
419 465
420 466
467 int Register::MaxRegisterIndex() { return kMaxRegisterIndex; }
468
469
470 int Register::MaxRegisterIndexForByteOperand() { return kMaxReg8Index; }
471
472
421 uint8_t Register::ToOperand() const { 473 uint8_t Register::ToOperand() const {
422 DCHECK_GE(index_, kMinInt8); 474 DCHECK(is_byte_operand());
423 DCHECK_LE(index_, kMaxInt8);
424 return static_cast<uint8_t>(-index_); 475 return static_cast<uint8_t>(-index_);
425 } 476 }
426 477
427 478
428 Register Register::FromOperand(uint8_t operand) { 479 Register Register::FromOperand(uint8_t operand) {
429 return Register(-static_cast<int8_t>(operand)); 480 return Register(-static_cast<int8_t>(operand));
430 } 481 }
431 482
432 483
433 uint16_t Register::ToWideOperand() const { 484 uint16_t Register::ToWideOperand() const {
434 DCHECK_GE(index_, kMinInt16); 485 DCHECK(is_short_operand());
435 DCHECK_LE(index_, kMaxInt16);
436 return static_cast<uint16_t>(-index_); 486 return static_cast<uint16_t>(-index_);
437 } 487 }
438 488
439 489
440 Register Register::FromWideOperand(uint16_t operand) { 490 Register Register::FromWideOperand(uint16_t operand) {
441 return Register(-static_cast<int16_t>(operand)); 491 return Register(-static_cast<int16_t>(operand));
442 } 492 }
443 493
444 494
445 uint32_t Register::ToRawOperand() const { 495 uint32_t Register::ToRawOperand() const {
(...skipping 19 matching lines...) Expand all
465 } 515 }
466 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { 516 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) {
467 return false; 517 return false;
468 } 518 }
469 return true; 519 return true;
470 } 520 }
471 521
472 } // namespace interpreter 522 } // namespace interpreter
473 } // namespace internal 523 } // namespace internal
474 } // namespace v8 524 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698