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