| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 // static |
| 103 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { | 119 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { |
| 104 DCHECK(bytecode <= Bytecode::kLast); | 120 DCHECK(bytecode <= Bytecode::kLast); |
| 105 switch (bytecode) { | 121 switch (bytecode) { |
| 106 #define CASE(Name, ...) \ | 122 #define CASE(Name, ...) \ |
| 107 case Bytecode::k##Name: \ | 123 case Bytecode::k##Name: \ |
| 108 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandType(i); | 124 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandType(i); |
| 109 BYTECODE_LIST(CASE) | 125 BYTECODE_LIST(CASE) |
| 110 #undef CASE | 126 #undef CASE |
| 111 } | 127 } |
| 112 UNREACHABLE(); | 128 UNREACHABLE(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandSize(i); | 139 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandSize(i); |
| 124 BYTECODE_LIST(CASE) | 140 BYTECODE_LIST(CASE) |
| 125 #undef CASE | 141 #undef CASE |
| 126 } | 142 } |
| 127 UNREACHABLE(); | 143 UNREACHABLE(); |
| 128 return OperandSize::kNone; | 144 return OperandSize::kNone; |
| 129 } | 145 } |
| 130 | 146 |
| 131 | 147 |
| 132 // static | 148 // static |
| 149 int Bytecodes::GetRegisterOperandBitmap(Bytecode bytecode) { |
| 150 DCHECK(bytecode <= Bytecode::kLast); |
| 151 switch (bytecode) { |
| 152 #define CASE(Name, ...) \ |
| 153 case Bytecode::k##Name: \ |
| 154 typedef BytecodeTraits<__VA_ARGS__, OPERAND_TERM> Name##Trait; \ |
| 155 return Name##Trait::kRegisterOperandBitmap; |
| 156 BYTECODE_LIST(CASE) |
| 157 #undef CASE |
| 158 } |
| 159 UNREACHABLE(); |
| 160 return false; |
| 161 } |
| 162 |
| 163 // static |
| 133 int Bytecodes::GetOperandOffset(Bytecode bytecode, int i) { | 164 int Bytecodes::GetOperandOffset(Bytecode bytecode, int i) { |
| 134 DCHECK(bytecode <= Bytecode::kLast); | 165 DCHECK(bytecode <= Bytecode::kLast); |
| 135 switch (bytecode) { | 166 switch (bytecode) { |
| 136 #define CASE(Name, ...) \ | 167 #define CASE(Name, ...) \ |
| 137 case Bytecode::k##Name: \ | 168 case Bytecode::k##Name: \ |
| 138 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandOffset(i); | 169 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandOffset(i); |
| 139 BYTECODE_LIST(CASE) | 170 BYTECODE_LIST(CASE) |
| 140 #undef CASE | 171 #undef CASE |
| 141 } | 172 } |
| 142 UNREACHABLE(); | 173 UNREACHABLE(); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 387 |
| 357 static const int kLastParamRegisterIndex = | 388 static const int kLastParamRegisterIndex = |
| 358 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; | 389 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; |
| 359 static const int kFunctionClosureRegisterIndex = | 390 static const int kFunctionClosureRegisterIndex = |
| 360 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize; | 391 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize; |
| 361 static const int kCurrentContextRegisterIndex = | 392 static const int kCurrentContextRegisterIndex = |
| 362 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; | 393 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; |
| 363 static const int kNewTargetRegisterIndex = | 394 static const int kNewTargetRegisterIndex = |
| 364 -InterpreterFrameConstants::kNewTargetFromRegisterPointer / kPointerSize; | 395 -InterpreterFrameConstants::kNewTargetFromRegisterPointer / kPointerSize; |
| 365 | 396 |
| 397 // The register space is a signed 16-bit space. Register operands |
| 398 // occupy range above 0. Parameter indices are biased with the |
| 399 // negative value kLastParamRegisterIndex for ease of access in the |
| 400 // interpreter. |
| 401 static const int kMaxParameterIndex = kMaxInt16 + kLastParamRegisterIndex; |
| 402 static const int kMaxRegisterIndex = -kMinInt16; |
| 403 static const int kMaxReg8Index = -kMinInt8; |
| 404 static const int kMinReg8Index = -kMaxInt8; |
| 405 static const int kMaxReg16Index = -kMinInt16; |
| 406 static const int kMinReg16Index = -kMaxInt16; |
| 366 | 407 |
| 367 // Registers occupy range 0-127 in 8-bit value leaving 128 unused values. | 408 bool Register::is_byte_operand() const { |
| 368 // Parameter indices are biased with the negative value kLastParamRegisterIndex | 409 return index_ >= kMinReg8Index && index_ <= kMaxReg8Index; |
| 369 // for ease of access in the interpreter. | 410 } |
| 370 static const int kMaxParameterIndex = 128 + kLastParamRegisterIndex; | |
| 371 | 411 |
| 412 bool Register::is_short_operand() const { |
| 413 return index_ >= kMinReg16Index && index_ <= kMaxReg16Index; |
| 414 } |
| 372 | 415 |
| 373 Register Register::FromParameterIndex(int index, int parameter_count) { | 416 Register Register::FromParameterIndex(int index, int parameter_count) { |
| 374 DCHECK_GE(index, 0); | 417 DCHECK_GE(index, 0); |
| 375 DCHECK_LT(index, parameter_count); | 418 DCHECK_LT(index, parameter_count); |
| 376 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); | 419 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); |
| 377 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; | 420 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; |
| 378 DCHECK_LT(register_index, 0); | 421 DCHECK_LT(register_index, 0); |
| 379 DCHECK_GE(register_index, kMinInt8); | |
| 380 return Register(register_index); | 422 return Register(register_index); |
| 381 } | 423 } |
| 382 | 424 |
| 383 | 425 |
| 384 int Register::ToParameterIndex(int parameter_count) const { | 426 int Register::ToParameterIndex(int parameter_count) const { |
| 385 DCHECK(is_parameter()); | 427 DCHECK(is_parameter()); |
| 386 return index() - kLastParamRegisterIndex + parameter_count - 1; | 428 return index() - kLastParamRegisterIndex + parameter_count - 1; |
| 387 } | 429 } |
| 388 | 430 |
| 389 | 431 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 410 Register Register::new_target() { return Register(kNewTargetRegisterIndex); } | 452 Register Register::new_target() { return Register(kNewTargetRegisterIndex); } |
| 411 | 453 |
| 412 | 454 |
| 413 bool Register::is_new_target() const { | 455 bool Register::is_new_target() const { |
| 414 return index() == kNewTargetRegisterIndex; | 456 return index() == kNewTargetRegisterIndex; |
| 415 } | 457 } |
| 416 | 458 |
| 417 | 459 |
| 418 int Register::MaxParameterIndex() { return kMaxParameterIndex; } | 460 int Register::MaxParameterIndex() { return kMaxParameterIndex; } |
| 419 | 461 |
| 462 int Register::MaxRegisterIndex() { return kMaxRegisterIndex; } |
| 463 |
| 464 int Register::MaxRegisterIndexForByteOperand() { return kMaxReg8Index; } |
| 420 | 465 |
| 421 uint8_t Register::ToOperand() const { | 466 uint8_t Register::ToOperand() const { |
| 422 DCHECK_GE(index_, kMinInt8); | 467 DCHECK(is_byte_operand()); |
| 423 DCHECK_LE(index_, kMaxInt8); | |
| 424 return static_cast<uint8_t>(-index_); | 468 return static_cast<uint8_t>(-index_); |
| 425 } | 469 } |
| 426 | 470 |
| 427 | 471 |
| 428 Register Register::FromOperand(uint8_t operand) { | 472 Register Register::FromOperand(uint8_t operand) { |
| 429 return Register(-static_cast<int8_t>(operand)); | 473 return Register(-static_cast<int8_t>(operand)); |
| 430 } | 474 } |
| 431 | 475 |
| 432 | 476 |
| 433 uint16_t Register::ToWideOperand() const { | 477 uint16_t Register::ToWideOperand() const { |
| 434 DCHECK_GE(index_, kMinInt16); | 478 DCHECK(is_short_operand()); |
| 435 DCHECK_LE(index_, kMaxInt16); | |
| 436 return static_cast<uint16_t>(-index_); | 479 return static_cast<uint16_t>(-index_); |
| 437 } | 480 } |
| 438 | 481 |
| 439 | 482 |
| 440 Register Register::FromWideOperand(uint16_t operand) { | 483 Register Register::FromWideOperand(uint16_t operand) { |
| 441 return Register(-static_cast<int16_t>(operand)); | 484 return Register(-static_cast<int16_t>(operand)); |
| 442 } | 485 } |
| 443 | 486 |
| 444 | 487 |
| 445 uint32_t Register::ToRawOperand() const { | 488 uint32_t Register::ToRawOperand() const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 465 } | 508 } |
| 466 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { | 509 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { |
| 467 return false; | 510 return false; |
| 468 } | 511 } |
| 469 return true; | 512 return true; |
| 470 } | 513 } |
| 471 | 514 |
| 472 } // namespace interpreter | 515 } // namespace interpreter |
| 473 } // namespace internal | 516 } // namespace internal |
| 474 } // namespace v8 | 517 } // namespace v8 |
| OLD | NEW |