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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1399773002: [Interpreter] Adds logical and, logical or and comma operators to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a new bytecode to jump by casting the value to boolean. This reduces code size for logical op… Created 5 years, 2 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
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/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 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 "function " + InterpreterTester::function_name() + "(a) {\n" 1630 "function " + InterpreterTester::function_name() + "(a) {\n"
1631 " return (function(x){ return x + 2; })(a);\n" 1631 " return (function(x){ return x + 2; })(a);\n"
1632 "}"); 1632 "}");
1633 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1633 InterpreterTester tester(handles.main_isolate(), source.c_str());
1634 auto callable = tester.GetCallable<Handle<Object>>(); 1634 auto callable = tester.GetCallable<Handle<Object>>();
1635 1635
1636 Handle<i::Object> return_val = callable( 1636 Handle<i::Object> return_val = callable(
1637 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); 1637 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked();
1638 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); 1638 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
1639 } 1639 }
1640
1641
1642 TEST(InterpreterCommaSmi) {
rmcilroy 2015/10/13 15:43:24 I'm not sure these are really useful tests (also t
mythria 2015/10/14 13:33:42 Done.
1643 HandleAndZoneScope handles;
1644 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1645 Register reg(0);
1646 i::Factory* factory = handles.main_isolate()->factory();
1647 builder.set_locals_count(1);
1648 builder.set_parameter_count(0);
1649
1650 builder.LoadLiteral(Smi::FromInt(10))
1651 .StoreAccumulatorInRegister(reg)
1652 .LoadLiteral(Smi::FromInt(300))
1653 .Return();
1654 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1655
1656 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1657 auto callable = tester.GetCallable<>();
1658 Handle<Object> return_value = callable().ToHandleChecked();
1659 Handle<Object> expected_value = factory->NewNumber(300);
1660 CHECK(return_value->SameValue(*expected_value));
1661 }
1662
1663
1664 TEST(InterpreterCommaHeapNumber) {
1665 double lhs_inputs[] = {32.73, 56e-12};
1666 double rhs_inputs[] = {8.3e-27, 32.73};
1667 for (size_t l = 0; l < arraysize(lhs_inputs); l++) {
1668 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
1669 HandleAndZoneScope handles;
1670 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1671 Register reg(0);
1672 i::Factory* factory = handles.main_isolate()->factory();
1673 builder.set_locals_count(1);
1674 builder.set_parameter_count(0);
1675
1676 builder.LoadLiteral(factory->NewNumber(lhs_inputs[l]))
1677 .StoreAccumulatorInRegister(reg)
1678 .LoadLiteral(factory->NewNumber(rhs_inputs[r]))
1679 .Return();
1680 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1681
1682 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1683 auto callable = tester.GetCallable<>();
1684 Handle<Object> return_value = callable().ToHandleChecked();
1685 Handle<Object> expected_value = factory->NewNumber(rhs_inputs[r]);
1686 CHECK(return_value->SameValue(*expected_value));
1687 }
1688 }
1689 }
1690
1691
1692 TEST(InterpreterCommaString) {
1693 HandleAndZoneScope handles;
1694 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1695 Register reg(0);
1696 i::Factory* factory = handles.main_isolate()->factory();
1697 builder.set_locals_count(1);
1698 builder.set_parameter_count(0);
1699
1700 builder.LoadLiteral(factory->NewNumber(20.34))
1701 .StoreAccumulatorInRegister(reg)
1702 .LoadLiteral(factory->NewStringFromAsciiChecked("abc"))
1703 .Return();
1704 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1705
1706 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1707 auto callable = tester.GetCallable<>();
1708 Handle<Object> return_value = callable().ToHandleChecked();
1709 Handle<Object> expected_value = factory->NewStringFromAsciiChecked("abc");
1710 CHECK(return_value->SameValue(*expected_value));
1711 }
1712
1713
1714 TEST(InterpreterLogicalOr) {
1715 int lhs_inputs[] = {0, 1, 12, -345};
1716 int rhs_inputs[] = {12, 0, -456, 1};
1717 for (size_t l = 0; l < arraysize(lhs_inputs); l++) {
1718 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
1719 HandleAndZoneScope handles;
1720 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1721 builder.set_locals_count(1);
1722 builder.set_parameter_count(0);
1723 Register reg(0);
1724 BytecodeLabel label[2];
1725
1726 builder.LoadLiteral(Smi::FromInt(lhs_inputs[l]))
1727 .StoreAccumulatorInRegister(reg)
1728 .CastAccumulatorToBoolean()
1729 .JumpIfFalse(&label[0])
1730 .LoadAccumulatorWithRegister(reg)
1731 .Jump(&label[1])
1732 .Bind(&label[0])
1733 .LoadLiteral(Smi::FromInt(rhs_inputs[r]))
1734 .Bind(&label[1])
1735 .Return();
1736
1737 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1738 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1739 auto callable = tester.GetCallable<>();
1740 Handle<Object> return_value = callable().ToHandleChecked();
1741 int expected_value = lhs_inputs[l];
1742 if (!lhs_inputs[l]) expected_value = rhs_inputs[r];
1743 CHECK_EQ(Smi::cast(*return_value)->value(), expected_value);
1744 }
1745 }
1746 }
1747
1748
1749 TEST(InterpreterLogicalAnd) {
1750 int lhs_inputs[] = {0, 1, 12, -345};
1751 int rhs_inputs[] = {12, 0, -456, 1};
1752 for (size_t l = 0; l < arraysize(lhs_inputs); l++) {
1753 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
1754 HandleAndZoneScope handles;
1755 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1756 builder.set_locals_count(1);
1757 builder.set_parameter_count(0);
1758 Register reg(0);
1759 BytecodeLabel label[2];
1760
1761 builder.LoadLiteral(Smi::FromInt(lhs_inputs[l]))
1762 .StoreAccumulatorInRegister(reg)
1763 .CastAccumulatorToBoolean()
1764 .JumpIfTrue(&label[0])
1765 .LoadAccumulatorWithRegister(reg)
1766 .Jump(&label[1])
1767 .Bind(&label[0])
1768 .LoadLiteral(Smi::FromInt(rhs_inputs[r]))
1769 .Bind(&label[1])
1770 .Return();
1771
1772 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1773 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1774 auto callable = tester.GetCallable<>();
1775 Handle<Object> return_value = callable().ToHandleChecked();
1776 int expected_value = lhs_inputs[l];
1777 if (lhs_inputs[l]) expected_value = rhs_inputs[r];
1778 CHECK_EQ(Smi::cast(*return_value)->value(), expected_value);
1779 }
1780 }
1781 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698