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 "test/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace compiler { | 9 namespace compiler { |
10 | 10 |
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 jnk >>= 32 - lsb; | 1700 jnk >>= 32 - lsb; |
1701 uint32_t msk = ((0xffffffffu >> (32 - width)) << lsb) | jnk; | 1701 uint32_t msk = ((0xffffffffu >> (32 - width)) << lsb) | jnk; |
1702 StreamBuilder m(this, kMachInt32, kMachInt32); | 1702 StreamBuilder m(this, kMachInt32, kMachInt32); |
1703 m.Return(m.Word32Shr(m.Word32And(m.Parameter(0), m.Int32Constant(msk)), | 1703 m.Return(m.Word32Shr(m.Word32And(m.Parameter(0), m.Int32Constant(msk)), |
1704 m.Int32Constant(lsb))); | 1704 m.Int32Constant(lsb))); |
1705 Stream s = m.Build(); | 1705 Stream s = m.Build(); |
1706 ASSERT_EQ(1U, s.size()); | 1706 ASSERT_EQ(1U, s.size()); |
1707 EXPECT_EQ(kArm64Ubfx32, s[0]->arch_opcode()); | 1707 EXPECT_EQ(kArm64Ubfx32, s[0]->arch_opcode()); |
1708 ASSERT_EQ(3U, s[0]->InputCount()); | 1708 ASSERT_EQ(3U, s[0]->InputCount()); |
1709 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); | 1709 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); |
1710 EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2))); | 1710 int32_t actual_width = (lsb + width > 32) ? (32 - lsb) : width; |
| 1711 EXPECT_EQ(actual_width, s.ToInt32(s[0]->InputAt(2))); |
1711 } | 1712 } |
1712 } | 1713 } |
1713 TRACED_FORRANGE(int32_t, lsb, 1, 31) { | 1714 TRACED_FORRANGE(int32_t, lsb, 1, 31) { |
1714 TRACED_FORRANGE(int32_t, width, 1, 32 - lsb) { | 1715 TRACED_FORRANGE(int32_t, width, 1, 32 - lsb) { |
1715 uint32_t jnk = rng()->NextInt(); | 1716 uint32_t jnk = rng()->NextInt(); |
1716 jnk >>= 32 - lsb; | 1717 jnk >>= 32 - lsb; |
1717 uint32_t msk = ((0xffffffffu >> (32 - width)) << lsb) | jnk; | 1718 uint32_t msk = ((0xffffffffu >> (32 - width)) << lsb) | jnk; |
1718 StreamBuilder m(this, kMachInt32, kMachInt32); | 1719 StreamBuilder m(this, kMachInt32, kMachInt32); |
1719 m.Return(m.Word32Shr(m.Word32And(m.Int32Constant(msk), m.Parameter(0)), | 1720 m.Return(m.Word32Shr(m.Word32And(m.Int32Constant(msk), m.Parameter(0)), |
1720 m.Int32Constant(lsb))); | 1721 m.Int32Constant(lsb))); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 uint64_t msk = | 1755 uint64_t msk = |
1755 ((V8_UINT64_C(0xffffffffffffffff) >> (64 - width)) << lsb) | jnk; | 1756 ((V8_UINT64_C(0xffffffffffffffff) >> (64 - width)) << lsb) | jnk; |
1756 StreamBuilder m(this, kMachInt64, kMachInt64); | 1757 StreamBuilder m(this, kMachInt64, kMachInt64); |
1757 m.Return(m.Word64Shr(m.Word64And(m.Int64Constant(msk), m.Parameter(0)), | 1758 m.Return(m.Word64Shr(m.Word64And(m.Int64Constant(msk), m.Parameter(0)), |
1758 m.Int64Constant(lsb))); | 1759 m.Int64Constant(lsb))); |
1759 Stream s = m.Build(); | 1760 Stream s = m.Build(); |
1760 ASSERT_EQ(1U, s.size()); | 1761 ASSERT_EQ(1U, s.size()); |
1761 EXPECT_EQ(kArm64Ubfx, s[0]->arch_opcode()); | 1762 EXPECT_EQ(kArm64Ubfx, s[0]->arch_opcode()); |
1762 ASSERT_EQ(3U, s[0]->InputCount()); | 1763 ASSERT_EQ(3U, s[0]->InputCount()); |
1763 EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1))); | 1764 EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1))); |
1764 EXPECT_EQ(width, s.ToInt64(s[0]->InputAt(2))); | 1765 int64_t actual_width = (lsb + width > 64) ? (64 - lsb) : width; |
| 1766 EXPECT_EQ(actual_width, s.ToInt64(s[0]->InputAt(2))); |
1765 } | 1767 } |
1766 } | 1768 } |
1767 } | 1769 } |
1768 | 1770 |
1769 | 1771 |
1770 TEST_F(InstructionSelectorTest, Word32AndWithImmediateWithWord32Shr) { | 1772 TEST_F(InstructionSelectorTest, Word32AndWithImmediateWithWord32Shr) { |
1771 TRACED_FORRANGE(int32_t, lsb, 1, 31) { | 1773 TRACED_FORRANGE(int32_t, lsb, 1, 31) { |
1772 TRACED_FORRANGE(int32_t, width, 1, 31) { | 1774 TRACED_FORRANGE(int32_t, width, 1, 31) { |
1773 uint32_t msk = (1 << width) - 1; | 1775 uint32_t msk = (1 << width) - 1; |
1774 StreamBuilder m(this, kMachInt32, kMachInt32); | 1776 StreamBuilder m(this, kMachInt32, kMachInt32); |
(...skipping 11 matching lines...) Expand all Loading... |
1786 TRACED_FORRANGE(int32_t, width, 1, 31) { | 1788 TRACED_FORRANGE(int32_t, width, 1, 31) { |
1787 uint32_t msk = (1 << width) - 1; | 1789 uint32_t msk = (1 << width) - 1; |
1788 StreamBuilder m(this, kMachInt32, kMachInt32); | 1790 StreamBuilder m(this, kMachInt32, kMachInt32); |
1789 m.Return(m.Word32And(m.Int32Constant(msk), | 1791 m.Return(m.Word32And(m.Int32Constant(msk), |
1790 m.Word32Shr(m.Parameter(0), m.Int32Constant(lsb)))); | 1792 m.Word32Shr(m.Parameter(0), m.Int32Constant(lsb)))); |
1791 Stream s = m.Build(); | 1793 Stream s = m.Build(); |
1792 ASSERT_EQ(1U, s.size()); | 1794 ASSERT_EQ(1U, s.size()); |
1793 EXPECT_EQ(kArm64Ubfx32, s[0]->arch_opcode()); | 1795 EXPECT_EQ(kArm64Ubfx32, s[0]->arch_opcode()); |
1794 ASSERT_EQ(3U, s[0]->InputCount()); | 1796 ASSERT_EQ(3U, s[0]->InputCount()); |
1795 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); | 1797 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); |
1796 EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2))); | 1798 int32_t actual_width = (lsb + width > 32) ? (32 - lsb) : width; |
| 1799 EXPECT_EQ(actual_width, s.ToInt32(s[0]->InputAt(2))); |
1797 } | 1800 } |
1798 } | 1801 } |
1799 } | 1802 } |
1800 | 1803 |
1801 | 1804 |
1802 TEST_F(InstructionSelectorTest, Word64AndWithImmediateWithWord64Shr) { | 1805 TEST_F(InstructionSelectorTest, Word64AndWithImmediateWithWord64Shr) { |
1803 TRACED_FORRANGE(int32_t, lsb, 1, 31) { | 1806 TRACED_FORRANGE(int64_t, lsb, 1, 63) { |
1804 TRACED_FORRANGE(int32_t, width, 1, 31) { | 1807 TRACED_FORRANGE(int64_t, width, 1, 63) { |
1805 uint64_t msk = (V8_UINT64_C(1) << width) - 1; | 1808 uint64_t msk = (V8_UINT64_C(1) << width) - 1; |
1806 StreamBuilder m(this, kMachInt64, kMachInt64); | 1809 StreamBuilder m(this, kMachInt64, kMachInt64); |
1807 m.Return(m.Word64And(m.Word64Shr(m.Parameter(0), m.Int64Constant(lsb)), | 1810 m.Return(m.Word64And(m.Word64Shr(m.Parameter(0), m.Int64Constant(lsb)), |
1808 m.Int64Constant(msk))); | 1811 m.Int64Constant(msk))); |
1809 Stream s = m.Build(); | 1812 Stream s = m.Build(); |
1810 ASSERT_EQ(1U, s.size()); | 1813 ASSERT_EQ(1U, s.size()); |
1811 EXPECT_EQ(kArm64Ubfx, s[0]->arch_opcode()); | 1814 EXPECT_EQ(kArm64Ubfx, s[0]->arch_opcode()); |
1812 ASSERT_EQ(3U, s[0]->InputCount()); | 1815 ASSERT_EQ(3U, s[0]->InputCount()); |
1813 EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1))); | 1816 EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1))); |
1814 EXPECT_EQ(width, s.ToInt64(s[0]->InputAt(2))); | 1817 int64_t actual_width = (lsb + width > 64) ? (64 - lsb) : width; |
| 1818 EXPECT_EQ(actual_width, s.ToInt64(s[0]->InputAt(2))); |
1815 } | 1819 } |
1816 } | 1820 } |
1817 TRACED_FORRANGE(int32_t, lsb, 1, 31) { | 1821 TRACED_FORRANGE(int64_t, lsb, 1, 63) { |
1818 TRACED_FORRANGE(int32_t, width, 1, 31) { | 1822 TRACED_FORRANGE(int64_t, width, 1, 63) { |
1819 uint64_t msk = (V8_UINT64_C(1) << width) - 1; | 1823 uint64_t msk = (V8_UINT64_C(1) << width) - 1; |
1820 StreamBuilder m(this, kMachInt64, kMachInt64); | 1824 StreamBuilder m(this, kMachInt64, kMachInt64); |
1821 m.Return(m.Word64And(m.Int64Constant(msk), | 1825 m.Return(m.Word64And(m.Int64Constant(msk), |
1822 m.Word64Shr(m.Parameter(0), m.Int64Constant(lsb)))); | 1826 m.Word64Shr(m.Parameter(0), m.Int64Constant(lsb)))); |
1823 Stream s = m.Build(); | 1827 Stream s = m.Build(); |
1824 ASSERT_EQ(1U, s.size()); | 1828 ASSERT_EQ(1U, s.size()); |
1825 EXPECT_EQ(kArm64Ubfx, s[0]->arch_opcode()); | 1829 EXPECT_EQ(kArm64Ubfx, s[0]->arch_opcode()); |
1826 ASSERT_EQ(3U, s[0]->InputCount()); | 1830 ASSERT_EQ(3U, s[0]->InputCount()); |
1827 EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1))); | 1831 EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1))); |
1828 EXPECT_EQ(width, s.ToInt64(s[0]->InputAt(2))); | 1832 EXPECT_EQ(width, s.ToInt64(s[0]->InputAt(2))); |
(...skipping 19 matching lines...) Expand all Loading... |
1848 ASSERT_EQ(2U, s[1]->InputCount()); | 1852 ASSERT_EQ(2U, s[1]->InputCount()); |
1849 EXPECT_EQ(s.ToVreg(s[0]->Output()), s.ToVreg(s[1]->InputAt(0))); | 1853 EXPECT_EQ(s.ToVreg(s[0]->Output()), s.ToVreg(s[1]->InputAt(0))); |
1850 EXPECT_EQ(32, s.ToInt64(s[1]->InputAt(1))); | 1854 EXPECT_EQ(32, s.ToInt64(s[1]->InputAt(1))); |
1851 ASSERT_EQ(1U, s[1]->OutputCount()); | 1855 ASSERT_EQ(1U, s[1]->OutputCount()); |
1852 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[1]->Output())); | 1856 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[1]->Output())); |
1853 } | 1857 } |
1854 | 1858 |
1855 } // namespace compiler | 1859 } // namespace compiler |
1856 } // namespace internal | 1860 } // namespace internal |
1857 } // namespace v8 | 1861 } // namespace v8 |
OLD | NEW |