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

Side by Side Diff: test/cctest/wasm/test-run-wasm-simd.cc

Issue 2847663005: [WASM SIMD] Replace primitive shuffles with general Shuffle. (Closed)
Patch Set: Remove stray wasm opcode. Created 3 years, 7 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 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
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 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || 1576 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS ||
1563 // V8_TARGET_ARCH_MIPS64 1577 // V8_TARGET_ARCH_MIPS64
1564 1578
1565 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 1579 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64
1566 WASM_SIMD_SELECT_TEST(16x8) 1580 WASM_SIMD_SELECT_TEST(16x8)
1567 1581
1568 WASM_SIMD_SELECT_TEST(8x16) 1582 WASM_SIMD_SELECT_TEST(8x16)
1569 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 1583 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64
1570 1584
1571 #if V8_TARGET_ARCH_ARM 1585 #if V8_TARGET_ARCH_ARM
1572 // Test unary ops with a lane test pattern, all lanes distinct.
1573 template <typename T>
1574 void RunUnaryLaneOpTest(
1575 WasmOpcode simd_op,
1576 const std::array<T, kSimd128Size / sizeof(T)>& expected) {
1577 FLAG_wasm_simd_prototype = true;
1578 WasmRunner<int32_t> r(kExecuteCompiled);
1579 // Set up a test pattern as a global, e.g. [0, 1, 2, 3].
1580 T* global = r.module().AddGlobal<T>(kWasmS128);
1581 static const size_t kElems = kSimd128Size / sizeof(T);
1582 for (size_t i = 0; i < kElems; i++) {
1583 global[i] = i;
1584 }
1585 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_UNOP(simd_op, WASM_GET_GLOBAL(0))),
1586 WASM_ONE);
1587
1588 CHECK_EQ(1, r.Call());
1589 for (size_t i = 0; i < kElems; i++) {
1590 CHECK_EQ(global[i], expected[i]);
1591 }
1592 }
1593
1594 WASM_EXEC_COMPILED_TEST(S32x2Reverse) {
1595 RunUnaryLaneOpTest<int32_t>(kExprS32x2Reverse, {{1, 0, 3, 2}});
1596 }
1597
1598 WASM_EXEC_COMPILED_TEST(S16x4Reverse) {
1599 RunUnaryLaneOpTest<int16_t>(kExprS16x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4}});
1600 }
1601
1602 WASM_EXEC_COMPILED_TEST(S16x2Reverse) {
1603 RunUnaryLaneOpTest<int16_t>(kExprS16x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6}});
1604 }
1605
1606 WASM_EXEC_COMPILED_TEST(S8x8Reverse) {
1607 RunUnaryLaneOpTest<int8_t>(kExprS8x8Reverse, {{7, 6, 5, 4, 3, 2, 1, 0, 15, 14,
1608 13, 12, 11, 10, 9, 8}});
1609 }
1610
1611 WASM_EXEC_COMPILED_TEST(S8x4Reverse) {
1612 RunUnaryLaneOpTest<int8_t>(kExprS8x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4, 11, 10,
1613 9, 8, 15, 14, 13, 12}});
1614 }
1615
1616 WASM_EXEC_COMPILED_TEST(S8x2Reverse) {
1617 RunUnaryLaneOpTest<int8_t>(kExprS8x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8,
1618 11, 10, 13, 12, 15, 14}});
1619 }
1620
1621 // Test binary ops with two lane test patterns, all lanes distinct. 1586 // Test binary ops with two lane test patterns, all lanes distinct.
1622 template <typename T> 1587 template <typename T>
1623 void RunBinaryLaneOpTest( 1588 void RunBinaryLaneOpTest(
1624 WasmOpcode simd_op, 1589 WasmOpcode simd_op,
1625 const std::array<T, kSimd128Size / sizeof(T)>& expected) { 1590 const std::array<T, kSimd128Size / sizeof(T)>& expected) {
1626 FLAG_wasm_simd_prototype = true; 1591 FLAG_wasm_simd_prototype = true;
1627 WasmRunner<int32_t> r(kExecuteCompiled); 1592 WasmRunner<int32_t> r(kExecuteCompiled);
1628 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. 1593 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
1629 T* global1 = r.module().AddGlobal<T>(kWasmS128); 1594 T* src0 = r.module().AddGlobal<T>(kWasmS128);
1630 T* global2 = r.module().AddGlobal<T>(kWasmS128); 1595 T* src1 = r.module().AddGlobal<T>(kWasmS128);
1631 static const size_t kElems = kSimd128Size / sizeof(T); 1596 static const size_t kElems = kSimd128Size / sizeof(T);
1632 for (size_t i = 0; i < kElems; i++) { 1597 for (size_t i = 0; i < kElems; i++) {
1633 global1[i] = i; 1598 src0[i] = i;
1634 global2[i] = kElems + i; 1599 src1[i] = kElems + i;
1635 } 1600 }
1636 BUILD(r, 1601 switch (simd_op) {
1637 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0), 1602 case kExprS32x4Shuffle: {
1638 WASM_GET_GLOBAL(1))), 1603 BUILD(r,
1639 WASM_ONE); 1604 WASM_SET_GLOBAL(0, WASM_SIMD_S32x4_SHUFFLE_OP(simd_op, expected,
1605 WASM_GET_GLOBAL(0),
1606 WASM_GET_GLOBAL(1))),
1607 WASM_ONE);
1608 break;
1609 }
1610 case kExprS16x8Shuffle: {
1611 BUILD(r,
1612 WASM_SET_GLOBAL(0, WASM_SIMD_S16x8_SHUFFLE_OP(simd_op, expected,
1613 WASM_GET_GLOBAL(0),
1614 WASM_GET_GLOBAL(1))),
1615 WASM_ONE);
1616 break;
1617 }
1618 case kExprS8x16Shuffle: {
1619 BUILD(r,
1620 WASM_SET_GLOBAL(0, WASM_SIMD_S8x16_SHUFFLE_OP(simd_op, expected,
1621 WASM_GET_GLOBAL(0),
1622 WASM_GET_GLOBAL(1))),
1623 WASM_ONE);
1624 break;
1625 }
1626 default: {
1627 BUILD(r,
1628 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0),
1629 WASM_GET_GLOBAL(1))),
1630 WASM_ONE);
1631 break;
1632 }
1633 }
1640 1634
1641 CHECK_EQ(1, r.Call()); 1635 CHECK_EQ(1, r.Call());
1642 for (size_t i = 0; i < expected.size(); i++) { 1636 for (size_t i = 0; i < expected.size(); i++) {
1643 CHECK_EQ(global1[i], expected[i]); 1637 CHECK_EQ(src0[i], expected[i]);
1644 } 1638 }
1645 } 1639 }
1646 1640
1647 WASM_EXEC_COMPILED_TEST(F32x4AddHoriz) { 1641 WASM_EXEC_COMPILED_TEST(F32x4AddHoriz) {
1648 RunBinaryLaneOpTest<float>(kExprF32x4AddHoriz, {{1.0f, 5.0f, 9.0f, 13.0f}}); 1642 RunBinaryLaneOpTest<float>(kExprF32x4AddHoriz, {{1.0f, 5.0f, 9.0f, 13.0f}});
1649 } 1643 }
1650 1644
1651 WASM_EXEC_COMPILED_TEST(I32x4AddHoriz) { 1645 WASM_EXEC_COMPILED_TEST(I32x4AddHoriz) {
1652 RunBinaryLaneOpTest<int32_t>(kExprI32x4AddHoriz, {{1, 5, 9, 13}}); 1646 RunBinaryLaneOpTest<int32_t>(kExprI32x4AddHoriz, {{1, 5, 9, 13}});
1653 } 1647 }
1654 1648
1655 WASM_EXEC_COMPILED_TEST(I16x8AddHoriz) { 1649 WASM_EXEC_COMPILED_TEST(I16x8AddHoriz) {
1656 RunBinaryLaneOpTest<int16_t>(kExprI16x8AddHoriz, 1650 RunBinaryLaneOpTest<int16_t>(kExprI16x8AddHoriz,
1657 {{1, 5, 9, 13, 17, 21, 25, 29}}); 1651 {{1, 5, 9, 13, 17, 21, 25, 29}});
1658 } 1652 }
1659 1653
1654 // Test some regular shuffles that may have special handling on some targets.
1655 // Test a normal and unary versions (where second operand isn't used).
1660 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) { 1656 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) {
1661 RunBinaryLaneOpTest<int32_t>(kExprS32x4ZipLeft, {{0, 4, 1, 5}}); 1657 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 4, 1, 5}});
1658 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 0, 1, 1}});
1662 } 1659 }
1663 1660
1664 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) { 1661 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) {
1665 RunBinaryLaneOpTest<int32_t>(kExprS32x4ZipRight, {{2, 6, 3, 7}}); 1662 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{2, 6, 3, 7}});
1663 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{2, 2, 3, 3}});
1666 } 1664 }
1667 1665
1668 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) { 1666 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) {
1669 RunBinaryLaneOpTest<int32_t>(kExprS32x4UnzipLeft, {{0, 2, 4, 6}}); 1667 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 2, 4, 6}});
1668 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 2, 0, 2}});
1670 } 1669 }
1671 1670
1672 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) { 1671 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) {
1673 RunBinaryLaneOpTest<int32_t>(kExprS32x4UnzipRight, {{1, 3, 5, 7}}); 1672 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 3, 5, 7}});
1673 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 3, 1, 3}});
1674 } 1674 }
1675 1675
1676 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) { 1676 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) {
1677 RunBinaryLaneOpTest<int32_t>(kExprS32x4TransposeLeft, {{0, 4, 2, 6}}); 1677 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 4, 2, 6}});
1678 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{0, 0, 2, 2}});
1678 } 1679 }
1679 1680
1680 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) { 1681 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) {
1681 RunBinaryLaneOpTest<int32_t>(kExprS32x4TransposeRight, {{1, 5, 3, 7}}); 1682 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 5, 3, 7}});
1683 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 1, 3, 3}});
1684 }
1685
1686 // Reverses are only unary.
1687 WASM_EXEC_COMPILED_TEST(S32x2Reverse) {
1688 RunBinaryLaneOpTest<int32_t>(kExprS32x4Shuffle, {{1, 0, 3, 2}});
1682 } 1689 }
1683 1690
1684 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) { 1691 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) {
1685 RunBinaryLaneOpTest<int16_t>(kExprS16x8ZipLeft, {{0, 8, 1, 9, 2, 10, 3, 11}}); 1692 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 8, 1, 9, 2, 10, 3, 11}});
1693 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 0, 1, 1, 2, 2, 3, 3}});
1686 } 1694 }
1687 1695
1688 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) { 1696 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) {
1689 RunBinaryLaneOpTest<int16_t>(kExprS16x8ZipRight, 1697 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle,
1690 {{4, 12, 5, 13, 6, 14, 7, 15}}); 1698 {{4, 12, 5, 13, 6, 14, 7, 15}});
1699 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{4, 4, 5, 5, 6, 6, 7, 7}});
1691 } 1700 }
1692 1701
1693 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) { 1702 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) {
1694 RunBinaryLaneOpTest<int16_t>(kExprS16x8UnzipLeft, 1703 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle,
1695 {{0, 2, 4, 6, 8, 10, 12, 14}}); 1704 {{0, 2, 4, 6, 8, 10, 12, 14}});
1705 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 2, 4, 6, 0, 2, 4, 6}});
1696 } 1706 }
1697 1707
1698 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) { 1708 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) {
1699 RunBinaryLaneOpTest<int16_t>(kExprS16x8UnzipRight, 1709 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle,
1700 {{1, 3, 5, 7, 9, 11, 13, 15}}); 1710 {{1, 3, 5, 7, 9, 11, 13, 15}});
1711 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{1, 3, 5, 7, 1, 3, 5, 7}});
1701 } 1712 }
1702 1713
1703 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) { 1714 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) {
1704 RunBinaryLaneOpTest<int16_t>(kExprS16x8TransposeLeft, 1715 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle,
1705 {{0, 8, 2, 10, 4, 12, 6, 14}}); 1716 {{0, 8, 2, 10, 4, 12, 6, 14}});
1717 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{0, 0, 2, 2, 4, 4, 6, 6}});
1706 } 1718 }
1707 1719
1708 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) { 1720 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) {
1709 RunBinaryLaneOpTest<int16_t>(kExprS16x8TransposeRight, 1721 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle,
1710 {{1, 9, 3, 11, 5, 13, 7, 15}}); 1722 {{1, 9, 3, 11, 5, 13, 7, 15}});
1723 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{1, 1, 3, 3, 5, 5, 7, 7}});
1724 }
1725
1726 WASM_EXEC_COMPILED_TEST(S16x4Reverse) {
1727 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{3, 2, 1, 0, 7, 6, 5, 4}});
1728 }
1729
1730 WASM_EXEC_COMPILED_TEST(S16x2Reverse) {
1731 RunBinaryLaneOpTest<int16_t>(kExprS16x8Shuffle, {{1, 0, 3, 2, 5, 4, 7, 6}});
1711 } 1732 }
1712 1733
1713 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) { 1734 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) {
1714 RunBinaryLaneOpTest<int8_t>( 1735 RunBinaryLaneOpTest<int8_t>(
1715 kExprS8x16ZipLeft, 1736 kExprS8x16Shuffle,
1716 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}); 1737 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}});
1738 RunBinaryLaneOpTest<int8_t>(
1739 kExprS8x16Shuffle, {{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}});
1717 } 1740 }
1718 1741
1719 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) { 1742 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) {
1720 RunBinaryLaneOpTest<int8_t>( 1743 RunBinaryLaneOpTest<int8_t>(
1721 kExprS8x16ZipRight, 1744 kExprS8x16Shuffle,
1722 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}); 1745 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}});
1746 RunBinaryLaneOpTest<int8_t>(
1747 kExprS8x16Shuffle,
1748 {{8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15}});
1723 } 1749 }
1724 1750
1725 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) { 1751 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) {
1726 RunBinaryLaneOpTest<int8_t>( 1752 RunBinaryLaneOpTest<int8_t>(
1727 kExprS8x16UnzipLeft, 1753 kExprS8x16Shuffle,
1728 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}); 1754 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}});
1755 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{0, 2, 4, 6, 8, 10, 12, 14, 0,
1756 2, 4, 6, 8, 10, 12, 14}});
1729 } 1757 }
1730 1758
1731 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) { 1759 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) {
1732 RunBinaryLaneOpTest<int8_t>( 1760 RunBinaryLaneOpTest<int8_t>(
1733 kExprS8x16UnzipRight, 1761 kExprS8x16Shuffle,
1734 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}); 1762 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}});
1763 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{1, 3, 5, 7, 9, 11, 13, 15, 1,
1764 3, 5, 7, 9, 11, 13, 15}});
1735 } 1765 }
1736 1766
1737 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) { 1767 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) {
1738 RunBinaryLaneOpTest<int8_t>( 1768 RunBinaryLaneOpTest<int8_t>(
1739 kExprS8x16TransposeLeft, 1769 kExprS8x16Shuffle,
1740 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}); 1770 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}});
1771 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{0, 0, 2, 2, 4, 4, 6, 6, 8, 8,
1772 10, 10, 12, 12, 14, 14}});
1741 } 1773 }
1742 1774
1743 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) { 1775 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) {
1744 RunBinaryLaneOpTest<int8_t>( 1776 RunBinaryLaneOpTest<int8_t>(
1745 kExprS8x16TransposeRight, 1777 kExprS8x16Shuffle,
1746 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}); 1778 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}});
1779 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{1, 1, 3, 3, 5, 5, 7, 7, 9, 9,
1780 11, 11, 13, 13, 15, 15}});
1747 } 1781 }
1748 1782
1783 WASM_EXEC_COMPILED_TEST(S8x8Reverse) {
1784 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{7, 6, 5, 4, 3, 2, 1, 0, 15,
1785 14, 13, 12, 11, 10, 9, 8}});
1786 }
1787
1788 WASM_EXEC_COMPILED_TEST(S8x4Reverse) {
1789 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{3, 2, 1, 0, 7, 6, 5, 4, 11,
1790 10, 9, 8, 15, 14, 13, 12}});
1791 }
1792
1793 WASM_EXEC_COMPILED_TEST(S8x2Reverse) {
1794 RunBinaryLaneOpTest<int8_t>(kExprS8x16Shuffle, {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8,
1795 11, 10, 13, 12, 15, 14}});
1796 }
1797
1798 // Test shuffles that concatenate the two vectors.
1749 template <typename T> 1799 template <typename T>
1750 void RunConcatOpTest(WasmOpcode simd_op, int bytes, 1800 void RunConcatOpTest(WasmOpcode simd_op) {
1751 const std::array<T, kSimd128Size / sizeof(T)>& expected) { 1801 static const int kLanes = kSimd128Size / sizeof(T);
1752 FLAG_wasm_simd_prototype = true; 1802 std::array<T, kLanes> expected;
1753 WasmRunner<int32_t> r(kExecuteCompiled); 1803 for (int bias = 1; bias < kLanes; bias++) {
1754 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7]. 1804 int i = 0;
1755 T* global1 = r.module().AddGlobal<T>(kWasmS128); 1805 // last kLanes - bias bytes of first vector.
1756 T* global2 = r.module().AddGlobal<T>(kWasmS128); 1806 for (int j = bias; j < kLanes; j++) {
1757 static const size_t kElems = kSimd128Size / sizeof(T); 1807 expected[i++] = j;
1758 for (size_t i = 0; i < kElems; i++) { 1808 }
1759 global1[i] = i; 1809 // first bias lanes of second vector
1760 global2[i] = kElems + i; 1810 for (int j = 0; j < bias; j++) {
1761 } 1811 expected[i++] = j + kLanes;
1762 BUILD( 1812 }
1763 r, 1813 RunBinaryLaneOpTest<T>(simd_op, expected);
1764 WASM_SET_GLOBAL(0, WASM_SIMD_CONCAT_OP(simd_op, bytes, WASM_GET_GLOBAL(0),
1765 WASM_GET_GLOBAL(1))),
1766 WASM_ONE);
1767
1768 CHECK_EQ(1, r.Call());
1769 for (size_t i = 0; i < expected.size(); i++) {
1770 CHECK_EQ(global1[i], expected[i]);
1771 } 1814 }
1772 } 1815 }
1773 1816
1817 WASM_EXEC_COMPILED_TEST(S32x4Concat) {
1818 RunConcatOpTest<int32_t>(kExprS32x4Shuffle);
1819 }
1820
1821 WASM_EXEC_COMPILED_TEST(S16x8Concat) {
1822 RunConcatOpTest<int16_t>(kExprS16x8Shuffle);
1823 }
1824
1774 WASM_EXEC_COMPILED_TEST(S8x16Concat) { 1825 WASM_EXEC_COMPILED_TEST(S8x16Concat) {
1775 std::array<int8_t, kSimd128Size> expected; 1826 RunConcatOpTest<int8_t>(kExprS8x16Shuffle);
1776 for (int k = 1; k < 16; k++) {
1777 int j = 0;
1778 // last 16 - k bytes of first vector.
1779 for (int i = k; i < kSimd128Size; i++) {
1780 expected[j++] = i;
1781 }
1782 // first k bytes of second vector
1783 for (int i = 0; i < k; i++) {
1784 expected[j++] = i + kSimd128Size;
1785 }
1786 RunConcatOpTest<int8_t>(kExprS8x16Concat, k, expected);
1787 }
1788 } 1827 }
1789 1828
1790 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer 1829 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer
1791 // result. Use relational ops on numeric vectors to create the boolean vector 1830 // result. Use relational ops on numeric vectors to create the boolean vector
1792 // test inputs. Test inputs with all true, all false, one true, and one false. 1831 // test inputs. Test inputs with all true, all false, one true, and one false.
1793 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ 1832 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \
1794 WASM_EXEC_TEST(ReductionTest##lanes) { \ 1833 WASM_EXEC_TEST(ReductionTest##lanes) { \
1795 FLAG_wasm_simd_prototype = true; \ 1834 FLAG_wasm_simd_prototype = true; \
1796 WasmRunner<int32_t> r(kExecuteCompiled); \ 1835 WasmRunner<int32_t> r(kExecuteCompiled); \
1797 byte zero = r.AllocateLocal(kWasmS128); \ 1836 byte zero = r.AllocateLocal(kWasmS128); \
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 WASM_SIMD_I32x4_EXTRACT_LANE( 2246 WASM_SIMD_I32x4_EXTRACT_LANE(
2208 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); 2247 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)));
2209 2248
2210 FOR_INT32_INPUTS(i) { 2249 FOR_INT32_INPUTS(i) {
2211 int32_t expected = *i; 2250 int32_t expected = *i;
2212 r.module().WriteMemory(&memory[0], expected); 2251 r.module().WriteMemory(&memory[0], expected);
2213 CHECK_EQ(expected, r.Call()); 2252 CHECK_EQ(expected, r.Call());
2214 } 2253 }
2215 } 2254 }
2216 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 2255 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698