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

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

Issue 2801183002: [WASM SIMD] Implement primitive shuffles. (Closed)
Patch Set: Add comments, remove S64x2Reverse, as it's redundant. Created 3 years, 8 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 "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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 , WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 1), \ 347 , WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 1), \
348 WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 2), \ 348 WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 2), \
349 WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 3) 349 WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 3)
350 350
351 #define TO_BYTE(val) static_cast<byte>(val) 351 #define TO_BYTE(val) static_cast<byte>(val)
352 #define WASM_SIMD_OP(op) kSimdPrefix, TO_BYTE(op) 352 #define WASM_SIMD_OP(op) kSimdPrefix, TO_BYTE(op)
353 #define WASM_SIMD_SPLAT(Type, x) x, WASM_SIMD_OP(kExpr##Type##Splat) 353 #define WASM_SIMD_SPLAT(Type, x) x, WASM_SIMD_OP(kExpr##Type##Splat)
354 #define WASM_SIMD_UNOP(op, x) x, WASM_SIMD_OP(op) 354 #define WASM_SIMD_UNOP(op, x) x, WASM_SIMD_OP(op)
355 #define WASM_SIMD_BINOP(op, x, y) x, y, WASM_SIMD_OP(op) 355 #define WASM_SIMD_BINOP(op, x, y) x, y, WASM_SIMD_OP(op)
356 #define WASM_SIMD_SHIFT_OP(op, shift, x) x, WASM_SIMD_OP(op), TO_BYTE(shift) 356 #define WASM_SIMD_SHIFT_OP(op, shift, x) x, WASM_SIMD_OP(op), TO_BYTE(shift)
357 #define WASM_SIMD_CONCAT_OP(op, bytes, x, y) \
358 x, y, WASM_SIMD_OP(op), TO_BYTE(bytes)
357 #define WASM_SIMD_SELECT(format, x, y, z) \ 359 #define WASM_SIMD_SELECT(format, x, y, z) \
358 x, y, z, WASM_SIMD_OP(kExprS##format##Select) 360 x, y, z, WASM_SIMD_OP(kExprS##format##Select)
359 // Since boolean vectors can't be checked directly, materialize them into 361 // Since boolean vectors can't be checked directly, materialize them into
360 // integer vectors using a Select operation. 362 // integer vectors using a Select operation.
361 #define WASM_SIMD_MATERIALIZE_BOOLS(format, x) \ 363 #define WASM_SIMD_MATERIALIZE_BOOLS(format, x) \
362 x, WASM_SIMD_I##format##_SPLAT(WASM_ONE), \ 364 x, WASM_SIMD_I##format##_SPLAT(WASM_ONE), \
363 WASM_SIMD_I##format##_SPLAT(WASM_ZERO), \ 365 WASM_SIMD_I##format##_SPLAT(WASM_ZERO), \
364 WASM_SIMD_OP(kExprS##format##Select) 366 WASM_SIMD_OP(kExprS##format##Select)
365 367
366 #define WASM_SIMD_F32x4_SPLAT(x) x, WASM_SIMD_OP(kExprF32x4Splat) 368 #define WASM_SIMD_F32x4_SPLAT(x) x, WASM_SIMD_OP(kExprF32x4Splat)
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 CHECK_EQ(1, r.Call(0x12, 0x34)); \ 1437 CHECK_EQ(1, r.Call(0x12, 0x34)); \
1436 } 1438 }
1437 1439
1438 WASM_SIMD_SELECT_TEST(32x4) 1440 WASM_SIMD_SELECT_TEST(32x4)
1439 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 1441 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64
1440 1442
1441 #if V8_TARGET_ARCH_ARM 1443 #if V8_TARGET_ARCH_ARM
1442 WASM_SIMD_SELECT_TEST(16x8) 1444 WASM_SIMD_SELECT_TEST(16x8)
1443 WASM_SIMD_SELECT_TEST(8x16) 1445 WASM_SIMD_SELECT_TEST(8x16)
1444 1446
1447 template <typename T>
1448 void RunUnaryPermuteOpTest(
1449 WasmOpcode simd_op,
1450 const std::array<T, kSimd128Size / sizeof(T)>& expected) {
1451 FLAG_wasm_simd_prototype = true;
1452 WasmRunner<int32_t> r(kExecuteCompiled);
1453 // Set up a test pattern as a global, e.g. [0, 1, 2, 3].
1454 T* global = r.module().AddGlobal<T>(kWasmS128);
1455 static const size_t kElems = kSimd128Size / sizeof(T);
1456 for (size_t i = 0; i < kElems; i++) {
1457 global[i] = i;
1458 }
1459 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_UNOP(simd_op, WASM_GET_GLOBAL(0))),
1460 WASM_ONE);
1461
1462 CHECK_EQ(1, r.Call());
1463 for (size_t i = 0; i < kElems; i++) {
1464 CHECK_EQ(global[i], expected[i]);
1465 }
1466 }
1467
1468 WASM_EXEC_COMPILED_TEST(S32x2Reverse) {
1469 RunUnaryPermuteOpTest<int32_t>(kExprS32x2Reverse, {{1, 0, 3, 2}});
1470 }
1471
1472 WASM_EXEC_COMPILED_TEST(S16x4Reverse) {
1473 RunUnaryPermuteOpTest<int16_t>(kExprS16x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4}});
1474 }
1475
1476 WASM_EXEC_COMPILED_TEST(S16x2Reverse) {
1477 RunUnaryPermuteOpTest<int16_t>(kExprS16x2Reverse, {{1, 0, 3, 2, 5, 4, 7, 6}});
1478 }
1479
1480 WASM_EXEC_COMPILED_TEST(S8x8Reverse) {
1481 RunUnaryPermuteOpTest<int8_t>(kExprS8x8Reverse, {{7, 6, 5, 4, 3, 2, 1, 0, 15,
1482 14, 13, 12, 11, 10, 9, 8}});
1483 }
1484
1485 WASM_EXEC_COMPILED_TEST(S8x4Reverse) {
1486 RunUnaryPermuteOpTest<int8_t>(kExprS8x4Reverse, {{3, 2, 1, 0, 7, 6, 5, 4, 11,
1487 10, 9, 8, 15, 14, 13, 12}});
1488 }
1489
1490 WASM_EXEC_COMPILED_TEST(S8x2Reverse) {
1491 RunUnaryPermuteOpTest<int8_t>(
1492 kExprS8x2Reverse,
1493 {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14}});
1494 }
1495
1496 template <typename T>
1497 void RunBinaryPermuteOpTest(
1498 WasmOpcode simd_op,
1499 const std::array<T, kSimd128Size / sizeof(T)>& expected) {
1500 FLAG_wasm_simd_prototype = true;
1501 WasmRunner<int32_t> r(kExecuteCompiled);
1502 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
1503 T* global1 = r.module().AddGlobal<T>(kWasmS128);
1504 T* global2 = r.module().AddGlobal<T>(kWasmS128);
1505 static const size_t kElems = kSimd128Size / sizeof(T);
1506 for (size_t i = 0; i < kElems; i++) {
1507 global1[i] = i;
1508 global2[i] = kElems + i;
1509 }
1510 BUILD(r,
1511 WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0),
1512 WASM_GET_GLOBAL(1))),
1513 WASM_ONE);
1514
1515 CHECK_EQ(1, r.Call());
1516 for (size_t i = 0; i < expected.size(); i++) {
1517 CHECK_EQ(global1[i], expected[i]);
1518 }
1519 }
1520
1521 WASM_EXEC_COMPILED_TEST(S32x4ZipLeft) {
1522 RunBinaryPermuteOpTest<int32_t>(kExprS32x4ZipLeft, {{0, 4, 1, 5}});
1523 }
1524
1525 WASM_EXEC_COMPILED_TEST(S32x4ZipRight) {
1526 RunBinaryPermuteOpTest<int32_t>(kExprS32x4ZipRight, {{2, 6, 3, 7}});
1527 }
1528
1529 WASM_EXEC_COMPILED_TEST(S32x4UnzipLeft) {
1530 RunBinaryPermuteOpTest<int32_t>(kExprS32x4UnzipLeft, {{0, 2, 4, 6}});
1531 }
1532
1533 WASM_EXEC_COMPILED_TEST(S32x4UnzipRight) {
1534 RunBinaryPermuteOpTest<int32_t>(kExprS32x4UnzipRight, {{1, 3, 5, 7}});
1535 }
1536
1537 WASM_EXEC_COMPILED_TEST(S32x4TransposeLeft) {
1538 RunBinaryPermuteOpTest<int32_t>(kExprS32x4TransposeLeft, {{0, 4, 2, 6}});
1539 }
1540
1541 WASM_EXEC_COMPILED_TEST(S32x4TransposeRight) {
1542 RunBinaryPermuteOpTest<int32_t>(kExprS32x4TransposeRight, {{1, 5, 3, 7}});
1543 }
1544
1545 WASM_EXEC_COMPILED_TEST(S16x8ZipLeft) {
1546 RunBinaryPermuteOpTest<int16_t>(kExprS16x8ZipLeft,
1547 {{0, 8, 1, 9, 2, 10, 3, 11}});
1548 }
1549
1550 WASM_EXEC_COMPILED_TEST(S16x8ZipRight) {
1551 RunBinaryPermuteOpTest<int16_t>(kExprS16x8ZipRight,
1552 {{4, 12, 5, 13, 6, 14, 7, 15}});
1553 }
1554
1555 WASM_EXEC_COMPILED_TEST(S16x8UnzipLeft) {
1556 RunBinaryPermuteOpTest<int16_t>(kExprS16x8UnzipLeft,
1557 {{0, 2, 4, 6, 8, 10, 12, 14}});
1558 }
1559
1560 WASM_EXEC_COMPILED_TEST(S16x8UnzipRight) {
1561 RunBinaryPermuteOpTest<int16_t>(kExprS16x8UnzipRight,
1562 {{1, 3, 5, 7, 9, 11, 13, 15}});
1563 }
1564
1565 WASM_EXEC_COMPILED_TEST(S16x8TransposeLeft) {
1566 RunBinaryPermuteOpTest<int16_t>(kExprS16x8TransposeLeft,
1567 {{0, 8, 2, 10, 4, 12, 6, 14}});
1568 }
1569
1570 WASM_EXEC_COMPILED_TEST(S16x8TransposeRight) {
1571 RunBinaryPermuteOpTest<int16_t>(kExprS16x8TransposeRight,
1572 {{1, 9, 3, 11, 5, 13, 7, 15}});
1573 }
1574
1575 WASM_EXEC_COMPILED_TEST(S8x16ZipLeft) {
1576 RunBinaryPermuteOpTest<int8_t>(
1577 kExprS8x16ZipLeft,
1578 {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}});
1579 }
1580
1581 WASM_EXEC_COMPILED_TEST(S8x16ZipRight) {
1582 RunBinaryPermuteOpTest<int8_t>(
1583 kExprS8x16ZipRight,
1584 {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}});
1585 }
1586
1587 WASM_EXEC_COMPILED_TEST(S8x16UnzipLeft) {
1588 RunBinaryPermuteOpTest<int8_t>(
1589 kExprS8x16UnzipLeft,
1590 {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}});
1591 }
1592
1593 WASM_EXEC_COMPILED_TEST(S8x16UnzipRight) {
1594 RunBinaryPermuteOpTest<int8_t>(
1595 kExprS8x16UnzipRight,
1596 {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}});
1597 }
1598
1599 WASM_EXEC_COMPILED_TEST(S8x16TransposeLeft) {
1600 RunBinaryPermuteOpTest<int8_t>(
1601 kExprS8x16TransposeLeft,
1602 {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}});
1603 }
1604
1605 WASM_EXEC_COMPILED_TEST(S8x16TransposeRight) {
1606 RunBinaryPermuteOpTest<int8_t>(
1607 kExprS8x16TransposeRight,
1608 {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}});
1609 }
1610
1611 template <typename T>
1612 void RunConcatOpTest(WasmOpcode simd_op, int bytes,
1613 const std::array<T, kSimd128Size / sizeof(T)>& expected) {
1614 FLAG_wasm_simd_prototype = true;
1615 WasmRunner<int32_t> r(kExecuteCompiled);
1616 // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
1617 T* global1 = r.module().AddGlobal<T>(kWasmS128);
1618 T* global2 = r.module().AddGlobal<T>(kWasmS128);
1619 static const size_t kElems = kSimd128Size / sizeof(T);
1620 for (size_t i = 0; i < kElems; i++) {
1621 global1[i] = i;
1622 global2[i] = kElems + i;
1623 }
1624 BUILD(
1625 r,
1626 WASM_SET_GLOBAL(0, WASM_SIMD_CONCAT_OP(simd_op, bytes, WASM_GET_GLOBAL(0),
1627 WASM_GET_GLOBAL(1))),
1628 WASM_ONE);
1629
1630 CHECK_EQ(1, r.Call());
1631 for (size_t i = 0; i < expected.size(); i++) {
1632 CHECK_EQ(global1[i], expected[i]);
1633 }
1634 }
1635
1636 WASM_EXEC_COMPILED_TEST(S8x16Concat) {
1637 std::array<int8_t, kSimd128Size> expected;
1638 for (int k = 1; k < 16; k++) {
1639 int j = 0;
1640 // last 16 - k bytes of first vector.
1641 for (int i = k; i < kSimd128Size; i++) {
1642 expected[j++] = i;
1643 }
1644 // first k bytes of second vector
1645 for (int i = 0; i < k; i++) {
1646 expected[j++] = i + kSimd128Size;
1647 }
1648 RunConcatOpTest<int8_t>(kExprS8x16Concat, k, expected);
1649 }
1650 }
1651
1445 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer 1652 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer
1446 // result. Use relational ops on numeric vectors to create the boolean vector 1653 // result. Use relational ops on numeric vectors to create the boolean vector
1447 // test inputs. Test inputs with all true, all false, one true, and one false. 1654 // test inputs. Test inputs with all true, all false, one true, and one false.
1448 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ 1655 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \
1449 WASM_EXEC_TEST(ReductionTest##lanes) { \ 1656 WASM_EXEC_TEST(ReductionTest##lanes) { \
1450 FLAG_wasm_simd_prototype = true; \ 1657 FLAG_wasm_simd_prototype = true; \
1451 WasmRunner<int32_t> r(kExecuteCompiled); \ 1658 WasmRunner<int32_t> r(kExecuteCompiled); \
1452 byte zero = r.AllocateLocal(kWasmS128); \ 1659 byte zero = r.AllocateLocal(kWasmS128); \
1453 byte one_one = r.AllocateLocal(kWasmS128); \ 1660 byte one_one = r.AllocateLocal(kWasmS128); \
1454 byte reduced = r.AllocateLocal(kWasmI32); \ 1661 byte reduced = r.AllocateLocal(kWasmI32); \
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 WASM_SIMD_I32x4_EXTRACT_LANE( 2067 WASM_SIMD_I32x4_EXTRACT_LANE(
1861 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); 2068 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)));
1862 2069
1863 FOR_INT32_INPUTS(i) { 2070 FOR_INT32_INPUTS(i) {
1864 int32_t expected = *i; 2071 int32_t expected = *i;
1865 r.module().WriteMemory(&memory[0], expected); 2072 r.module().WriteMemory(&memory[0], expected);
1866 CHECK_EQ(expected, r.Call()); 2073 CHECK_EQ(expected, r.Call());
1867 } 2074 }
1868 } 2075 }
1869 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 2076 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
OLDNEW
« src/compiler/arm/code-generator-arm.cc ('K') | « test/cctest/test-macro-assembler-arm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698