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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 3662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3673 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { | 3673 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { |
3674 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first, | 3674 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first, |
3675 "*"); | 3675 "*"); |
3676 auto callable = tester.GetCallable<>(); | 3676 auto callable = tester.GetCallable<>(); |
3677 | 3677 |
3678 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3678 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3679 CHECK(return_value->SameValue(*eval_func_decl[i].second)); | 3679 CHECK(return_value->SameValue(*eval_func_decl[i].second)); |
3680 } | 3680 } |
3681 } | 3681 } |
3682 | 3682 |
| 3683 TEST(InterpreterWideRegisterArithmetic) { |
| 3684 HandleAndZoneScope handles; |
| 3685 i::Isolate* isolate = handles.main_isolate(); |
| 3686 |
| 3687 static const size_t kMaxRegisterForTest = 150; |
| 3688 std::ostringstream os; |
| 3689 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
| 3690 os << " var retval = -77;\n"; |
| 3691 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
| 3692 os << " var x" << i << " = " << i << ";\n"; |
| 3693 } |
| 3694 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
| 3695 size_t j = kMaxRegisterForTest - i - 1; |
| 3696 os << " var tmp = x" << j << ";\n"; |
| 3697 os << " var x" << j << " = x" << i << ";\n"; |
| 3698 os << " var x" << i << " = tmp;\n"; |
| 3699 } |
| 3700 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
| 3701 size_t j = kMaxRegisterForTest - i - 1; |
| 3702 os << " var tmp = x" << j << ";\n"; |
| 3703 os << " var x" << j << " = x" << i << ";\n"; |
| 3704 os << " var x" << i << " = tmp;\n"; |
| 3705 } |
| 3706 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
| 3707 os << " if (arg == " << i << ") {\n" // |
| 3708 << " retval = x" << i << ";\n" // |
| 3709 << " }\n"; // |
| 3710 } |
| 3711 os << " return retval;\n"; |
| 3712 os << "}\n"; |
| 3713 |
| 3714 std::string source = os.str(); |
| 3715 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 3716 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3717 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
| 3718 Handle<Object> arg = handle(Smi::FromInt(static_cast<int>(i)), isolate); |
| 3719 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
| 3720 CHECK(return_value->SameValue(*arg)); |
| 3721 } |
| 3722 } |
| 3723 |
| 3724 TEST(InterpreterCallWideRegisters) { |
| 3725 static const int kPeriod = 25; |
| 3726 static const int kLength = 512; |
| 3727 static const int kStartChar = 65; |
| 3728 |
| 3729 for (int pass = 0; pass < 3; pass += 1) { |
| 3730 std::ostringstream os; |
| 3731 for (int i = 0; i < pass * 97; i += 1) { |
| 3732 os << "var x" << i << " = " << i << "\n"; |
| 3733 } |
| 3734 os << "return String.fromCharCode("; |
| 3735 os << kStartChar; |
| 3736 for (int i = 1; i < kLength; i += 1) { |
| 3737 os << "," << kStartChar + (i % kPeriod); |
| 3738 } |
| 3739 os << ");"; |
| 3740 std::string source = InterpreterTester::SourceForBody(os.str().c_str()); |
| 3741 HandleAndZoneScope handles; |
| 3742 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 3743 auto callable = tester.GetCallable(); |
| 3744 Handle<Object> return_val = callable().ToHandleChecked(); |
| 3745 Handle<String> return_string = Handle<String>::cast(return_val); |
| 3746 CHECK_EQ(return_string->length(), kLength); |
| 3747 for (int i = 0; i < kLength; i += 1) { |
| 3748 CHECK_EQ(return_string->Get(i), 65 + (i % kPeriod)); |
| 3749 } |
| 3750 } |
| 3751 } |
| 3752 |
| 3753 TEST(InterpreterWideParametersPickOne) { |
| 3754 static const int kParameterCount = 130; |
| 3755 for (int parameter = 0; parameter < 10; parameter++) { |
| 3756 HandleAndZoneScope handles; |
| 3757 i::Isolate* isolate = handles.main_isolate(); |
| 3758 std::ostringstream os; |
| 3759 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
| 3760 os << " function selector(i"; |
| 3761 for (int i = 0; i < kParameterCount; i++) { |
| 3762 os << "," |
| 3763 << "a" << i; |
| 3764 } |
| 3765 os << ") {\n"; |
| 3766 os << " return a" << parameter << ";\n"; |
| 3767 os << " };\n"; |
| 3768 os << " return selector(arg"; |
| 3769 for (int i = 0; i < kParameterCount; i++) { |
| 3770 os << "," << i; |
| 3771 } |
| 3772 os << ");"; |
| 3773 os << "}\n"; |
| 3774 |
| 3775 std::string source = os.str(); |
| 3776 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); |
| 3777 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3778 Handle<Object> arg = handle(Smi::FromInt(0xaa55), isolate); |
| 3779 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
| 3780 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
| 3781 CHECK_EQ(actual->value(), parameter); |
| 3782 } |
| 3783 } |
| 3784 |
| 3785 TEST(InterpreterWideParametersSummation) { |
| 3786 static int kParameterCount = 200; |
| 3787 static int kBaseValue = 17000; |
| 3788 HandleAndZoneScope handles; |
| 3789 i::Isolate* isolate = handles.main_isolate(); |
| 3790 std::ostringstream os; |
| 3791 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
| 3792 os << " function summation(i"; |
| 3793 for (int i = 0; i < kParameterCount; i++) { |
| 3794 os << "," |
| 3795 << "a" << i; |
| 3796 } |
| 3797 os << ") {\n"; |
| 3798 os << " var sum = " << kBaseValue << ";\n"; |
| 3799 os << " switch(i) {\n"; |
| 3800 for (int i = 0; i < kParameterCount; i++) { |
| 3801 int j = kParameterCount - i - 1; |
| 3802 os << " case " << j << ": sum += a" << j << ";\n"; |
| 3803 } |
| 3804 os << " }\n"; |
| 3805 os << " return sum;\n"; |
| 3806 os << " };\n"; |
| 3807 os << " return summation(arg"; |
| 3808 for (int i = 0; i < kParameterCount; i++) { |
| 3809 os << "," << i; |
| 3810 } |
| 3811 os << ");"; |
| 3812 os << "}\n"; |
| 3813 |
| 3814 std::string source = os.str(); |
| 3815 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); |
| 3816 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3817 for (int i = 0; i < kParameterCount; i++) { |
| 3818 Handle<Object> arg = handle(Smi::FromInt(i), isolate); |
| 3819 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
| 3820 int expected = kBaseValue + i * (i + 1) / 2; |
| 3821 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
| 3822 CHECK_EQ(actual->value(), expected); |
| 3823 } |
| 3824 } |
| 3825 |
| 3826 // TODO(oth): Test for..in with wide registers. |
| 3827 |
3683 } // namespace interpreter | 3828 } // namespace interpreter |
3684 } // namespace internal | 3829 } // namespace internal |
3685 } // namespace v8 | 3830 } // namespace v8 |
OLD | NEW |