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 "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 #include "test/cctest/compiler/value-helper.h" | 7 #include "test/cctest/compiler/value-helper.h" |
8 #include "test/cctest/wasm/wasm-run-utils.h" | 8 #include "test/cctest/wasm/wasm-run-utils.h" |
9 #include "test/common/wasm/wasm-macro-gen.h" | 9 #include "test/common/wasm/wasm-macro-gen.h" |
10 | 10 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 x, WASM_SIMD_OP(kExprI16x8ExtractLane), TO_BYTE(lane) | 386 x, WASM_SIMD_OP(kExprI16x8ExtractLane), TO_BYTE(lane) |
387 #define WASM_SIMD_I16x8_REPLACE_LANE(lane, x, y) \ | 387 #define WASM_SIMD_I16x8_REPLACE_LANE(lane, x, y) \ |
388 x, y, WASM_SIMD_OP(kExprI16x8ReplaceLane), TO_BYTE(lane) | 388 x, y, WASM_SIMD_OP(kExprI16x8ReplaceLane), TO_BYTE(lane) |
389 | 389 |
390 #define WASM_SIMD_I8x16_SPLAT(x) x, WASM_SIMD_OP(kExprI8x16Splat) | 390 #define WASM_SIMD_I8x16_SPLAT(x) x, WASM_SIMD_OP(kExprI8x16Splat) |
391 #define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \ | 391 #define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \ |
392 x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane) | 392 x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane) |
393 #define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \ | 393 #define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \ |
394 x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane) | 394 x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane) |
395 | 395 |
| 396 #define WASM_SIMD_S32x4_SHUFFLE_OP(opcode, m, x, y) \ |
| 397 x, y, WASM_SIMD_OP(opcode), TO_BYTE(m[0]), TO_BYTE(m[1]), TO_BYTE(m[2]), \ |
| 398 TO_BYTE(m[3]) |
| 399 #define WASM_SIMD_S16x8_SHUFFLE_OP(opcode, m, x, y) \ |
| 400 x, y, WASM_SIMD_OP(opcode), TO_BYTE(m[0]), TO_BYTE(m[1]), TO_BYTE(m[2]), \ |
| 401 TO_BYTE(m[3]), TO_BYTE(m[4]), TO_BYTE(m[5]), TO_BYTE(m[6]), \ |
| 402 TO_BYTE(m[7]) |
| 403 #define WASM_SIMD_S8x16_SHUFFLE_OP(opcode, m, x, y) \ |
| 404 x, y, WASM_SIMD_OP(opcode), TO_BYTE(m[0]), TO_BYTE(m[1]), TO_BYTE(m[2]), \ |
| 405 TO_BYTE(m[3]), TO_BYTE(m[4]), TO_BYTE(m[5]), TO_BYTE(m[6]), \ |
| 406 TO_BYTE(m[7]), TO_BYTE(m[8]), TO_BYTE(m[9]), TO_BYTE(m[10]), \ |
| 407 TO_BYTE(m[11]), TO_BYTE(m[12]), TO_BYTE(m[13]), TO_BYTE(m[14]), \ |
| 408 TO_BYTE(m[15]) |
| 409 |
396 // Skip FP tests involving extremely large or extremely small values, which | 410 // Skip FP tests involving extremely large or extremely small values, which |
397 // may fail due to non-IEEE-754 SIMD arithmetic on some platforms. | 411 // may fail due to non-IEEE-754 SIMD arithmetic on some platforms. |
398 bool SkipFPValue(float x) { | 412 bool SkipFPValue(float x) { |
399 float abs_x = std::fabs(x); | 413 float abs_x = std::fabs(x); |
400 const float kSmallFloatThreshold = 1.0e-32f; | 414 const float kSmallFloatThreshold = 1.0e-32f; |
401 const float kLargeFloatThreshold = 1.0e32f; | 415 const float kLargeFloatThreshold = 1.0e32f; |
402 return abs_x != 0.0f && // 0 or -0 are fine. | 416 return abs_x != 0.0f && // 0 or -0 are fine. |
403 (abs_x < kSmallFloatThreshold || abs_x > kLargeFloatThreshold); | 417 (abs_x < kSmallFloatThreshold || abs_x > kLargeFloatThreshold); |
404 } | 418 } |
405 | 419 |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 WASM_SIMD_SELECT_TEST(32x4) | 1577 WASM_SIMD_SELECT_TEST(32x4) |
1564 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || | 1578 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || |
1565 // V8_TARGET_ARCH_MIPS64 | 1579 // V8_TARGET_ARCH_MIPS64 |
1566 | 1580 |
1567 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 | 1581 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1568 WASM_SIMD_SELECT_TEST(16x8) | 1582 WASM_SIMD_SELECT_TEST(16x8) |
1569 | 1583 |
1570 WASM_SIMD_SELECT_TEST(8x16) | 1584 WASM_SIMD_SELECT_TEST(8x16) |
1571 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 | 1585 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1572 | 1586 |
1573 #if V8_TARGET_ARCH_ARM | |
1574 // Test unary ops with a lane test pattern, all lanes distinct. | |
1575 template <typename T> | |
1576 void RunUnaryLaneOpTest( | |
1577 WasmOpcode simd_op, | |
1578 const std::array<T, kSimd128Size / sizeof(T)>& expected) { | |
1579 FLAG_wasm_simd_prototype = true; | |
1580 WasmRunner<int32_t> r(kExecuteCompiled); | |
1581 // Set up a test pattern as a global, e.g. [0, 1, 2, 3]. | |
1582 T* global = r.module().AddGlobal<T>(kWasmS128); | |
1583 static const size_t kElems = kSimd128Size / sizeof(T); | |
1584 for (size_t i = 0; i < kElems; i++) { | |
1585 global[i] = i; | |
1586 } | |
1587 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_UNOP(simd_op, WASM_GET_GLOBAL(0))), | |
1588 WASM_ONE); | |
1589 | |
1590 CHECK_EQ(1, r.Call()); | |
1591 for (size_t i = 0; i < kElems; i++) { | |
1592 CHECK_EQ(global[i], expected[i]); | |
1593 } | |
1594 } | |
1595 | |
1596 WASM_EXEC_COMPILED_TEST(S32x2Reverse) { | |
1597 RunUnaryLaneOpTest<int32_t>(kExprS32x2Reverse, {{1, 0, 3, 2}}); | |
1598 } | |
1599 | |
1600 WASM_EXEC_COMPILED_TEST(S16x4Reverse) { | |
1601 RunUnaryLaneOpTest<int16_t>(kExprS16x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4}}); | |
1602 } | |
1603 | |
1604 WASM_EXEC_COMPILED_TEST(S16x2Reverse) { | |
1605 RunUnaryLaneOpTest<int16_t>(kExprS16x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6}}); | |
1606 } | |
1607 | |
1608 WASM_EXEC_COMPILED_TEST(S8x8Reverse) { | |
1609 RunUnaryLaneOpTest<int8_t>(kExprS8x8Reverse, {{7, 6, 5, 4, 3, 2, 1, 0, 15, 14, | |
1610 13, 12, 11, 10, 9, 8}}); | |
1611 } | |
1612 | |
1613 WASM_EXEC_COMPILED_TEST(S8x4Reverse) { | |
1614 RunUnaryLaneOpTest<int8_t>(kExprS8x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4, 11, 10, | |
1615 9, 8, 15, 14, 13, 12}}); | |
1616 } | |
1617 | |
1618 WASM_EXEC_COMPILED_TEST(S8x2Reverse) { | |
1619 RunUnaryLaneOpTest<int8_t>(kExprS8x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, | |
1620 11, 10, 13, 12, 15, 14}}); | |
1621 } | |
1622 #endif // V8_TARGET_ARCH_ARM | |
1623 | |
1624 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 | 1587 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1625 // Test binary ops with two lane test patterns, all lanes distinct. | 1588 // Test binary ops with two lane test patterns, all lanes distinct. |
1626 template <typename T> | 1589 template <typename T> |
1627 void RunBinaryLaneOpTest( | 1590 void RunBinaryLaneOpTest( |
1628 WasmOpcode simd_op, | 1591 WasmOpcode simd_op, |
1629 const std::array<T, kSimd128Size / sizeof(T)>& expected) { | 1592 const std::array<T, kSimd128Size / sizeof(T)>& expected) { |
1630 FLAG_wasm_simd_prototype = true; | 1593 FLAG_wasm_simd_prototype = true; |
1631 WasmRunner<int32_t> r(kExecuteCompiled); | 1594 WasmRunner<int32_t> r(kExecuteCompiled); |
1632 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. | 1595 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. |
1633 T* global1 = r.module().AddGlobal<T>(kWasmS128); | 1596 T* src0 = r.module().AddGlobal<T>(kWasmS128); |
1634 T* global2 = r.module().AddGlobal<T>(kWasmS128); | 1597 T* src1 = r.module().AddGlobal<T>(kWasmS128); |
1635 static const size_t kElems = kSimd128Size / sizeof(T); | 1598 static const int kElems = kSimd128Size / sizeof(T); |
1636 for (size_t i = 0; i < kElems; i++) { | 1599 for (int i = 0; i < kElems; i++) { |
1637 global1[i] = static_cast<T>(i); | 1600 src0[i] = i; |
1638 global2[i] = static_cast<T>(kElems + i); | 1601 src1[i] = kElems + i; |
1639 } | 1602 } |
1640 BUILD(r, | 1603 switch (simd_op) { |
1641 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0), | 1604 case kExprS32x4Shuffle: { |
1642 WASM_GET_GLOBAL(1))), | 1605 BUILD(r, |
1643 WASM_ONE); | 1606 WASM_SET_GLOBAL(0, WASM_SIMD_S32x4_SHUFFLE_OP(simd_op, expected, |
| 1607 WASM_GET_GLOBAL(0), |
| 1608 WASM_GET_GLOBAL(1))), |
| 1609 WASM_ONE); |
| 1610 break; |
| 1611 } |
| 1612 case kExprS16x8Shuffle: { |
| 1613 BUILD(r, |
| 1614 WASM_SET_GLOBAL(0, WASM_SIMD_S16x8_SHUFFLE_OP(simd_op, expected, |
| 1615 WASM_GET_GLOBAL(0), |
| 1616 WASM_GET_GLOBAL(1))), |
| 1617 WASM_ONE); |
| 1618 break; |
| 1619 } |
| 1620 case kExprS8x16Shuffle: { |
| 1621 BUILD(r, |
| 1622 WASM_SET_GLOBAL(0, WASM_SIMD_S8x16_SHUFFLE_OP(simd_op, expected, |
| 1623 WASM_GET_GLOBAL(0), |
| 1624 WASM_GET_GLOBAL(1))), |
| 1625 WASM_ONE); |
| 1626 break; |
| 1627 } |
| 1628 default: { |
| 1629 BUILD(r, |
| 1630 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0), |
| 1631 WASM_GET_GLOBAL(1))), |
| 1632 WASM_ONE); |
| 1633 break; |
| 1634 } |
| 1635 } |
1644 | 1636 |
1645 CHECK_EQ(1, r.Call()); | 1637 CHECK_EQ(1, r.Call()); |
1646 for (size_t i = 0; i < expected.size(); i++) { | 1638 for (size_t i = 0; i < expected.size(); i++) { |
1647 CHECK_EQ(global1[i], expected[i]); | 1639 CHECK_EQ(src0[i], expected[i]); |
1648 } | 1640 } |
1649 } | 1641 } |
1650 | 1642 |
1651 WASM_EXEC_COMPILED_TEST(I32x4AddHoriz) { | 1643 WASM_EXEC_COMPILED_TEST(I32x4AddHoriz) { |
1652 RunBinaryLaneOpTest<int32_t>(kExprI32x4AddHoriz, {{1, 5, 9, 13}}); | 1644 RunBinaryLaneOpTest<int32_t>(kExprI32x4AddHoriz, {{1, 5, 9, 13}}); |
1653 } | 1645 } |
1654 | 1646 |
1655 WASM_EXEC_COMPILED_TEST(I16x8AddHoriz) { | 1647 WASM_EXEC_COMPILED_TEST(I16x8AddHoriz) { |
1656 RunBinaryLaneOpTest<int16_t>(kExprI16x8AddHoriz, | 1648 RunBinaryLaneOpTest<int16_t>(kExprI16x8AddHoriz, |
1657 {{1, 5, 9, 13, 17, 21, 25, 29}}); | 1649 {{1, 5, 9, 13, 17, 21, 25, 29}}); |
1658 } | 1650 } |
1659 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 | 1651 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1660 | 1652 |
1661 #if V8_TARGET_ARCH_ARM | 1653 #if V8_TARGET_ARCH_ARM |
1662 WASM_EXEC_COMPILED_TEST(F32x4AddHoriz) { | 1654 WASM_EXEC_COMPILED_TEST(F32x4AddHoriz) { |
1663 RunBinaryLaneOpTest<float>(kExprF32x4AddHoriz, {{1.0f, 5.0f, 9.0f, 13.0f}}); | 1655 RunBinaryLaneOpTest<float>(kExprF32x4AddHoriz, {{1.0f, 5.0f, 9.0f, 13.0f}}); |
1664 } | 1656 } |
1665 | 1657 |
| 1658 // Test some regular shuffles that may have special handling on some targets. |
| 1659 // Test a normal and unary versions (where second operand isn't used). |
1666 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) { | 1660 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) { |
1667 RunBinaryLaneOpTest<int32_t>(kExprS32x4ZipLeft, {{0, 4, 1, 5}}); | 1661 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 4, 1, 5}}); |
| 1662 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 0, 1, 1}}); |
1668 } | 1663 } |
1669 | 1664 |
1670 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) { | 1665 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) { |
1671 RunBinaryLaneOpTest<int32_t>(kExprS32x4ZipRight, {{2, 6, 3, 7}}); | 1666 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{2, 6, 3, 7}}); |
| 1667 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{2, 2, 3, 3}}); |
1672 } | 1668 } |
1673 | 1669 |
1674 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) { | 1670 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) { |
1675 RunBinaryLaneOpTest<int32_t>(kExprS32x4UnzipLeft, {{0, 2, 4, 6}}); | 1671 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 2, 4, 6}}); |
| 1672 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 2, 0, 2}}); |
1676 } | 1673 } |
1677 | 1674 |
1678 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) { | 1675 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) { |
1679 RunBinaryLaneOpTest<int32_t>(kExprS32x4UnzipRight, {{1, 3, 5, 7}}); | 1676 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 3, 5, 7}}); |
| 1677 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 3, 1, 3}}); |
1680 } | 1678 } |
1681 | 1679 |
1682 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) { | 1680 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) { |
1683 RunBinaryLaneOpTest<int32_t>(kExprS32x4TransposeLeft, {{0, 4, 2, 6}}); | 1681 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 4, 2, 6}}); |
| 1682 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 0, 2, 2}}); |
1684 } | 1683 } |
1685 | 1684 |
1686 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) { | 1685 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) { |
1687 RunBinaryLaneOpTest<int32_t>(kExprS32x4TransposeRight, {{1, 5, 3, 7}}); | 1686 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 5, 3, 7}}); |
| 1687 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 1, 3, 3}}); |
| 1688 } |
| 1689 |
| 1690 // Reverses are only unary. |
| 1691 WASM_EXEC_COMPILED_TEST(S32x2Reverse) { |
| 1692 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 0, 3, 2}}); |
1688 } | 1693 } |
1689 | 1694 |
1690 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) { | 1695 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) { |
1691 RunBinaryLaneOpTest<int16_t>(kExprS16x8ZipLeft, {{0, 8, 1, 9, 2, 10, 3, 11}}); | 1696 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 8, 1, 9, 2, 10, 3, 11}}); |
| 1697 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 0, 1, 1, 2, 2, 3, 3}}); |
1692 } | 1698 } |
1693 | 1699 |
1694 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) { | 1700 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) { |
1695 RunBinaryLaneOpTest<int16_t>(kExprS16x8ZipRight, | 1701 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, |
1696 {{4, 12, 5, 13, 6, 14, 7, 15}}); | 1702 {{4, 12, 5, 13, 6, 14, 7, 15}}); |
| 1703 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{4, 4, 5, 5, 6, 6, 7, 7}}); |
1697 } | 1704 } |
1698 | 1705 |
1699 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) { | 1706 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) { |
1700 RunBinaryLaneOpTest<int16_t>(kExprS16x8UnzipLeft, | 1707 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, |
1701 {{0, 2, 4, 6, 8, 10, 12, 14}}); | 1708 {{0, 2, 4, 6, 8, 10, 12, 14}}); |
| 1709 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 2, 4, 6, 0, 2, 4, 6}}); |
1702 } | 1710 } |
1703 | 1711 |
1704 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) { | 1712 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) { |
1705 RunBinaryLaneOpTest<int16_t>(kExprS16x8UnzipRight, | 1713 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, |
1706 {{1, 3, 5, 7, 9, 11, 13, 15}}); | 1714 {{1, 3, 5, 7, 9, 11, 13, 15}}); |
| 1715 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{1, 3, 5, 7, 1, 3, 5, 7}}); |
1707 } | 1716 } |
1708 | 1717 |
1709 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) { | 1718 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) { |
1710 RunBinaryLaneOpTest<int16_t>(kExprS16x8TransposeLeft, | 1719 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, |
1711 {{0, 8, 2, 10, 4, 12, 6, 14}}); | 1720 {{0, 8, 2, 10, 4, 12, 6, 14}}); |
| 1721 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 0, 2, 2, 4, 4, 6, 6}}); |
1712 } | 1722 } |
1713 | 1723 |
1714 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) { | 1724 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) { |
1715 RunBinaryLaneOpTest<int16_t>(kExprS16x8TransposeRight, | 1725 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, |
1716 {{1, 9, 3, 11, 5, 13, 7, 15}}); | 1726 {{1, 9, 3, 11, 5, 13, 7, 15}}); |
| 1727 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{1, 1, 3, 3, 5, 5, 7, 7}}); |
| 1728 } |
| 1729 |
| 1730 WASM_EXEC_COMPILED_TEST(S16x4Reverse) { |
| 1731 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{3, 2, 1, 0, 7, 6, 5, 4}}); |
| 1732 } |
| 1733 |
| 1734 WASM_EXEC_COMPILED_TEST(S16x2Reverse) { |
| 1735 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{1, 0, 3, 2, 5, 4, 7, 6}}); |
1717 } | 1736 } |
1718 | 1737 |
1719 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) { | 1738 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) { |
1720 RunBinaryLaneOpTest<int8_t>( | 1739 RunBinaryLaneOpTest<int8_t>( |
1721 kExprS8x16ZipLeft, | 1740 kExprS8x16Shuffle, |
1722 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}); | 1741 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}); |
| 1742 RunBinaryLaneOpTest<int8_t>( |
| 1743 kExprS8x16Shuffle, {{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}}); |
1723 } | 1744 } |
1724 | 1745 |
1725 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) { | 1746 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) { |
1726 RunBinaryLaneOpTest<int8_t>( | 1747 RunBinaryLaneOpTest<int8_t>( |
1727 kExprS8x16ZipRight, | 1748 kExprS8x16Shuffle, |
1728 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}); | 1749 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}); |
| 1750 RunBinaryLaneOpTest<int8_t>( |
| 1751 kExprS8x16Shuffle, |
| 1752 {{8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15}}); |
1729 } | 1753 } |
1730 | 1754 |
1731 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) { | 1755 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) { |
1732 RunBinaryLaneOpTest<int8_t>( | 1756 RunBinaryLaneOpTest<int8_t>( |
1733 kExprS8x16UnzipLeft, | 1757 kExprS8x16Shuffle, |
1734 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}); | 1758 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}); |
| 1759 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{0, 2, 4, 6, 8, 10, 12, 14, 0, |
| 1760 2, 4, 6, 8, 10, 12, 14}}); |
1735 } | 1761 } |
1736 | 1762 |
1737 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) { | 1763 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) { |
1738 RunBinaryLaneOpTest<int8_t>( | 1764 RunBinaryLaneOpTest<int8_t>( |
1739 kExprS8x16UnzipRight, | 1765 kExprS8x16Shuffle, |
1740 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}); | 1766 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}); |
| 1767 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{1, 3, 5, 7, 9, 11, 13, 15, 1, |
| 1768 3, 5, 7, 9, 11, 13, 15}}); |
1741 } | 1769 } |
1742 | 1770 |
1743 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) { | 1771 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) { |
1744 RunBinaryLaneOpTest<int8_t>( | 1772 RunBinaryLaneOpTest<int8_t>( |
1745 kExprS8x16TransposeLeft, | 1773 kExprS8x16Shuffle, |
1746 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}); | 1774 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}); |
| 1775 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{0, 0, 2, 2, 4, 4, 6, 6, 8, 8, |
| 1776 10, 10, 12, 12, 14, 14}}); |
1747 } | 1777 } |
1748 | 1778 |
1749 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) { | 1779 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) { |
1750 RunBinaryLaneOpTest<int8_t>( | 1780 RunBinaryLaneOpTest<int8_t>( |
1751 kExprS8x16TransposeRight, | 1781 kExprS8x16Shuffle, |
1752 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}); | 1782 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}); |
| 1783 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{1, 1, 3, 3, 5, 5, 7, 7, 9, 9, |
| 1784 11, 11, 13, 13, 15, 15}}); |
1753 } | 1785 } |
1754 | 1786 |
| 1787 WASM_EXEC_COMPILED_TEST(S8x8Reverse) { |
| 1788 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{7, 6, 5, 4, 3, 2, 1, 0, 15, |
| 1789 14, 13, 12, 11, 10, 9, 8}}); |
| 1790 } |
| 1791 |
| 1792 WASM_EXEC_COMPILED_TEST(S8x4Reverse) { |
| 1793 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{3, 2, 1, 0, 7, 6, 5, 4, 11, |
| 1794 10, 9, 8, 15, 14, 13, 12}}); |
| 1795 } |
| 1796 |
| 1797 WASM_EXEC_COMPILED_TEST(S8x2Reverse) { |
| 1798 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, |
| 1799 11, 10, 13, 12, 15, 14}}); |
| 1800 } |
| 1801 |
| 1802 // Test shuffles that concatenate the two vectors. |
1755 template <typename T> | 1803 template <typename T> |
1756 void RunConcatOpTest(WasmOpcode simd_op, int bytes, | 1804 void RunConcatOpTest(WasmOpcode simd_op) { |
1757 const std::array<T, kSimd128Size / sizeof(T)>& expected) { | 1805 static const int kLanes = kSimd128Size / sizeof(T); |
1758 FLAG_wasm_simd_prototype = true; | 1806 std::array<T, kLanes> expected; |
1759 WasmRunner<int32_t> r(kExecuteCompiled); | 1807 for (int bias = 1; bias < kLanes; bias++) { |
1760 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. | 1808 int i = 0; |
1761 T* global1 = r.module().AddGlobal<T>(kWasmS128); | 1809 // last kLanes - bias bytes of first vector. |
1762 T* global2 = r.module().AddGlobal<T>(kWasmS128); | 1810 for (int j = bias; j < kLanes; j++) { |
1763 static const size_t kElems = kSimd128Size / sizeof(T); | 1811 expected[i++] = j; |
1764 for (size_t i = 0; i < kElems; i++) { | 1812 } |
1765 global1[i] = i; | 1813 // first bias lanes of second vector |
1766 global2[i] = kElems + i; | 1814 for (int j = 0; j < bias; j++) { |
1767 } | 1815 expected[i++] = j + kLanes; |
1768 BUILD( | 1816 } |
1769 r, | 1817 RunBinaryLaneOpTest<T>(simd_op, expected); |
1770 WASM_SET_GLOBAL(0, WASM_SIMD_CONCAT_OP(simd_op, bytes, WASM_GET_GLOBAL(0), | |
1771 WASM_GET_GLOBAL(1))), | |
1772 WASM_ONE); | |
1773 | |
1774 CHECK_EQ(1, r.Call()); | |
1775 for (size_t i = 0; i < expected.size(); i++) { | |
1776 CHECK_EQ(global1[i], expected[i]); | |
1777 } | 1818 } |
1778 } | 1819 } |
1779 | 1820 |
| 1821 WASM_EXEC_COMPILED_TEST(S32x4Concat) { |
| 1822 RunConcatOpTest<int32_t>(kExprS32x4Shuffle); |
| 1823 } |
| 1824 |
| 1825 WASM_EXEC_COMPILED_TEST(S16x8Concat) { |
| 1826 RunConcatOpTest<int16_t>(kExprS16x8Shuffle); |
| 1827 } |
| 1828 |
1780 WASM_EXEC_COMPILED_TEST(S8x16Concat) { | 1829 WASM_EXEC_COMPILED_TEST(S8x16Concat) { |
1781 std::array<int8_t, kSimd128Size> expected; | 1830 RunConcatOpTest<int8_t>(kExprS8x16Shuffle); |
1782 for (int k = 1; k < 16; k++) { | |
1783 int j = 0; | |
1784 // last 16 - k bytes of first vector. | |
1785 for (int i = k; i < kSimd128Size; i++) { | |
1786 expected[j++] = i; | |
1787 } | |
1788 // first k bytes of second vector | |
1789 for (int i = 0; i < k; i++) { | |
1790 expected[j++] = i + kSimd128Size; | |
1791 } | |
1792 RunConcatOpTest<int8_t>(kExprS8x16Concat, k, expected); | |
1793 } | |
1794 } | 1831 } |
1795 | 1832 |
1796 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer | 1833 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer |
1797 // result. Use relational ops on numeric vectors to create the boolean vector | 1834 // result. Use relational ops on numeric vectors to create the boolean vector |
1798 // test inputs. Test inputs with all true, all false, one true, and one false. | 1835 // test inputs. Test inputs with all true, all false, one true, and one false. |
1799 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ | 1836 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ |
1800 WASM_EXEC_TEST(ReductionTest##lanes) { \ | 1837 WASM_EXEC_TEST(ReductionTest##lanes) { \ |
1801 FLAG_wasm_simd_prototype = true; \ | 1838 FLAG_wasm_simd_prototype = true; \ |
1802 WasmRunner<int32_t> r(kExecuteCompiled); \ | 1839 WasmRunner<int32_t> r(kExecuteCompiled); \ |
1803 byte zero = r.AllocateLocal(kWasmS128); \ | 1840 byte zero = r.AllocateLocal(kWasmS128); \ |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 WASM_SIMD_I32x4_EXTRACT_LANE( | 2260 WASM_SIMD_I32x4_EXTRACT_LANE( |
2224 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); | 2261 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); |
2225 | 2262 |
2226 FOR_INT32_INPUTS(i) { | 2263 FOR_INT32_INPUTS(i) { |
2227 int32_t expected = *i; | 2264 int32_t expected = *i; |
2228 r.module().WriteMemory(&memory[0], expected); | 2265 r.module().WriteMemory(&memory[0], expected); |
2229 CHECK_EQ(expected, r.Call()); | 2266 CHECK_EQ(expected, r.Call()); |
2230 } | 2267 } |
2231 } | 2268 } |
2232 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64 | 2269 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64 |
OLD | NEW |