OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/assembler-inl.h" | 5 #include "src/assembler-inl.h" |
6 #include "src/wasm/wasm-macro-gen.h" | 6 #include "src/wasm/wasm-macro-gen.h" |
7 #include "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
8 #include "test/cctest/compiler/value-helper.h" | 8 #include "test/cctest/compiler/value-helper.h" |
9 #include "test/cctest/wasm/wasm-run-utils.h" | 9 #include "test/cctest/wasm/wasm-run-utils.h" |
10 | 10 |
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || | 1562 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || |
1563 // V8_TARGET_ARCH_MIPS64 | 1563 // V8_TARGET_ARCH_MIPS64 |
1564 | 1564 |
1565 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 | 1565 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1566 WASM_SIMD_SELECT_TEST(16x8) | 1566 WASM_SIMD_SELECT_TEST(16x8) |
1567 | 1567 |
1568 WASM_SIMD_SELECT_TEST(8x16) | 1568 WASM_SIMD_SELECT_TEST(8x16) |
1569 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 | 1569 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1570 | 1570 |
1571 #if V8_TARGET_ARCH_ARM | 1571 #if V8_TARGET_ARCH_ARM |
| 1572 // Test unary ops with a lane test pattern, all lanes distinct. |
1572 template <typename T> | 1573 template <typename T> |
1573 void RunUnaryPermuteOpTest( | 1574 void RunUnaryLaneOpTest( |
1574 WasmOpcode simd_op, | 1575 WasmOpcode simd_op, |
1575 const std::array<T, kSimd128Size / sizeof(T)>& expected) { | 1576 const std::array<T, kSimd128Size / sizeof(T)>& expected) { |
1576 FLAG_wasm_simd_prototype = true; | 1577 FLAG_wasm_simd_prototype = true; |
1577 WasmRunner<int32_t> r(kExecuteCompiled); | 1578 WasmRunner<int32_t> r(kExecuteCompiled); |
1578 // Set up a test pattern as a global, e.g. [0, 1, 2, 3]. | 1579 // Set up a test pattern as a global, e.g. [0, 1, 2, 3]. |
1579 T* global = r.module().AddGlobal<T>(kWasmS128); | 1580 T* global = r.module().AddGlobal<T>(kWasmS128); |
1580 static const size_t kElems = kSimd128Size / sizeof(T); | 1581 static const size_t kElems = kSimd128Size / sizeof(T); |
1581 for (size_t i = 0; i < kElems; i++) { | 1582 for (size_t i = 0; i < kElems; i++) { |
1582 global[i] = i; | 1583 global[i] = i; |
1583 } | 1584 } |
1584 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_UNOP(simd_op, WASM_GET_GLOBAL(0))), | 1585 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_UNOP(simd_op, WASM_GET_GLOBAL(0))), |
1585 WASM_ONE); | 1586 WASM_ONE); |
1586 | 1587 |
1587 CHECK_EQ(1, r.Call()); | 1588 CHECK_EQ(1, r.Call()); |
1588 for (size_t i = 0; i < kElems; i++) { | 1589 for (size_t i = 0; i < kElems; i++) { |
1589 CHECK_EQ(global[i], expected[i]); | 1590 CHECK_EQ(global[i], expected[i]); |
1590 } | 1591 } |
1591 } | 1592 } |
1592 | 1593 |
1593 WASM_EXEC_COMPILED_TEST(S32x2Reverse) { | 1594 WASM_EXEC_COMPILED_TEST(S32x2Reverse) { |
1594 RunUnaryPermuteOpTest<int32_t>(kExprS32x2Reverse, {{1, 0, 3, 2}}); | 1595 RunUnaryLaneOpTest<int32_t>(kExprS32x2Reverse, {{1, 0, 3, 2}}); |
1595 } | 1596 } |
1596 | 1597 |
1597 WASM_EXEC_COMPILED_TEST(S16x4Reverse) { | 1598 WASM_EXEC_COMPILED_TEST(S16x4Reverse) { |
1598 RunUnaryPermuteOpTest<int16_t>(kExprS16x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4}}); | 1599 RunUnaryLaneOpTest<int16_t>(kExprS16x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4}}); |
1599 } | 1600 } |
1600 | 1601 |
1601 WASM_EXEC_COMPILED_TEST(S16x2Reverse) { | 1602 WASM_EXEC_COMPILED_TEST(S16x2Reverse) { |
1602 RunUnaryPermuteOpTest<int16_t>(kExprS16x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6}}); | 1603 RunUnaryLaneOpTest<int16_t>(kExprS16x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6}}); |
1603 } | 1604 } |
1604 | 1605 |
1605 WASM_EXEC_COMPILED_TEST(S8x8Reverse) { | 1606 WASM_EXEC_COMPILED_TEST(S8x8Reverse) { |
1606 RunUnaryPermuteOpTest<int8_t>(kExprS8x8Reverse, {{7, 6, 5, 4, 3, 2, 1, 0, 15, | 1607 RunUnaryLaneOpTest<int8_t>(kExprS8x8Reverse, {{7, 6, 5, 4, 3, 2, 1, 0, 15, 14, |
1607 14, 13, 12, 11, 10, 9, 8}}); | 1608 13, 12, 11, 10, 9, 8}}); |
1608 } | 1609 } |
1609 | 1610 |
1610 WASM_EXEC_COMPILED_TEST(S8x4Reverse) { | 1611 WASM_EXEC_COMPILED_TEST(S8x4Reverse) { |
1611 RunUnaryPermuteOpTest<int8_t>(kExprS8x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4, 11, | 1612 RunUnaryLaneOpTest<int8_t>(kExprS8x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4, 11, 10, |
1612 10, 9, 8, 15, 14, 13, 12}}); | 1613 9, 8, 15, 14, 13, 12}}); |
1613 } | 1614 } |
1614 | 1615 |
1615 WASM_EXEC_COMPILED_TEST(S8x2Reverse) { | 1616 WASM_EXEC_COMPILED_TEST(S8x2Reverse) { |
1616 RunUnaryPermuteOpTest<int8_t>( | 1617 RunUnaryLaneOpTest<int8_t>(kExprS8x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, |
1617 kExprS8x2Reverse, | 1618 11, 10, 13, 12, 15, 14}}); |
1618 {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14}}); | |
1619 } | 1619 } |
1620 | 1620 |
| 1621 // Test binary ops with two lane test patterns, all lanes distinct. |
1621 template <typename T> | 1622 template <typename T> |
1622 void RunBinaryPermuteOpTest( | 1623 void RunBinaryLaneOpTest( |
1623 WasmOpcode simd_op, | 1624 WasmOpcode simd_op, |
1624 const std::array<T, kSimd128Size / sizeof(T)>& expected) { | 1625 const std::array<T, kSimd128Size / sizeof(T)>& expected) { |
1625 FLAG_wasm_simd_prototype = true; | 1626 FLAG_wasm_simd_prototype = true; |
1626 WasmRunner<int32_t> r(kExecuteCompiled); | 1627 WasmRunner<int32_t> r(kExecuteCompiled); |
1627 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. | 1628 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. |
1628 T* global1 = r.module().AddGlobal<T>(kWasmS128); | 1629 T* global1 = r.module().AddGlobal<T>(kWasmS128); |
1629 T* global2 = r.module().AddGlobal<T>(kWasmS128); | 1630 T* global2 = r.module().AddGlobal<T>(kWasmS128); |
1630 static const size_t kElems = kSimd128Size / sizeof(T); | 1631 static const size_t kElems = kSimd128Size / sizeof(T); |
1631 for (size_t i = 0; i < kElems; i++) { | 1632 for (size_t i = 0; i < kElems; i++) { |
1632 global1[i] = i; | 1633 global1[i] = i; |
1633 global2[i] = kElems + i; | 1634 global2[i] = kElems + i; |
1634 } | 1635 } |
1635 BUILD(r, | 1636 BUILD(r, |
1636 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0), | 1637 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0), |
1637 WASM_GET_GLOBAL(1))), | 1638 WASM_GET_GLOBAL(1))), |
1638 WASM_ONE); | 1639 WASM_ONE); |
1639 | 1640 |
1640 CHECK_EQ(1, r.Call()); | 1641 CHECK_EQ(1, r.Call()); |
1641 for (size_t i = 0; i < expected.size(); i++) { | 1642 for (size_t i = 0; i < expected.size(); i++) { |
1642 CHECK_EQ(global1[i], expected[i]); | 1643 CHECK_EQ(global1[i], expected[i]); |
1643 } | 1644 } |
1644 } | 1645 } |
1645 | 1646 |
| 1647 WASM_EXEC_COMPILED_TEST(F32x4AddHoriz) { |
| 1648 RunBinaryLaneOpTest<float>(kExprF32x4AddHoriz, {{1.0f, 5.0f, 9.0f, 13.0f}}); |
| 1649 } |
| 1650 |
| 1651 WASM_EXEC_COMPILED_TEST(I32x4AddHoriz) { |
| 1652 RunBinaryLaneOpTest<int32_t>(kExprI32x4AddHoriz, {{1, 5, 9, 13}}); |
| 1653 } |
| 1654 |
| 1655 WASM_EXEC_COMPILED_TEST(I16x8AddHoriz) { |
| 1656 RunBinaryLaneOpTest<int16_t>(kExprI16x8AddHoriz, |
| 1657 {{1, 5, 9, 13, 17, 21, 25, 29}}); |
| 1658 } |
| 1659 |
1646 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) { | 1660 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) { |
1647 RunBinaryPermuteOpTest<int32_t>(kExprS32x4ZipLeft, {{0, 4, 1, 5}}); | 1661 RunBinaryLaneOpTest<int32_t>(kExprS32x4ZipLeft, {{0, 4, 1, 5}}); |
1648 } | 1662 } |
1649 | 1663 |
1650 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) { | 1664 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) { |
1651 RunBinaryPermuteOpTest<int32_t>(kExprS32x4ZipRight, {{2, 6, 3, 7}}); | 1665 RunBinaryLaneOpTest<int32_t>(kExprS32x4ZipRight, {{2, 6, 3, 7}}); |
1652 } | 1666 } |
1653 | 1667 |
1654 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) { | 1668 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) { |
1655 RunBinaryPermuteOpTest<int32_t>(kExprS32x4UnzipLeft, {{0, 2, 4, 6}}); | 1669 RunBinaryLaneOpTest<int32_t>(kExprS32x4UnzipLeft, {{0, 2, 4, 6}}); |
1656 } | 1670 } |
1657 | 1671 |
1658 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) { | 1672 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) { |
1659 RunBinaryPermuteOpTest<int32_t>(kExprS32x4UnzipRight, {{1, 3, 5, 7}}); | 1673 RunBinaryLaneOpTest<int32_t>(kExprS32x4UnzipRight, {{1, 3, 5, 7}}); |
1660 } | 1674 } |
1661 | 1675 |
1662 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) { | 1676 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) { |
1663 RunBinaryPermuteOpTest<int32_t>(kExprS32x4TransposeLeft, {{0, 4, 2, 6}}); | 1677 RunBinaryLaneOpTest<int32_t>(kExprS32x4TransposeLeft, {{0, 4, 2, 6}}); |
1664 } | 1678 } |
1665 | 1679 |
1666 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) { | 1680 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) { |
1667 RunBinaryPermuteOpTest<int32_t>(kExprS32x4TransposeRight, {{1, 5, 3, 7}}); | 1681 RunBinaryLaneOpTest<int32_t>(kExprS32x4TransposeRight, {{1, 5, 3, 7}}); |
1668 } | 1682 } |
1669 | 1683 |
1670 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) { | 1684 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) { |
1671 RunBinaryPermuteOpTest<int16_t>(kExprS16x8ZipLeft, | 1685 RunBinaryLaneOpTest<int16_t>(kExprS16x8ZipLeft, {{0, 8, 1, 9, 2, 10, 3, 11}}); |
1672 {{0, 8, 1, 9, 2, 10, 3, 11}}); | |
1673 } | 1686 } |
1674 | 1687 |
1675 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) { | 1688 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) { |
1676 RunBinaryPermuteOpTest<int16_t>(kExprS16x8ZipRight, | 1689 RunBinaryLaneOpTest<int16_t>(kExprS16x8ZipRight, |
1677 {{4, 12, 5, 13, 6, 14, 7, 15}}); | 1690 {{4, 12, 5, 13, 6, 14, 7, 15}}); |
1678 } | 1691 } |
1679 | 1692 |
1680 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) { | 1693 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) { |
1681 RunBinaryPermuteOpTest<int16_t>(kExprS16x8UnzipLeft, | 1694 RunBinaryLaneOpTest<int16_t>(kExprS16x8UnzipLeft, |
1682 {{0, 2, 4, 6, 8, 10, 12, 14}}); | 1695 {{0, 2, 4, 6, 8, 10, 12, 14}}); |
1683 } | 1696 } |
1684 | 1697 |
1685 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) { | 1698 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) { |
1686 RunBinaryPermuteOpTest<int16_t>(kExprS16x8UnzipRight, | 1699 RunBinaryLaneOpTest<int16_t>(kExprS16x8UnzipRight, |
1687 {{1, 3, 5, 7, 9, 11, 13, 15}}); | 1700 {{1, 3, 5, 7, 9, 11, 13, 15}}); |
1688 } | 1701 } |
1689 | 1702 |
1690 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) { | 1703 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) { |
1691 RunBinaryPermuteOpTest<int16_t>(kExprS16x8TransposeLeft, | 1704 RunBinaryLaneOpTest<int16_t>(kExprS16x8TransposeLeft, |
1692 {{0, 8, 2, 10, 4, 12, 6, 14}}); | 1705 {{0, 8, 2, 10, 4, 12, 6, 14}}); |
1693 } | 1706 } |
1694 | 1707 |
1695 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) { | 1708 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) { |
1696 RunBinaryPermuteOpTest<int16_t>(kExprS16x8TransposeRight, | 1709 RunBinaryLaneOpTest<int16_t>(kExprS16x8TransposeRight, |
1697 {{1, 9, 3, 11, 5, 13, 7, 15}}); | 1710 {{1, 9, 3, 11, 5, 13, 7, 15}}); |
1698 } | 1711 } |
1699 | 1712 |
1700 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) { | 1713 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) { |
1701 RunBinaryPermuteOpTest<int8_t>( | 1714 RunBinaryLaneOpTest<int8_t>( |
1702 kExprS8x16ZipLeft, | 1715 kExprS8x16ZipLeft, |
1703 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}); | 1716 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}); |
1704 } | 1717 } |
1705 | 1718 |
1706 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) { | 1719 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) { |
1707 RunBinaryPermuteOpTest<int8_t>( | 1720 RunBinaryLaneOpTest<int8_t>( |
1708 kExprS8x16ZipRight, | 1721 kExprS8x16ZipRight, |
1709 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}); | 1722 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}); |
1710 } | 1723 } |
1711 | 1724 |
1712 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) { | 1725 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) { |
1713 RunBinaryPermuteOpTest<int8_t>( | 1726 RunBinaryLaneOpTest<int8_t>( |
1714 kExprS8x16UnzipLeft, | 1727 kExprS8x16UnzipLeft, |
1715 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}); | 1728 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}); |
1716 } | 1729 } |
1717 | 1730 |
1718 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) { | 1731 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) { |
1719 RunBinaryPermuteOpTest<int8_t>( | 1732 RunBinaryLaneOpTest<int8_t>( |
1720 kExprS8x16UnzipRight, | 1733 kExprS8x16UnzipRight, |
1721 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}); | 1734 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}); |
1722 } | 1735 } |
1723 | 1736 |
1724 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) { | 1737 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) { |
1725 RunBinaryPermuteOpTest<int8_t>( | 1738 RunBinaryLaneOpTest<int8_t>( |
1726 kExprS8x16TransposeLeft, | 1739 kExprS8x16TransposeLeft, |
1727 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}); | 1740 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}); |
1728 } | 1741 } |
1729 | 1742 |
1730 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) { | 1743 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) { |
1731 RunBinaryPermuteOpTest<int8_t>( | 1744 RunBinaryLaneOpTest<int8_t>( |
1732 kExprS8x16TransposeRight, | 1745 kExprS8x16TransposeRight, |
1733 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}); | 1746 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}); |
1734 } | 1747 } |
1735 | 1748 |
1736 template <typename T> | 1749 template <typename T> |
1737 void RunConcatOpTest(WasmOpcode simd_op, int bytes, | 1750 void RunConcatOpTest(WasmOpcode simd_op, int bytes, |
1738 const std::array<T, kSimd128Size / sizeof(T)>& expected) { | 1751 const std::array<T, kSimd128Size / sizeof(T)>& expected) { |
1739 FLAG_wasm_simd_prototype = true; | 1752 FLAG_wasm_simd_prototype = true; |
1740 WasmRunner<int32_t> r(kExecuteCompiled); | 1753 WasmRunner<int32_t> r(kExecuteCompiled); |
1741 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. | 1754 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2194 WASM_SIMD_I32x4_EXTRACT_LANE( | 2207 WASM_SIMD_I32x4_EXTRACT_LANE( |
2195 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); | 2208 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); |
2196 | 2209 |
2197 FOR_INT32_INPUTS(i) { | 2210 FOR_INT32_INPUTS(i) { |
2198 int32_t expected = *i; | 2211 int32_t expected = *i; |
2199 r.module().WriteMemory(&memory[0], expected); | 2212 r.module().WriteMemory(&memory[0], expected); |
2200 CHECK_EQ(expected, r.Call()); | 2213 CHECK_EQ(expected, r.Call()); |
2201 } | 2214 } |
2202 } | 2215 } |
2203 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 2216 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
OLD | NEW |