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

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

Issue 1997653002: [interpreter] Bytecode register optimizer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Decouple a test from implementation. Created 4 years, 6 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
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <iomanip> 7 #include <iomanip>
8 8
9 #include "src/frames.h" 9 #include "src/frames.h"
10 #include "src/interpreter/bytecode-traits.h" 10 #include "src/interpreter/bytecode-traits.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 BYTECODE_LIST(CASE) 294 BYTECODE_LIST(CASE)
295 #undef CASE 295 #undef CASE
296 } 296 }
297 UNREACHABLE(); 297 UNREACHABLE();
298 return nullptr; 298 return nullptr;
299 } 299 }
300 300
301 // static 301 // static
302 OperandSize Bytecodes::GetOperandSize(Bytecode bytecode, int i, 302 OperandSize Bytecodes::GetOperandSize(Bytecode bytecode, int i,
303 OperandScale operand_scale) { 303 OperandScale operand_scale) {
304 DCHECK_LT(i, NumberOfOperands(bytecode));
305 return GetOperandSizes(bytecode, operand_scale)[i];
306 }
307
308 // static
309 const OperandSize* Bytecodes::GetOperandSizes(Bytecode bytecode,
310 OperandScale operand_scale) {
304 DCHECK(bytecode <= Bytecode::kLast); 311 DCHECK(bytecode <= Bytecode::kLast);
305 switch (bytecode) { 312 switch (bytecode) {
306 #define CASE(Name, ...) \ 313 #define CASE(Name, ...) \
307 case Bytecode::k##Name: \ 314 case Bytecode::k##Name: \
308 return BytecodeTraits<__VA_ARGS__>::GetOperandSize(i, operand_scale); 315 return BytecodeTraits<__VA_ARGS__>::GetOperandSizes(operand_scale);
309 BYTECODE_LIST(CASE) 316 BYTECODE_LIST(CASE)
310 #undef CASE 317 #undef CASE
311 } 318 }
312 UNREACHABLE(); 319 UNREACHABLE();
313 return OperandSize::kNone; 320 return nullptr;
314 } 321 }
315 322
316 // static 323 // static
317 int Bytecodes::GetRegisterOperandBitmap(Bytecode bytecode) { 324 int Bytecodes::GetRegisterOperandBitmap(Bytecode bytecode) {
318 DCHECK(bytecode <= Bytecode::kLast); 325 DCHECK(bytecode <= Bytecode::kLast);
319 switch (bytecode) { 326 switch (bytecode) {
320 #define CASE(Name, ...) \ 327 #define CASE(Name, ...) \
321 case Bytecode::k##Name: \ 328 case Bytecode::k##Name: \
322 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \ 329 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \
323 return Name##Trait::kRegisterOperandBitmap; 330 return Name##Trait::kRegisterOperandBitmap;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 } else if (value <= static_cast<size_t>(kMaxUInt16)) { 619 } else if (value <= static_cast<size_t>(kMaxUInt16)) {
613 return OperandSize::kShort; 620 return OperandSize::kShort;
614 } else if (value <= kMaxUInt32) { 621 } else if (value <= kMaxUInt32) {
615 return OperandSize::kQuad; 622 return OperandSize::kQuad;
616 } else { 623 } else {
617 UNREACHABLE(); 624 UNREACHABLE();
618 return OperandSize::kQuad; 625 return OperandSize::kQuad;
619 } 626 }
620 } 627 }
621 628
629 OperandScale Bytecodes::OperandSizesToScale(OperandSize size0) {
630 OperandScale operand_scale = static_cast<OperandScale>(size0);
631 DCHECK(operand_scale == OperandScale::kSingle ||
632 operand_scale == OperandScale::kDouble ||
633 operand_scale == OperandScale::kQuadruple);
634 return operand_scale;
635 }
636
637 OperandScale Bytecodes::OperandSizesToScale(OperandSize size0,
638 OperandSize size1) {
639 OperandSize operand_size = std::max(size0, size1);
640 // Operand sizes have been scaled before calling this function.
641 // Currently all scalable operands are byte sized at
642 // OperandScale::kSingle.
643 STATIC_ASSERT(static_cast<int>(OperandSize::kByte) ==
644 static_cast<int>(OperandScale::kSingle) &&
645 static_cast<int>(OperandSize::kShort) ==
646 static_cast<int>(OperandScale::kDouble) &&
647 static_cast<int>(OperandSize::kQuad) ==
648 static_cast<int>(OperandScale::kQuadruple));
649 OperandScale operand_scale = static_cast<OperandScale>(operand_size);
650 DCHECK(operand_scale == OperandScale::kSingle ||
651 operand_scale == OperandScale::kDouble ||
652 operand_scale == OperandScale::kQuadruple);
653 return operand_scale;
654 }
655
622 OperandScale Bytecodes::OperandSizesToScale(OperandSize size0, 656 OperandScale Bytecodes::OperandSizesToScale(OperandSize size0,
623 OperandSize size1, 657 OperandSize size1,
624 OperandSize size2, 658 OperandSize size2,
625 OperandSize size3) { 659 OperandSize size3) {
626 OperandSize upper = std::max(size0, size1); 660 OperandSize upper = std::max(size0, size1);
627 OperandSize lower = std::max(size2, size3); 661 OperandSize lower = std::max(size2, size3);
628 OperandSize result = std::max(upper, lower); 662 OperandSize result = std::max(upper, lower);
629 // Operand sizes have been scaled before calling this function. 663 // Operand sizes have been scaled before calling this function.
630 // Currently all scalable operands are byte sized at 664 // Currently all scalable operands are byte sized at
631 // OperandScale::kSingle. 665 // OperandScale::kSingle.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 InterpreterFrameConstants::kNewTargetFromFp) / 857 InterpreterFrameConstants::kNewTargetFromFp) /
824 kPointerSize; 858 kPointerSize;
825 static const int kBytecodeArrayRegisterIndex = 859 static const int kBytecodeArrayRegisterIndex =
826 (InterpreterFrameConstants::kRegisterFileFromFp - 860 (InterpreterFrameConstants::kRegisterFileFromFp -
827 InterpreterFrameConstants::kBytecodeArrayFromFp) / 861 InterpreterFrameConstants::kBytecodeArrayFromFp) /
828 kPointerSize; 862 kPointerSize;
829 static const int kBytecodeOffsetRegisterIndex = 863 static const int kBytecodeOffsetRegisterIndex =
830 (InterpreterFrameConstants::kRegisterFileFromFp - 864 (InterpreterFrameConstants::kRegisterFileFromFp -
831 InterpreterFrameConstants::kBytecodeOffsetFromFp) / 865 InterpreterFrameConstants::kBytecodeOffsetFromFp) /
832 kPointerSize; 866 kPointerSize;
867 static const int kCallerPCOffsetRegisterIndex =
868 (InterpreterFrameConstants::kRegisterFileFromFp -
869 InterpreterFrameConstants::kCallerPCOffsetFromFp) /
870 kPointerSize;
833 871
834 Register Register::FromParameterIndex(int index, int parameter_count) { 872 Register Register::FromParameterIndex(int index, int parameter_count) {
835 DCHECK_GE(index, 0); 873 DCHECK_GE(index, 0);
836 DCHECK_LT(index, parameter_count); 874 DCHECK_LT(index, parameter_count);
837 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; 875 int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
838 DCHECK_LT(register_index, 0); 876 DCHECK_LT(register_index, 0);
839 return Register(register_index); 877 return Register(register_index);
840 } 878 }
841 879
842 int Register::ToParameterIndex(int parameter_count) const { 880 int Register::ToParameterIndex(int parameter_count) const {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 } 913 }
876 914
877 Register Register::bytecode_offset() { 915 Register Register::bytecode_offset() {
878 return Register(kBytecodeOffsetRegisterIndex); 916 return Register(kBytecodeOffsetRegisterIndex);
879 } 917 }
880 918
881 bool Register::is_bytecode_offset() const { 919 bool Register::is_bytecode_offset() const {
882 return index() == kBytecodeOffsetRegisterIndex; 920 return index() == kBytecodeOffsetRegisterIndex;
883 } 921 }
884 922
923 // static
924 Register Register::virtual_accumulator() {
925 return Register(kCallerPCOffsetRegisterIndex);
926 }
927
885 OperandSize Register::SizeOfOperand() const { 928 OperandSize Register::SizeOfOperand() const {
886 int32_t operand = ToOperand(); 929 int32_t operand = ToOperand();
887 if (operand >= kMinInt8 && operand <= kMaxInt8) { 930 if (operand >= kMinInt8 && operand <= kMaxInt8) {
888 return OperandSize::kByte; 931 return OperandSize::kByte;
889 } else if (operand >= kMinInt16 && operand <= kMaxInt16) { 932 } else if (operand >= kMinInt16 && operand <= kMaxInt16) {
890 return OperandSize::kShort; 933 return OperandSize::kShort;
891 } else { 934 } else {
892 return OperandSize::kQuad; 935 return OperandSize::kQuad;
893 } 936 }
894 } 937 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 } else { 972 } else {
930 std::ostringstream s; 973 std::ostringstream s;
931 s << "r" << index(); 974 s << "r" << index();
932 return s.str(); 975 return s.str();
933 } 976 }
934 } 977 }
935 978
936 } // namespace interpreter 979 } // namespace interpreter
937 } // namespace internal 980 } // namespace internal
938 } // namespace v8 981 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698