OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.h" |
9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
10 #include "src/compiler/effect-control-linearizer.h" | 10 #include "src/compiler/effect-control-linearizer.h" |
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 load0, load1, t.start); | 1540 load0, load1, t.start); |
1541 t.Return(t.Use(phi, kMachineTypes[i])); | 1541 t.Return(t.Use(phi, kMachineTypes[i])); |
1542 t.Lower(); | 1542 t.Lower(); |
1543 | 1543 |
1544 CHECK_EQ(IrOpcode::kPhi, phi->opcode()); | 1544 CHECK_EQ(IrOpcode::kPhi, phi->opcode()); |
1545 CHECK_EQ(kMachineTypes[i].representation(), PhiRepresentationOf(phi->op())); | 1545 CHECK_EQ(kMachineTypes[i].representation(), PhiRepresentationOf(phi->op())); |
1546 } | 1546 } |
1547 } | 1547 } |
1548 | 1548 |
1549 | 1549 |
1550 TEST(RunNumberDivide_minus_1_TruncatingToInt32) { | |
1551 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1552 Node* num = t.NumberToInt32(t.Parameter(0)); | |
1553 Node* div = t.NumberDivide(num, t.jsgraph.Constant(-1)); | |
1554 Node* trunc = t.NumberToInt32(div); | |
1555 t.Return(trunc); | |
1556 | |
1557 t.LowerAllNodesAndLowerChanges(); | |
1558 t.GenerateCode(); | |
1559 | |
1560 FOR_INT32_INPUTS(i) { | |
1561 int32_t x = 0 - *i; | |
1562 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1563 } | |
1564 } | |
1565 | |
1566 | |
1567 TEST(RunNumberMultiply_TruncatingToInt32) { | |
1568 int32_t constants[] = {-100, -10, -1, 0, 1, 100, 1000, 3000999}; | |
1569 | |
1570 for (size_t i = 0; i < arraysize(constants); i++) { | |
1571 double k = static_cast<double>(constants[i]); | |
1572 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1573 Node* num = t.NumberToInt32(t.Parameter(0)); | |
1574 Node* mul = t.NumberMultiply(num, t.jsgraph.Constant(k)); | |
1575 Node* trunc = t.NumberToInt32(mul); | |
1576 t.Return(trunc); | |
1577 | |
1578 t.LowerAllNodesAndLowerChanges(); | |
1579 t.GenerateCode(); | |
1580 | |
1581 FOR_INT32_INPUTS(i) { | |
1582 int32_t x = DoubleToInt32(static_cast<double>(*i) * k); | |
1583 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1584 } | |
1585 } | |
1586 } | |
1587 | |
1588 | |
1589 TEST(RunNumberMultiply_TruncatingToUint32) { | |
1590 uint32_t constants[] = {0, 1, 2, 3, 4, 100, 1000, 1024, 2048, 3000999}; | |
1591 | |
1592 for (size_t i = 0; i < arraysize(constants); i++) { | |
1593 double k = static_cast<double>(constants[i]); | |
1594 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1595 Node* num = t.NumberToUint32(t.Parameter(0)); | |
1596 Node* mul = t.NumberMultiply(num, t.jsgraph.Constant(k)); | |
1597 Node* trunc = t.NumberToUint32(mul); | |
1598 t.Return(trunc); | |
1599 | |
1600 t.LowerAllNodesAndLowerChanges(); | |
1601 t.GenerateCode(); | |
1602 | |
1603 FOR_UINT32_INPUTS(i) { | |
1604 uint32_t x = DoubleToUint32(static_cast<double>(*i) * k); | |
1605 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1606 } | |
1607 } | |
1608 } | |
1609 | |
1610 | |
1611 TEST(RunNumberDivide_2_TruncatingToUint32) { | |
1612 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1613 Node* num = t.NumberToUint32(t.Parameter(0)); | |
1614 Node* div = t.NumberDivide(num, t.jsgraph.Constant(2)); | |
1615 Node* trunc = t.NumberToUint32(div); | |
1616 t.Return(trunc); | |
1617 | |
1618 t.LowerAllNodesAndLowerChanges(); | |
1619 t.GenerateCode(); | |
1620 | |
1621 FOR_UINT32_INPUTS(i) { | |
1622 uint32_t x = DoubleToUint32(static_cast<double>(*i / 2.0)); | |
1623 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1624 } | |
1625 } | |
1626 | |
1627 | |
1628 TEST(NumberMultiply_ConstantOutOfRange) { | 1550 TEST(NumberMultiply_ConstantOutOfRange) { |
1629 TestingGraph t(Type::Signed32()); | 1551 TestingGraph t(Type::Signed32()); |
1630 Node* k = t.jsgraph.Constant(1000000023); | 1552 Node* k = t.jsgraph.Constant(1000000023); |
1631 Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k); | 1553 Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k); |
1632 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul); | 1554 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul); |
1633 t.Return(trunc); | 1555 t.Return(trunc); |
1634 t.Lower(); | 1556 t.Lower(); |
1635 | 1557 |
1636 CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode()); | 1558 CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode()); |
1637 } | 1559 } |
(...skipping 19 matching lines...) Expand all Loading... |
1657 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); | 1579 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
1658 Node* use = t.Use(div, MachineType::Int32()); | 1580 Node* use = t.Use(div, MachineType::Int32()); |
1659 t.Return(use); | 1581 t.Return(use); |
1660 t.Lower(); | 1582 t.Lower(); |
1661 | 1583 |
1662 CHECK_EQ(IrOpcode::kInt32Div, use->InputAt(0)->opcode()); | 1584 CHECK_EQ(IrOpcode::kInt32Div, use->InputAt(0)->opcode()); |
1663 } | 1585 } |
1664 } | 1586 } |
1665 | 1587 |
1666 | 1588 |
1667 TEST(RunNumberDivide_TruncatingToInt32) { | |
1668 int32_t constants[] = {-100, -10, -1, 1, 2, 100, 1000, 1024, 2048}; | |
1669 | |
1670 for (size_t i = 0; i < arraysize(constants); i++) { | |
1671 int32_t k = constants[i]; | |
1672 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1673 Node* num = t.NumberToInt32(t.Parameter(0)); | |
1674 Node* div = t.NumberDivide(num, t.jsgraph.Constant(k)); | |
1675 Node* trunc = t.NumberToInt32(div); | |
1676 t.Return(trunc); | |
1677 | |
1678 t.LowerAllNodesAndLowerChanges(); | |
1679 t.GenerateCode(); | |
1680 | |
1681 FOR_INT32_INPUTS(i) { | |
1682 if (*i == INT_MAX) continue; // exclude max int. | |
1683 int32_t x = DoubleToInt32(static_cast<double>(*i) / k); | |
1684 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1685 } | |
1686 } | |
1687 } | |
1688 | |
1689 | |
1690 TEST(NumberDivide_TruncatingToUint32) { | 1589 TEST(NumberDivide_TruncatingToUint32) { |
1691 double constants[] = {1, 3, 100, 1000, 100998348}; | 1590 double constants[] = {1, 3, 100, 1000, 100998348}; |
1692 | 1591 |
1693 for (size_t i = 0; i < arraysize(constants); i++) { | 1592 for (size_t i = 0; i < arraysize(constants); i++) { |
1694 TestingGraph t(Type::Unsigned32()); | 1593 TestingGraph t(Type::Unsigned32()); |
1695 Node* k = t.jsgraph.Constant(constants[i]); | 1594 Node* k = t.jsgraph.Constant(constants[i]); |
1696 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); | 1595 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
1697 Node* use = t.Use(div, MachineType::Uint32()); | 1596 Node* use = t.Use(div, MachineType::Uint32()); |
1698 t.Return(use); | 1597 t.Return(use); |
1699 t.Lower(); | 1598 t.Lower(); |
1700 | 1599 |
1701 CHECK_EQ(IrOpcode::kUint32Div, use->InputAt(0)->opcode()); | 1600 CHECK_EQ(IrOpcode::kUint32Div, use->InputAt(0)->opcode()); |
1702 } | 1601 } |
1703 } | 1602 } |
1704 | 1603 |
1705 | 1604 |
1706 TEST(RunNumberDivide_TruncatingToUint32) { | |
1707 uint32_t constants[] = {100, 10, 1, 1, 2, 4, 1000, 1024, 2048}; | |
1708 | |
1709 for (size_t i = 0; i < arraysize(constants); i++) { | |
1710 uint32_t k = constants[i]; | |
1711 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1712 Node* num = t.NumberToUint32(t.Parameter(0)); | |
1713 Node* div = t.NumberDivide(num, t.jsgraph.Constant(static_cast<double>(k))); | |
1714 Node* trunc = t.NumberToUint32(div); | |
1715 t.Return(trunc); | |
1716 | |
1717 t.LowerAllNodesAndLowerChanges(); | |
1718 t.GenerateCode(); | |
1719 | |
1720 FOR_UINT32_INPUTS(i) { | |
1721 uint32_t x = *i / k; | |
1722 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1723 } | |
1724 } | |
1725 } | |
1726 | |
1727 | |
1728 TEST(NumberDivide_BadConstants) { | 1605 TEST(NumberDivide_BadConstants) { |
1729 { | 1606 { |
1730 TestingGraph t(Type::Signed32()); | 1607 TestingGraph t(Type::Signed32()); |
1731 Node* k = t.jsgraph.Constant(-1); | 1608 Node* k = t.jsgraph.Constant(-1); |
1732 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); | 1609 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
1733 Node* use = t.Use(div, MachineType::Int32()); | 1610 Node* use = t.Use(div, MachineType::Int32()); |
1734 t.Return(use); | 1611 t.Return(use); |
1735 t.Lower(); | 1612 t.Lower(); |
1736 | 1613 |
1737 CHECK_EQ(IrOpcode::kInt32Sub, use->InputAt(0)->opcode()); | 1614 CHECK_EQ(IrOpcode::kInt32Sub, use->InputAt(0)->opcode()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); | 1649 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
1773 Node* use = t.Use(mod, MachineType::Int32()); | 1650 Node* use = t.Use(mod, MachineType::Int32()); |
1774 t.Return(use); | 1651 t.Return(use); |
1775 t.Lower(); | 1652 t.Lower(); |
1776 | 1653 |
1777 CHECK_EQ(IrOpcode::kInt32Mod, use->InputAt(0)->opcode()); | 1654 CHECK_EQ(IrOpcode::kInt32Mod, use->InputAt(0)->opcode()); |
1778 } | 1655 } |
1779 } | 1656 } |
1780 | 1657 |
1781 | 1658 |
1782 TEST(RunNumberModulus_TruncatingToInt32) { | |
1783 int32_t constants[] = {-100, -10, -1, 1, 2, 100, 1000, 1024, 2048}; | |
1784 | |
1785 for (size_t i = 0; i < arraysize(constants); i++) { | |
1786 int32_t k = constants[i]; | |
1787 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1788 Node* num = t.NumberToInt32(t.Parameter(0)); | |
1789 Node* mod = t.NumberModulus(num, t.jsgraph.Constant(k)); | |
1790 Node* trunc = t.NumberToInt32(mod); | |
1791 t.Return(trunc); | |
1792 | |
1793 t.LowerAllNodesAndLowerChanges(); | |
1794 t.GenerateCode(); | |
1795 | |
1796 FOR_INT32_INPUTS(i) { | |
1797 if (*i == INT_MAX) continue; // exclude max int. | |
1798 int32_t x = DoubleToInt32(std::fmod(static_cast<double>(*i), k)); | |
1799 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1800 } | |
1801 } | |
1802 } | |
1803 | |
1804 | |
1805 TEST(NumberModulus_TruncatingToUint32) { | 1659 TEST(NumberModulus_TruncatingToUint32) { |
1806 double constants[] = {1, 3, 100, 1000, 100998348}; | 1660 double constants[] = {1, 3, 100, 1000, 100998348}; |
1807 | 1661 |
1808 for (size_t i = 0; i < arraysize(constants); i++) { | 1662 for (size_t i = 0; i < arraysize(constants); i++) { |
1809 TestingGraph t(Type::Unsigned32()); | 1663 TestingGraph t(Type::Unsigned32()); |
1810 Node* k = t.jsgraph.Constant(constants[i]); | 1664 Node* k = t.jsgraph.Constant(constants[i]); |
1811 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); | 1665 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
1812 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod); | 1666 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod); |
1813 t.Return(trunc); | 1667 t.Return(trunc); |
1814 t.Lower(); | 1668 t.Lower(); |
1815 | 1669 |
1816 CHECK_EQ(IrOpcode::kUint32Mod, t.ret->InputAt(0)->InputAt(0)->opcode()); | 1670 CHECK_EQ(IrOpcode::kUint32Mod, t.ret->InputAt(0)->InputAt(0)->opcode()); |
1817 } | 1671 } |
1818 } | 1672 } |
1819 | 1673 |
1820 | 1674 |
1821 TEST(RunNumberModulus_TruncatingToUint32) { | |
1822 uint32_t constants[] = {1, 2, 100, 1000, 1024, 2048}; | |
1823 | |
1824 for (size_t i = 0; i < arraysize(constants); i++) { | |
1825 uint32_t k = constants[i]; | |
1826 SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged()); | |
1827 Node* num = t.NumberToUint32(t.Parameter(0)); | |
1828 Node* mod = | |
1829 t.NumberModulus(num, t.jsgraph.Constant(static_cast<double>(k))); | |
1830 Node* trunc = t.NumberToUint32(mod); | |
1831 t.Return(trunc); | |
1832 | |
1833 t.LowerAllNodesAndLowerChanges(); | |
1834 t.GenerateCode(); | |
1835 | |
1836 FOR_UINT32_INPUTS(i) { | |
1837 uint32_t x = *i % k; | |
1838 t.CheckNumberCall(static_cast<double>(x), static_cast<double>(*i)); | |
1839 } | |
1840 } | |
1841 } | |
1842 | |
1843 | |
1844 TEST(NumberModulus_Int32) { | 1675 TEST(NumberModulus_Int32) { |
1845 int32_t constants[] = {-100, -10, 1, 4, 100, 1000}; | 1676 int32_t constants[] = {-100, -10, 1, 4, 100, 1000}; |
1846 | 1677 |
1847 for (size_t i = 0; i < arraysize(constants); i++) { | 1678 for (size_t i = 0; i < arraysize(constants); i++) { |
1848 TestingGraph t(Type::Signed32()); | 1679 TestingGraph t(Type::Signed32()); |
1849 Node* k = t.jsgraph.Constant(constants[i]); | 1680 Node* k = t.jsgraph.Constant(constants[i]); |
1850 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); | 1681 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
1851 t.Return(mod); | 1682 t.Return(mod); |
1852 t.Lower(); | 1683 t.Lower(); |
1853 | 1684 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 t.Return(use); | 1747 t.Return(use); |
1917 t.Lower(); | 1748 t.Lower(); |
1918 | 1749 |
1919 CHECK_EQ(d.expected, PhiRepresentationOf(phi->op())); | 1750 CHECK_EQ(d.expected, PhiRepresentationOf(phi->op())); |
1920 } | 1751 } |
1921 } | 1752 } |
1922 | 1753 |
1923 } // namespace compiler | 1754 } // namespace compiler |
1924 } // namespace internal | 1755 } // namespace internal |
1925 } // namespace v8 | 1756 } // namespace v8 |
OLD | NEW |