| 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 |
| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 373 |
| 357 static const int kLastParamRegisterIndex = | 374 static const int kLastParamRegisterIndex = |
| 358 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; | 375 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; |
| 359 static const int kFunctionClosureRegisterIndex = | 376 static const int kFunctionClosureRegisterIndex = |
| 360 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize; | 377 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize; |
| 361 static const int kFunctionContextRegisterIndex = | 378 static const int kFunctionContextRegisterIndex = |
| 362 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; | 379 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; |
| 363 static const int kNewTargetRegisterIndex = | 380 static const int kNewTargetRegisterIndex = |
| 364 -InterpreterFrameConstants::kNewTargetFromRegisterPointer / kPointerSize; | 381 -InterpreterFrameConstants::kNewTargetFromRegisterPointer / kPointerSize; |
| 365 | 382 |
| 383 // The register space is a signed 16-bit space. Register operands |
| 384 // occupy range above 0. Parameter indices are biased with the |
| 385 // negative value kLastParamRegisterIndex for ease of access in the |
| 386 // interpreter. |
| 387 static const int kMaxParameterIndex = kMaxInt16 + kLastParamRegisterIndex; |
| 388 static const int kMaxRegisterIndex = -kMinInt16; |
| 366 | 389 |
| 367 // Registers occupy range 0-127 in 8-bit value leaving 128 unused values. | 390 |
| 368 // Parameter indices are biased with the negative value kLastParamRegisterIndex | 391 bool Register::is_byte_operand() const { |
| 369 // for ease of access in the interpreter. | 392 return index_ >= -kMaxInt8 && index_ <= -kMinInt8; |
| 370 static const int kMaxParameterIndex = 128 + kLastParamRegisterIndex; | 393 } |
| 394 |
| 395 |
| 396 bool Register::is_short_operand() const { |
| 397 return index_ >= -kMaxInt16 && index_ <= -kMinInt16; |
| 398 } |
| 371 | 399 |
| 372 | 400 |
| 373 Register Register::FromParameterIndex(int index, int parameter_count) { | 401 Register Register::FromParameterIndex(int index, int parameter_count) { |
| 374 DCHECK_GE(index, 0); | 402 DCHECK_GE(index, 0); |
| 375 DCHECK_LT(index, parameter_count); | 403 DCHECK_LT(index, parameter_count); |
| 376 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); | 404 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); |
| 377 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; | 405 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; |
| 378 DCHECK_LT(register_index, 0); | 406 DCHECK_LT(register_index, 0); |
| 379 DCHECK_GE(register_index, kMinInt8); | |
| 380 return Register(register_index); | 407 return Register(register_index); |
| 381 } | 408 } |
| 382 | 409 |
| 383 | 410 |
| 384 int Register::ToParameterIndex(int parameter_count) const { | 411 int Register::ToParameterIndex(int parameter_count) const { |
| 385 DCHECK(is_parameter()); | 412 DCHECK(is_parameter()); |
| 386 return index() - kLastParamRegisterIndex + parameter_count - 1; | 413 return index() - kLastParamRegisterIndex + parameter_count - 1; |
| 387 } | 414 } |
| 388 | 415 |
| 389 | 416 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 411 | 438 |
| 412 | 439 |
| 413 bool Register::is_new_target() const { | 440 bool Register::is_new_target() const { |
| 414 return index() == kNewTargetRegisterIndex; | 441 return index() == kNewTargetRegisterIndex; |
| 415 } | 442 } |
| 416 | 443 |
| 417 | 444 |
| 418 int Register::MaxParameterIndex() { return kMaxParameterIndex; } | 445 int Register::MaxParameterIndex() { return kMaxParameterIndex; } |
| 419 | 446 |
| 420 | 447 |
| 448 int Register::MaxRegisterIndex() { return kMaxRegisterIndex; } |
| 449 |
| 450 |
| 421 uint8_t Register::ToOperand() const { | 451 uint8_t Register::ToOperand() const { |
| 422 DCHECK_GE(index_, kMinInt8); | 452 DCHECK(is_byte_operand()); |
| 423 DCHECK_LE(index_, kMaxInt8); | |
| 424 return static_cast<uint8_t>(-index_); | 453 return static_cast<uint8_t>(-index_); |
| 425 } | 454 } |
| 426 | 455 |
| 427 | 456 |
| 428 Register Register::FromOperand(uint8_t operand) { | 457 Register Register::FromOperand(uint8_t operand) { |
| 429 return Register(-static_cast<int8_t>(operand)); | 458 return Register(-static_cast<int8_t>(operand)); |
| 430 } | 459 } |
| 431 | 460 |
| 432 | 461 |
| 433 uint16_t Register::ToWideOperand() const { | 462 uint16_t Register::ToWideOperand() const { |
| 434 DCHECK_GE(index_, kMinInt16); | 463 DCHECK(is_short_operand()); |
| 435 DCHECK_LE(index_, kMaxInt16); | |
| 436 return static_cast<uint16_t>(-index_); | 464 return static_cast<uint16_t>(-index_); |
| 437 } | 465 } |
| 438 | 466 |
| 439 | 467 |
| 440 Register Register::FromWideOperand(uint16_t operand) { | 468 Register Register::FromWideOperand(uint16_t operand) { |
| 441 return Register(-static_cast<int16_t>(operand)); | 469 return Register(-static_cast<int16_t>(operand)); |
| 442 } | 470 } |
| 443 | 471 |
| 444 | 472 |
| 445 uint32_t Register::ToRawOperand() const { | 473 uint32_t Register::ToRawOperand() const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 465 } | 493 } |
| 466 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { | 494 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { |
| 467 return false; | 495 return false; |
| 468 } | 496 } |
| 469 return true; | 497 return true; |
| 470 } | 498 } |
| 471 | 499 |
| 472 } // namespace interpreter | 500 } // namespace interpreter |
| 473 } // namespace internal | 501 } // namespace internal |
| 474 } // namespace v8 | 502 } // namespace v8 |
| OLD | NEW |