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 3516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3527 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { | 3527 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { |
3528 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first, | 3528 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first, |
3529 "*"); | 3529 "*"); |
3530 auto callable = tester.GetCallable<>(); | 3530 auto callable = tester.GetCallable<>(); |
3531 | 3531 |
3532 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3532 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3533 CHECK(return_value->SameValue(*eval_func_decl[i].second)); | 3533 CHECK(return_value->SameValue(*eval_func_decl[i].second)); |
3534 } | 3534 } |
3535 } | 3535 } |
3536 | 3536 |
| 3537 |
| 3538 TEST(InterpreterWideRegisterArithmetic) { |
| 3539 HandleAndZoneScope handles; |
| 3540 i::Isolate* isolate = handles.main_isolate(); |
| 3541 |
| 3542 static const size_t kMaxRegisterForTest = 150; |
| 3543 std::ostringstream os; |
| 3544 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
| 3545 os << " var retval = -77;\n"; |
| 3546 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
| 3547 os << " var x" << i << " = " << i << ";\n"; |
| 3548 } |
| 3549 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
| 3550 size_t j = kMaxRegisterForTest - i - 1; |
| 3551 os << " var tmp = x" << j << ";\n"; |
| 3552 os << " var x" << j << " = x" << i << ";\n"; |
| 3553 os << " var x" << i << " = tmp;\n"; |
| 3554 } |
| 3555 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
| 3556 size_t j = kMaxRegisterForTest - i - 1; |
| 3557 os << " var tmp = x" << j << ";\n"; |
| 3558 os << " var x" << j << " = x" << i << ";\n"; |
| 3559 os << " var x" << i << " = tmp;\n"; |
| 3560 } |
| 3561 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
| 3562 os << " if (arg == " << i << ") {\n" // |
| 3563 << " retval = x" << i << ";\n" // |
| 3564 << " }\n"; // |
| 3565 } |
| 3566 os << " return retval;\n"; |
| 3567 os << "}\n"; |
| 3568 |
| 3569 std::string source = os.str(); |
| 3570 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 3571 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3572 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
| 3573 Handle<Object> arg = handle(Smi::FromInt(static_cast<int>(i)), isolate); |
| 3574 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
| 3575 CHECK(return_value->SameValue(*arg)); |
| 3576 } |
| 3577 } |
| 3578 |
| 3579 |
| 3580 TEST(InterpreterCallWideRegisters) { |
| 3581 static const int kPeriod = 25; |
| 3582 static const int kLength = 512; |
| 3583 static const int kStartChar = 65; |
| 3584 |
| 3585 for (int pass = 0; pass < 3; pass += 1) { |
| 3586 std::ostringstream os; |
| 3587 for (int i = 0; i < pass * 97; i += 1) { |
| 3588 os << "var x" << i << " = " << i << "\n"; |
| 3589 } |
| 3590 os << "return String.fromCharCode("; |
| 3591 os << kStartChar; |
| 3592 for (int i = 1; i < kLength; i += 1) { |
| 3593 os << "," << kStartChar + (i % kPeriod); |
| 3594 } |
| 3595 os << ");"; |
| 3596 std::string source = InterpreterTester::SourceForBody(os.str().c_str()); |
| 3597 HandleAndZoneScope handles; |
| 3598 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 3599 auto callable = tester.GetCallable(); |
| 3600 Handle<Object> return_val = callable().ToHandleChecked(); |
| 3601 Handle<String> return_string = Handle<String>::cast(return_val); |
| 3602 CHECK_EQ(return_string->length(), kLength); |
| 3603 for (int i = 0; i < kLength; i += 1) { |
| 3604 CHECK_EQ(return_string->Get(i), 65 + (i % kPeriod)); |
| 3605 } |
| 3606 } |
| 3607 } |
| 3608 |
| 3609 |
| 3610 TEST(InterpreterWideParametersPickOne) { |
| 3611 static const int kParameterCount = 130; |
| 3612 for (int i = 0; i < 10; i++) { |
| 3613 HandleAndZoneScope handles; |
| 3614 i::Isolate* isolate = handles.main_isolate(); |
| 3615 std::ostringstream os; |
| 3616 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
| 3617 os << " function selector(i"; |
| 3618 for (int i = 0; i < kParameterCount; i++) { |
| 3619 os << "," |
| 3620 << "a" << i; |
| 3621 } |
| 3622 os << ") {\n"; |
| 3623 os << " return a" << i << ";\n"; |
| 3624 os << " };\n"; |
| 3625 os << " return selector(arg"; |
| 3626 for (int i = 0; i < kParameterCount; i++) { |
| 3627 os << "," << i; |
| 3628 } |
| 3629 os << ");"; |
| 3630 os << "}\n"; |
| 3631 |
| 3632 std::string source = os.str(); |
| 3633 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); |
| 3634 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3635 Handle<Object> arg = handle(Smi::FromInt(0xaa55), isolate); |
| 3636 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
| 3637 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
| 3638 CHECK_EQ(actual->value(), i); |
| 3639 } |
| 3640 } |
| 3641 |
| 3642 |
| 3643 TEST(InterpreterWideParametersSummation) { |
| 3644 static int kParameterCount = 200; |
| 3645 static int kBaseValue = 17000; |
| 3646 HandleAndZoneScope handles; |
| 3647 i::Isolate* isolate = handles.main_isolate(); |
| 3648 std::ostringstream os; |
| 3649 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
| 3650 os << " function summation(i"; |
| 3651 for (int i = 0; i < kParameterCount; i++) { |
| 3652 os << "," |
| 3653 << "a" << i; |
| 3654 } |
| 3655 os << ") {\n"; |
| 3656 os << " var sum = " << kBaseValue << ";\n"; |
| 3657 os << " switch(i) {\n"; |
| 3658 for (int i = 0; i < kParameterCount; i++) { |
| 3659 int j = kParameterCount - i - 1; |
| 3660 os << " case " << j << ": sum += a" << j << ";\n"; |
| 3661 } |
| 3662 os << " }\n"; |
| 3663 os << " return sum;\n"; |
| 3664 os << " };\n"; |
| 3665 os << " return summation(arg"; |
| 3666 for (int i = 0; i < kParameterCount; i++) { |
| 3667 os << "," << i; |
| 3668 } |
| 3669 os << ");"; |
| 3670 os << "}\n"; |
| 3671 |
| 3672 std::string source = os.str(); |
| 3673 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); |
| 3674 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3675 for (int i = 0; i < kParameterCount; i++) { |
| 3676 Handle<Object> arg = handle(Smi::FromInt(i), isolate); |
| 3677 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
| 3678 int expected = kBaseValue + i * (i + 1) / 2; |
| 3679 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
| 3680 CHECK_EQ(actual->value(), expected); |
| 3681 } |
| 3682 } |
| 3683 |
| 3684 |
| 3685 // TODO(oth): Test for..in with wide registers. |
| 3686 |
| 3687 |
3537 } // namespace interpreter | 3688 } // namespace interpreter |
3538 } // namespace internal | 3689 } // namespace internal |
3539 } // namespace v8 | 3690 } // namespace v8 |
OLD | NEW |