LCOV - code coverage report
Current view: top level - test/cctest/wasm - test-run-wasm-simd.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 617 711 86.8 %
Date: 2019-01-20 Functions: 661 755 87.5 %

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #include <type_traits>
       6             : 
       7             : #include "src/assembler-inl.h"
       8             : #include "src/base/bits.h"
       9             : #include "src/base/overflowing-math.h"
      10             : #include "test/cctest/cctest.h"
      11             : #include "test/cctest/compiler/value-helper.h"
      12             : #include "test/cctest/wasm/wasm-run-utils.h"
      13             : #include "test/common/wasm/wasm-macro-gen.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : namespace wasm {
      18             : namespace test_run_wasm_simd {
      19             : 
      20             : namespace {
      21             : 
      22             : typedef float (*FloatUnOp)(float);
      23             : typedef float (*FloatBinOp)(float, float);
      24             : typedef int (*FloatCompareOp)(float, float);
      25             : typedef int32_t (*Int32UnOp)(int32_t);
      26             : typedef int32_t (*Int32BinOp)(int32_t, int32_t);
      27             : typedef int (*Int32CompareOp)(int32_t, int32_t);
      28             : typedef int32_t (*Int32ShiftOp)(int32_t, int);
      29             : typedef int16_t (*Int16UnOp)(int16_t);
      30             : typedef int16_t (*Int16BinOp)(int16_t, int16_t);
      31             : typedef int (*Int16CompareOp)(int16_t, int16_t);
      32             : typedef int16_t (*Int16ShiftOp)(int16_t, int);
      33             : typedef int8_t (*Int8UnOp)(int8_t);
      34             : typedef int8_t (*Int8BinOp)(int8_t, int8_t);
      35             : typedef int (*Int8CompareOp)(int8_t, int8_t);
      36             : typedef int8_t (*Int8ShiftOp)(int8_t, int);
      37             : 
      38             : #define WASM_SIMD_TEST(name)                                          \
      39             :   void RunWasm_##name##_Impl(LowerSimd lower_simd,                    \
      40             :                              ExecutionTier execution_tier);           \
      41             :   TEST(RunWasm_##name##_turbofan) {                                   \
      42             :     EXPERIMENTAL_FLAG_SCOPE(simd);                                    \
      43             :     RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kOptimized);   \
      44             :   }                                                                   \
      45             :   TEST(RunWasm_##name##_interpreter) {                                \
      46             :     EXPERIMENTAL_FLAG_SCOPE(simd);                                    \
      47             :     RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kInterpreter); \
      48             :   }                                                                   \
      49             :   TEST(RunWasm_##name##_simd_lowered) {                               \
      50             :     EXPERIMENTAL_FLAG_SCOPE(simd);                                    \
      51             :     RunWasm_##name##_Impl(kLowerSimd, ExecutionTier::kOptimized);     \
      52             :   }                                                                   \
      53             :   void RunWasm_##name##_Impl(LowerSimd lower_simd, ExecutionTier execution_tier)
      54             : 
      55             : // Generic expected value functions.
      56             : template <typename T, typename = typename std::enable_if<
      57             :                           std::is_floating_point<T>::value>::type>
      58        1455 : T Negate(T a) {
      59        1455 :   return -a;
      60             : }
      61             : 
      62             : // For signed integral types, use base::AddWithWraparound.
      63             : template <typename T, typename = typename std::enable_if<
      64             :                           std::is_floating_point<T>::value>::type>
      65      141135 : T Add(T a, T b) {
      66      141135 :   return a + b;
      67             : }
      68             : 
      69             : // For signed integral types, use base::SubWithWraparound.
      70             : template <typename T, typename = typename std::enable_if<
      71             :                           std::is_floating_point<T>::value>::type>
      72      141135 : T Sub(T a, T b) {
      73      141135 :   return a - b;
      74             : }
      75             : 
      76             : // For signed integral types, use base::MulWithWraparound.
      77             : template <typename T, typename = typename std::enable_if<
      78             :                           std::is_floating_point<T>::value>::type>
      79      141135 : T Mul(T a, T b) {
      80      141135 :   return a * b;
      81             : }
      82             : 
      83             : template <typename T>
      84       52890 : T Minimum(T a, T b) {
      85       52890 :   return a <= b ? a : b;
      86             : }
      87             : 
      88             : template <typename T>
      89       52890 : T Maximum(T a, T b) {
      90       52890 :   return a >= b ? a : b;
      91             : }
      92             : 
      93             : template <typename T>
      94       52890 : T UnsignedMinimum(T a, T b) {
      95             :   using UnsignedT = typename std::make_unsigned<T>::type;
      96       52890 :   return static_cast<UnsignedT>(a) <= static_cast<UnsignedT>(b) ? a : b;
      97             : }
      98             : 
      99             : template <typename T>
     100       52890 : T UnsignedMaximum(T a, T b) {
     101             :   using UnsignedT = typename std::make_unsigned<T>::type;
     102       52890 :   return static_cast<UnsignedT>(a) >= static_cast<UnsignedT>(b) ? a : b;
     103             : }
     104             : 
     105             : template <typename T>
     106      188265 : int Equal(T a, T b) {
     107      188265 :   return a == b ? -1 : 0;
     108             : }
     109             : 
     110             : template <typename T>
     111      188265 : int NotEqual(T a, T b) {
     112      188265 :   return a != b ? -1 : 0;
     113             : }
     114             : 
     115             : template <typename T>
     116      188265 : int Less(T a, T b) {
     117      188265 :   return a < b ? -1 : 0;
     118             : }
     119             : 
     120             : template <typename T>
     121      188265 : int LessEqual(T a, T b) {
     122      188265 :   return a <= b ? -1 : 0;
     123             : }
     124             : 
     125             : template <typename T>
     126      188265 : int Greater(T a, T b) {
     127      188265 :   return a > b ? -1 : 0;
     128             : }
     129             : 
     130             : template <typename T>
     131      188265 : int GreaterEqual(T a, T b) {
     132      188265 :   return a >= b ? -1 : 0;
     133             : }
     134             : 
     135             : template <typename T>
     136       52890 : int UnsignedLess(T a, T b) {
     137             :   using UnsignedT = typename std::make_unsigned<T>::type;
     138       52890 :   return static_cast<UnsignedT>(a) < static_cast<UnsignedT>(b) ? -1 : 0;
     139             : }
     140             : 
     141             : template <typename T>
     142       52890 : int UnsignedLessEqual(T a, T b) {
     143             :   using UnsignedT = typename std::make_unsigned<T>::type;
     144       52890 :   return static_cast<UnsignedT>(a) <= static_cast<UnsignedT>(b) ? -1 : 0;
     145             : }
     146             : 
     147             : template <typename T>
     148       52890 : int UnsignedGreater(T a, T b) {
     149             :   using UnsignedT = typename std::make_unsigned<T>::type;
     150       52890 :   return static_cast<UnsignedT>(a) > static_cast<UnsignedT>(b) ? -1 : 0;
     151             : }
     152             : 
     153             : template <typename T>
     154       52890 : int UnsignedGreaterEqual(T a, T b) {
     155             :   using UnsignedT = typename std::make_unsigned<T>::type;
     156       52890 :   return static_cast<UnsignedT>(a) >= static_cast<UnsignedT>(b) ? -1 : 0;
     157             : }
     158             : 
     159             : template <typename T>
     160       29940 : T LogicalShiftLeft(T a, int shift) {
     161       29940 :   return a << shift;
     162             : }
     163             : 
     164             : template <typename T>
     165       29940 : T LogicalShiftRight(T a, int shift) {
     166             :   using UnsignedT = typename std::make_unsigned<T>::type;
     167       29940 :   return static_cast<UnsignedT>(a) >> shift;
     168             : }
     169             : 
     170             : template <typename T>
     171             : T Clamp(int64_t value) {
     172             :   static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
     173      216420 :   int64_t min = static_cast<int64_t>(std::numeric_limits<T>::min());
     174      216420 :   int64_t max = static_cast<int64_t>(std::numeric_limits<T>::max());
     175      216420 :   int64_t clamped = std::max(min, std::min(max, value));
     176      113070 :   return static_cast<T>(clamped);
     177             : }
     178             : 
     179             : template <typename T>
     180             : int64_t Widen(T value) {
     181             :   static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
     182        5130 :   return static_cast<int64_t>(value);
     183             : }
     184             : 
     185             : template <typename T>
     186             : int64_t UnsignedWiden(T value) {
     187             :   static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
     188             :   using UnsignedT = typename std::make_unsigned<T>::type;
     189        5130 :   return static_cast<int64_t>(static_cast<UnsignedT>(value));
     190             : }
     191             : 
     192             : template <typename T>
     193             : T Narrow(int64_t value) {
     194             :   return Clamp<T>(value);
     195             : }
     196             : 
     197             : template <typename T>
     198             : T UnsignedNarrow(int64_t value) {
     199             :   static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
     200             :   using UnsignedT = typename std::make_unsigned<T>::type;
     201      206700 :   return static_cast<T>(Clamp<UnsignedT>(value & 0xFFFFFFFFu));
     202             : }
     203             : 
     204             : template <typename T>
     205        2430 : T AddSaturate(T a, T b) {
     206        4860 :   return Clamp<T>(Widen(a) + Widen(b));
     207             : }
     208             : 
     209             : template <typename T>
     210        2430 : T SubSaturate(T a, T b) {
     211        4860 :   return Clamp<T>(Widen(a) - Widen(b));
     212             : }
     213             : 
     214             : template <typename T>
     215        2430 : T UnsignedAddSaturate(T a, T b) {
     216             :   using UnsignedT = typename std::make_unsigned<T>::type;
     217        4860 :   return Clamp<UnsignedT>(UnsignedWiden(a) + UnsignedWiden(b));
     218             : }
     219             : 
     220             : template <typename T>
     221        2430 : T UnsignedSubSaturate(T a, T b) {
     222             :   using UnsignedT = typename std::make_unsigned<T>::type;
     223        4860 :   return Clamp<UnsignedT>(UnsignedWiden(a) - UnsignedWiden(b));
     224             : }
     225             : 
     226             : template <typename T>
     227       50460 : T And(T a, T b) {
     228       50460 :   return a & b;
     229             : }
     230             : 
     231             : template <typename T>
     232       50460 : T Or(T a, T b) {
     233       50460 :   return a | b;
     234             : }
     235             : 
     236             : template <typename T>
     237       50460 : T Xor(T a, T b) {
     238       50460 :   return a ^ b;
     239             : }
     240             : 
     241             : template <typename T>
     242         870 : T Not(T a) {
     243         870 :   return ~a;
     244             : }
     245             : 
     246             : template <typename T>
     247             : T LogicalNot(T a) {
     248             :   return a == 0 ? -1 : 0;
     249             : }
     250             : 
     251             : template <typename T>
     252             : T Sqrt(T a) {
     253             :   return std::sqrt(a);
     254             : }
     255             : 
     256             : }  // namespace
     257             : 
     258             : #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \
     259             :   WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value),                  \
     260             :                                 WASM_SIMD_##TYPE##_EXTRACT_LANE(             \
     261             :                                     lane_index, WASM_GET_LOCAL(value))),     \
     262             :           WASM_RETURN1(WASM_ZERO))
     263             : 
     264             : #define WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3) \
     265             :   WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0)               \
     266             :   , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1),            \
     267             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2),          \
     268             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3)
     269             : 
     270             : #define WASM_SIMD_CHECK_SPLAT4(TYPE, value, LANE_TYPE, lv) \
     271             :   WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv, lv, lv, lv)
     272             : 
     273             : #define WASM_SIMD_CHECK8(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3, lv4, lv5, \
     274             :                          lv6, lv7)                                             \
     275             :   WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0)                         \
     276             :   , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1),                      \
     277             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2),                    \
     278             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3),                    \
     279             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv4, 4),                    \
     280             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv5, 5),                    \
     281             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv6, 6),                    \
     282             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv7, 7)
     283             : 
     284             : #define WASM_SIMD_CHECK_SPLAT8(TYPE, value, LANE_TYPE, lv) \
     285             :   WASM_SIMD_CHECK8(TYPE, value, LANE_TYPE, lv, lv, lv, lv, lv, lv, lv, lv)
     286             : 
     287             : #define WASM_SIMD_CHECK16(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3, lv4, \
     288             :                           lv5, lv6, lv7, lv8, lv9, lv10, lv11, lv12, lv13, \
     289             :                           lv14, lv15)                                      \
     290             :   WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0)                     \
     291             :   , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1),                  \
     292             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2),                \
     293             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3),                \
     294             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv4, 4),                \
     295             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv5, 5),                \
     296             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv6, 6),                \
     297             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv7, 7),                \
     298             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv8, 8),                \
     299             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv9, 9),                \
     300             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv10, 10),              \
     301             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv11, 11),              \
     302             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv12, 12),              \
     303             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv13, 13),              \
     304             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv14, 14),              \
     305             :       WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv15, 15)
     306             : 
     307             : #define WASM_SIMD_CHECK_SPLAT16(TYPE, value, LANE_TYPE, lv)                 \
     308             :   WASM_SIMD_CHECK16(TYPE, value, LANE_TYPE, lv, lv, lv, lv, lv, lv, lv, lv, \
     309             :                     lv, lv, lv, lv, lv, lv, lv, lv)
     310             : 
     311             : #define WASM_SIMD_CHECK_F32_LANE(value, lane_value, lane_index)             \
     312             :   WASM_IF(WASM_F32_NE(WASM_GET_LOCAL(lane_value),                           \
     313             :                       WASM_SIMD_F32x4_EXTRACT_LANE(lane_index,              \
     314             :                                                    WASM_GET_LOCAL(value))), \
     315             :           WASM_RETURN1(WASM_ZERO))
     316             : 
     317             : #define WASM_SIMD_CHECK_F32x4(value, lv0, lv1, lv2, lv3) \
     318             :   WASM_SIMD_CHECK_F32_LANE(value, lv0, 0)                \
     319             :   , WASM_SIMD_CHECK_F32_LANE(value, lv1, 1),             \
     320             :       WASM_SIMD_CHECK_F32_LANE(value, lv2, 2),           \
     321             :       WASM_SIMD_CHECK_F32_LANE(value, lv3, 3)
     322             : 
     323             : #define WASM_SIMD_CHECK_SPLAT_F32x4(value, lv) \
     324             :   WASM_SIMD_CHECK_F32x4(value, lv, lv, lv, lv)
     325             : 
     326             : #define WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, lane_index)       \
     327             :   WASM_IF(WASM_F32_GT(WASM_GET_LOCAL(low),                                    \
     328             :                       WASM_SIMD_F32x4_EXTRACT_LANE(lane_index,                \
     329             :                                                    WASM_GET_LOCAL(value))),   \
     330             :           WASM_RETURN1(WASM_ZERO))                                            \
     331             :   , WASM_IF(WASM_F32_LT(WASM_GET_LOCAL(high),                                 \
     332             :                         WASM_SIMD_F32x4_EXTRACT_LANE(lane_index,              \
     333             :                                                      WASM_GET_LOCAL(value))), \
     334             :             WASM_RETURN1(WASM_ZERO))
     335             : 
     336             : #define WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE(value, low, high) \
     337             :   WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 0)       \
     338             :   , WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 1),    \
     339             :       WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 2),  \
     340             :       WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 3)
     341             : 
     342             : #define TO_BYTE(val) static_cast<byte>(val)
     343             : #define WASM_SIMD_OP(op) kSimdPrefix, TO_BYTE(op)
     344             : #define WASM_SIMD_SPLAT(Type, x) x, WASM_SIMD_OP(kExpr##Type##Splat)
     345             : #define WASM_SIMD_UNOP(op, x) x, WASM_SIMD_OP(op)
     346             : #define WASM_SIMD_BINOP(op, x, y) x, y, WASM_SIMD_OP(op)
     347             : #define WASM_SIMD_SHIFT_OP(op, shift, x) x, WASM_SIMD_OP(op), TO_BYTE(shift)
     348             : #define WASM_SIMD_CONCAT_OP(op, bytes, x, y) \
     349             :   x, y, WASM_SIMD_OP(op), TO_BYTE(bytes)
     350             : #define WASM_SIMD_SELECT(format, x, y, z) x, y, z, WASM_SIMD_OP(kExprS128Select)
     351             : #define WASM_SIMD_F32x4_SPLAT(x) x, WASM_SIMD_OP(kExprF32x4Splat)
     352             : #define WASM_SIMD_F32x4_EXTRACT_LANE(lane, x) \
     353             :   x, WASM_SIMD_OP(kExprF32x4ExtractLane), TO_BYTE(lane)
     354             : #define WASM_SIMD_F32x4_REPLACE_LANE(lane, x, y) \
     355             :   x, y, WASM_SIMD_OP(kExprF32x4ReplaceLane), TO_BYTE(lane)
     356             : 
     357             : #define WASM_SIMD_I32x4_SPLAT(x) x, WASM_SIMD_OP(kExprI32x4Splat)
     358             : #define WASM_SIMD_I32x4_EXTRACT_LANE(lane, x) \
     359             :   x, WASM_SIMD_OP(kExprI32x4ExtractLane), TO_BYTE(lane)
     360             : #define WASM_SIMD_I32x4_REPLACE_LANE(lane, x, y) \
     361             :   x, y, WASM_SIMD_OP(kExprI32x4ReplaceLane), TO_BYTE(lane)
     362             : 
     363             : #define WASM_SIMD_I16x8_SPLAT(x) x, WASM_SIMD_OP(kExprI16x8Splat)
     364             : #define WASM_SIMD_I16x8_EXTRACT_LANE(lane, x) \
     365             :   x, WASM_SIMD_OP(kExprI16x8ExtractLane), TO_BYTE(lane)
     366             : #define WASM_SIMD_I16x8_REPLACE_LANE(lane, x, y) \
     367             :   x, y, WASM_SIMD_OP(kExprI16x8ReplaceLane), TO_BYTE(lane)
     368             : 
     369             : #define WASM_SIMD_I8x16_SPLAT(x) x, WASM_SIMD_OP(kExprI8x16Splat)
     370             : #define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \
     371             :   x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane)
     372             : #define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \
     373             :   x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane)
     374             : 
     375             : #define WASM_SIMD_S8x16_SHUFFLE_OP(opcode, m, x, y)                        \
     376             :   x, y, WASM_SIMD_OP(opcode), TO_BYTE(m[0]), TO_BYTE(m[1]), TO_BYTE(m[2]), \
     377             :       TO_BYTE(m[3]), TO_BYTE(m[4]), TO_BYTE(m[5]), TO_BYTE(m[6]),          \
     378             :       TO_BYTE(m[7]), TO_BYTE(m[8]), TO_BYTE(m[9]), TO_BYTE(m[10]),         \
     379             :       TO_BYTE(m[11]), TO_BYTE(m[12]), TO_BYTE(m[13]), TO_BYTE(m[14]),      \
     380             :       TO_BYTE(m[15])
     381             : 
     382             : #define WASM_SIMD_LOAD_MEM(index) \
     383             :   index, WASM_SIMD_OP(kExprS128LoadMem), ZERO_ALIGNMENT, ZERO_OFFSET
     384             : #define WASM_SIMD_STORE_MEM(index, val) \
     385             :   index, val, WASM_SIMD_OP(kExprS128StoreMem), ZERO_ALIGNMENT, ZERO_OFFSET
     386             : 
     387             : // Skip FP tests involving extremely large or extremely small values, which
     388             : // may fail due to non-IEEE-754 SIMD arithmetic on some platforms.
     389           0 : bool SkipFPValue(float x) {
     390             :   float abs_x = std::fabs(x);
     391             :   const float kSmallFloatThreshold = 1.0e-32f;
     392             :   const float kLargeFloatThreshold = 1.0e32f;
     393     3363900 :   return abs_x != 0.0f &&  // 0 or -0 are fine.
     394     3240495 :          (abs_x < kSmallFloatThreshold || abs_x > kLargeFloatThreshold);
     395             : }
     396             : 
     397             : // Skip tests where the expected value is a NaN, since our wasm test code
     398             : // doesn't handle NaNs. Also skip extreme values.
     399     3055755 : bool SkipFPExpectedValue(float x) { return std::isnan(x) || SkipFPValue(x); }
     400             : 
     401       28397 : WASM_SIMD_TEST(F32x4Splat) {
     402             :   WasmRunner<int32_t, float> r(execution_tier, lower_simd);
     403             :   byte lane_val = 0;
     404             :   byte simd = r.AllocateLocal(kWasmS128);
     405          15 :   BUILD(r,
     406             :         WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
     407             :         WASM_SIMD_CHECK_SPLAT_F32x4(simd, lane_val), WASM_RETURN1(WASM_ONE));
     408             : 
     409        1740 :   FOR_FLOAT32_INPUTS(i) {
     410        3450 :     if (SkipFPExpectedValue(*i)) continue;
     411        1425 :     CHECK_EQ(1, r.Call(*i));
     412             :   }
     413          15 : }
     414             : 
     415       28397 : WASM_SIMD_TEST(F32x4ReplaceLane) {
     416             :   WasmRunner<int32_t, float, float> r(execution_tier, lower_simd);
     417             :   byte old_val = 0;
     418             :   byte new_val = 1;
     419             :   byte simd = r.AllocateLocal(kWasmS128);
     420          15 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
     421             :         WASM_SET_LOCAL(simd,
     422             :                        WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
     423             :                                                     WASM_GET_LOCAL(new_val))),
     424             :         WASM_SIMD_CHECK_F32x4(simd, new_val, old_val, old_val, old_val),
     425             :         WASM_SET_LOCAL(simd,
     426             :                        WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
     427             :                                                     WASM_GET_LOCAL(new_val))),
     428             :         WASM_SIMD_CHECK_F32x4(simd, new_val, new_val, old_val, old_val),
     429             :         WASM_SET_LOCAL(simd,
     430             :                        WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
     431             :                                                     WASM_GET_LOCAL(new_val))),
     432             :         WASM_SIMD_CHECK_F32x4(simd, new_val, new_val, new_val, old_val),
     433             :         WASM_SET_LOCAL(simd,
     434             :                        WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
     435             :                                                     WASM_GET_LOCAL(new_val))),
     436             :         WASM_SIMD_CHECK_SPLAT_F32x4(simd, new_val), WASM_RETURN1(WASM_ONE));
     437             : 
     438          15 :   CHECK_EQ(1, r.Call(3.14159f, -1.5f));
     439          15 : }
     440             : 
     441             : // Runs tests of compiled code, using the interpreter as a reference.
     442             : #define WASM_SIMD_COMPILED_TEST(name)                               \
     443             :   void RunWasm_##name##_Impl(LowerSimd lower_simd,                  \
     444             :                              ExecutionTier execution_tier);         \
     445             :   TEST(RunWasm_##name##_turbofan) {                                 \
     446             :     EXPERIMENTAL_FLAG_SCOPE(simd);                                  \
     447             :     RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kOptimized); \
     448             :   }                                                                 \
     449             :   TEST(RunWasm_##name##_simd_lowered) {                             \
     450             :     EXPERIMENTAL_FLAG_SCOPE(simd);                                  \
     451             :     RunWasm_##name##_Impl(kLowerSimd, ExecutionTier::kOptimized);   \
     452             :   }                                                                 \
     453             :   void RunWasm_##name##_Impl(LowerSimd lower_simd, ExecutionTier execution_tier)
     454             : 
     455             : // The macro below disables tests lowering for certain nodes where the simd
     456             : // lowering doesn't work correctly. Early return here if the CPU does not
     457             : // support SIMD as the graph will be implicitly lowered in that case.
     458             : #define WASM_SIMD_TEST_TURBOFAN(name)                               \
     459             :   void RunWasm_##name##_Impl(LowerSimd lower_simd,                  \
     460             :                              ExecutionTier execution_tier);         \
     461             :   TEST(RunWasm_##name##_turbofan) {                                 \
     462             :     if (!CpuFeatures::SupportsWasmSimd128()) return;                \
     463             :     EXPERIMENTAL_FLAG_SCOPE(simd);                                  \
     464             :     RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kOptimized); \
     465             :   }                                                                 \
     466             :   void RunWasm_##name##_Impl(LowerSimd lower_simd, ExecutionTier execution_tier)
     467             : 
     468             : // Tests both signed and unsigned conversion.
     469             : // v8:8425 tracks this test being enabled in the interpreter.
     470       28377 : WASM_SIMD_COMPILED_TEST(F32x4ConvertI32x4) {
     471             :   WasmRunner<int32_t, int32_t, float, float> r(execution_tier, lower_simd);
     472             :   byte a = 0;
     473             :   byte expected_signed = 1;
     474             :   byte expected_unsigned = 2;
     475             :   byte simd0 = r.AllocateLocal(kWasmS128);
     476             :   byte simd1 = r.AllocateLocal(kWasmS128);
     477             :   byte simd2 = r.AllocateLocal(kWasmS128);
     478          10 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
     479             :         WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprF32x4SConvertI32x4,
     480             :                                              WASM_GET_LOCAL(simd0))),
     481             :         WASM_SIMD_CHECK_SPLAT_F32x4(simd1, expected_signed),
     482             :         WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprF32x4UConvertI32x4,
     483             :                                              WASM_GET_LOCAL(simd0))),
     484             :         WASM_SIMD_CHECK_SPLAT_F32x4(simd2, expected_unsigned),
     485             :         WASM_RETURN1(WASM_ONE));
     486             : 
     487         590 :   FOR_INT32_INPUTS(i) {
     488         580 :     CHECK_EQ(1, r.Call(*i, static_cast<float>(*i),
     489             :                        static_cast<float>(static_cast<uint32_t>(*i))));
     490             :   }
     491          10 : }
     492             : 
     493          60 : void RunF32x4UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
     494             :                       WasmOpcode simd_op, FloatUnOp expected_op,
     495             :                       float error = 0.0f) {
     496             :   WasmRunner<int32_t, float, float, float> r(execution_tier, lower_simd);
     497             :   byte a = 0;
     498             :   byte low = 1;
     499             :   byte high = 2;
     500             :   byte simd = r.AllocateLocal(kWasmS128);
     501          60 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
     502             :         WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
     503             :         WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE(simd, low, high),
     504             :         WASM_RETURN1(WASM_ONE));
     505             : 
     506        6960 :   FOR_FLOAT32_INPUTS(i) {
     507       13800 :     if (SkipFPValue(*i)) continue;
     508        5820 :     float expected = expected_op(*i);
     509        5820 :     if (SkipFPExpectedValue(expected)) continue;
     510        4845 :     float abs_error = std::abs(expected) * error;
     511        4845 :     CHECK_EQ(1, r.Call(*i, expected - abs_error, expected + abs_error));
     512             :   }
     513          60 : }
     514             : 
     515       28367 : WASM_SIMD_TEST(F32x4Abs) {
     516          15 :   RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4Abs, std::abs);
     517           0 : }
     518       28367 : WASM_SIMD_TEST(F32x4Neg) {
     519          15 :   RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4Neg, Negate);
     520           0 : }
     521             : 
     522             : static const float kApproxError = 0.01f;
     523             : 
     524       28367 : WASM_SIMD_TEST(F32x4RecipApprox) {
     525             :   RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4RecipApprox,
     526          15 :                    base::Recip, kApproxError);
     527           0 : }
     528             : 
     529       28367 : WASM_SIMD_TEST(F32x4RecipSqrtApprox) {
     530             :   RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4RecipSqrtApprox,
     531          15 :                    base::RecipSqrt, kApproxError);
     532           0 : }
     533             : 
     534          75 : void RunF32x4BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
     535             :                        WasmOpcode simd_op, FloatBinOp expected_op) {
     536             :   WasmRunner<int32_t, float, float, float> r(execution_tier, lower_simd);
     537             :   byte a = 0;
     538             :   byte b = 1;
     539             :   byte expected = 2;
     540             :   byte simd0 = r.AllocateLocal(kWasmS128);
     541             :   byte simd1 = r.AllocateLocal(kWasmS128);
     542          75 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
     543             :         WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
     544             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
     545             :                                               WASM_GET_LOCAL(simd1))),
     546             :         WASM_SIMD_CHECK_SPLAT_F32x4(simd1, expected), WASM_RETURN1(WASM_ONE));
     547             : 
     548        8700 :   FOR_FLOAT32_INPUTS(i) {
     549       17250 :     if (SkipFPValue(*i)) continue;
     550      836625 :     FOR_FLOAT32_INPUTS(j) {
     551     1673250 :       if (SkipFPValue(*j)) continue;
     552      705675 :       float expected = expected_op(*i, *j);
     553      705675 :       if (SkipFPExpectedValue(expected)) continue;
     554      662340 :       CHECK_EQ(1, r.Call(*i, *j, expected));
     555             :     }
     556             :   }
     557          75 : }
     558             : 
     559       28367 : WASM_SIMD_TEST(F32x4Add) {
     560          15 :   RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Add, Add);
     561           0 : }
     562       28367 : WASM_SIMD_TEST(F32x4Sub) {
     563          15 :   RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Sub, Sub);
     564           0 : }
     565       28367 : WASM_SIMD_TEST(F32x4Mul) {
     566          15 :   RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Mul, Mul);
     567           0 : }
     568       28367 : WASM_SIMD_TEST(F32x4_Min) {
     569          15 :   RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Min, JSMin);
     570           0 : }
     571       28367 : WASM_SIMD_TEST(F32x4_Max) {
     572          15 :   RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Max, JSMax);
     573           0 : }
     574             : 
     575          90 : void RunF32x4CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
     576             :                            WasmOpcode simd_op, FloatCompareOp expected_op) {
     577             :   WasmRunner<int32_t, float, float, int32_t> r(execution_tier, lower_simd);
     578             :   byte a = 0;
     579             :   byte b = 1;
     580             :   byte expected = 2;
     581             :   byte simd0 = r.AllocateLocal(kWasmS128);
     582             :   byte simd1 = r.AllocateLocal(kWasmS128);
     583          90 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
     584             :         WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
     585             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
     586             :                                               WASM_GET_LOCAL(simd1))),
     587             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
     588             : 
     589       10440 :   FOR_FLOAT32_INPUTS(i) {
     590       20700 :     if (SkipFPValue(*i)) continue;
     591     1003950 :     FOR_FLOAT32_INPUTS(j) {
     592     2007900 :       if (SkipFPValue(*j)) continue;
     593      846810 :       float diff = *i - *j;
     594      846810 :       if (SkipFPExpectedValue(diff)) continue;
     595      812250 :       CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j)));
     596             :     }
     597             :   }
     598          90 : }
     599             : 
     600       28367 : WASM_SIMD_TEST(F32x4Eq) {
     601          15 :   RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Eq, Equal);
     602           0 : }
     603             : 
     604       28367 : WASM_SIMD_TEST(F32x4Ne) {
     605          15 :   RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Ne, NotEqual);
     606           0 : }
     607             : 
     608       28367 : WASM_SIMD_TEST(F32x4Gt) {
     609          15 :   RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Gt, Greater);
     610           0 : }
     611             : 
     612       28367 : WASM_SIMD_TEST(F32x4Ge) {
     613          15 :   RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Ge, GreaterEqual);
     614           0 : }
     615             : 
     616       28367 : WASM_SIMD_TEST(F32x4Lt) {
     617          15 :   RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Lt, Less);
     618           0 : }
     619             : 
     620       28367 : WASM_SIMD_TEST(F32x4Le) {
     621          15 :   RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Le, LessEqual);
     622           0 : }
     623             : 
     624       28397 : WASM_SIMD_TEST(I32x4Splat) {
     625             :   // Store SIMD value in a local variable, use extract lane to check lane values
     626             :   // This test is not a test for ExtractLane as Splat does not create
     627             :   // interesting SIMD values.
     628             :   //
     629             :   // SetLocal(1, I32x4Splat(Local(0)));
     630             :   // For each lane index
     631             :   // if(Local(0) != I32x4ExtractLane(Local(1), index)
     632             :   //   return 0
     633             :   //
     634             :   // return 1
     635             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
     636             :   byte lane_val = 0;
     637             :   byte simd = r.AllocateLocal(kWasmS128);
     638          15 :   BUILD(r,
     639             :         WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
     640             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), WASM_ONE);
     641             : 
     642          15 :   FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
     643          15 : }
     644             : 
     645       28397 : WASM_SIMD_TEST(I32x4ReplaceLane) {
     646             :   WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
     647             :   byte old_val = 0;
     648             :   byte new_val = 1;
     649             :   byte simd = r.AllocateLocal(kWasmS128);
     650          15 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
     651             :         WASM_SET_LOCAL(simd,
     652             :                        WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
     653             :                                                     WASM_GET_LOCAL(new_val))),
     654             :         WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, old_val),
     655             :         WASM_SET_LOCAL(simd,
     656             :                        WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
     657             :                                                     WASM_GET_LOCAL(new_val))),
     658             :         WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, old_val),
     659             :         WASM_SET_LOCAL(simd,
     660             :                        WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
     661             :                                                     WASM_GET_LOCAL(new_val))),
     662             :         WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val),
     663             :         WASM_SET_LOCAL(simd,
     664             :                        WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
     665             :                                                     WASM_GET_LOCAL(new_val))),
     666             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE);
     667             : 
     668          15 :   CHECK_EQ(1, r.Call(1, 2));
     669          15 : }
     670             : 
     671       28397 : WASM_SIMD_TEST(I16x8Splat) {
     672             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
     673             :   byte lane_val = 0;
     674             :   byte simd = r.AllocateLocal(kWasmS128);
     675          15 :   BUILD(r,
     676             :         WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(lane_val))),
     677             :         WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val), WASM_ONE);
     678             : 
     679          15 :   FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
     680          15 : }
     681             : 
     682       28397 : WASM_SIMD_TEST(I16x8ReplaceLane) {
     683             :   WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
     684             :   byte old_val = 0;
     685             :   byte new_val = 1;
     686             :   byte simd = r.AllocateLocal(kWasmS128);
     687          15 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(old_val))),
     688             :         WASM_SET_LOCAL(simd,
     689             :                        WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
     690             :                                                     WASM_GET_LOCAL(new_val))),
     691             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, old_val, old_val, old_val,
     692             :                          old_val, old_val, old_val, old_val),
     693             :         WASM_SET_LOCAL(simd,
     694             :                        WASM_SIMD_I16x8_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
     695             :                                                     WASM_GET_LOCAL(new_val))),
     696             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, old_val, old_val,
     697             :                          old_val, old_val, old_val, old_val),
     698             :         WASM_SET_LOCAL(simd,
     699             :                        WASM_SIMD_I16x8_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
     700             :                                                     WASM_GET_LOCAL(new_val))),
     701             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, old_val,
     702             :                          old_val, old_val, old_val, old_val),
     703             :         WASM_SET_LOCAL(simd,
     704             :                        WASM_SIMD_I16x8_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
     705             :                                                     WASM_GET_LOCAL(new_val))),
     706             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
     707             :                          old_val, old_val, old_val, old_val),
     708             :         WASM_SET_LOCAL(simd,
     709             :                        WASM_SIMD_I16x8_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
     710             :                                                     WASM_GET_LOCAL(new_val))),
     711             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
     712             :                          new_val, old_val, old_val, old_val),
     713             :         WASM_SET_LOCAL(simd,
     714             :                        WASM_SIMD_I16x8_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
     715             :                                                     WASM_GET_LOCAL(new_val))),
     716             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
     717             :                          new_val, new_val, old_val, old_val),
     718             :         WASM_SET_LOCAL(simd,
     719             :                        WASM_SIMD_I16x8_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
     720             :                                                     WASM_GET_LOCAL(new_val))),
     721             :         WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
     722             :                          new_val, new_val, new_val, old_val),
     723             :         WASM_SET_LOCAL(simd,
     724             :                        WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
     725             :                                                     WASM_GET_LOCAL(new_val))),
     726             :         WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val), WASM_ONE);
     727             : 
     728          15 :   CHECK_EQ(1, r.Call(1, 2));
     729          15 : }
     730             : 
     731       28397 : WASM_SIMD_TEST(I8x16Splat) {
     732             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
     733             :   byte lane_val = 0;
     734             :   byte simd = r.AllocateLocal(kWasmS128);
     735          15 :   BUILD(r,
     736             :         WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(lane_val))),
     737             :         WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val), WASM_ONE);
     738             : 
     739          15 :   FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
     740          15 : }
     741             : 
     742       28397 : WASM_SIMD_TEST(I8x16ReplaceLane) {
     743             :   WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
     744             :   byte old_val = 0;
     745             :   byte new_val = 1;
     746             :   byte simd = r.AllocateLocal(kWasmS128);
     747          15 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(old_val))),
     748             :         WASM_SET_LOCAL(simd,
     749             :                        WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
     750             :                                                     WASM_GET_LOCAL(new_val))),
     751             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, old_val, old_val, old_val,
     752             :                           old_val, old_val, old_val, old_val, old_val, old_val,
     753             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     754             :         WASM_SET_LOCAL(simd,
     755             :                        WASM_SIMD_I8x16_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
     756             :                                                     WASM_GET_LOCAL(new_val))),
     757             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, old_val, old_val,
     758             :                           old_val, old_val, old_val, old_val, old_val, old_val,
     759             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     760             :         WASM_SET_LOCAL(simd,
     761             :                        WASM_SIMD_I8x16_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
     762             :                                                     WASM_GET_LOCAL(new_val))),
     763             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, old_val,
     764             :                           old_val, old_val, old_val, old_val, old_val, old_val,
     765             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     766             :         WASM_SET_LOCAL(simd,
     767             :                        WASM_SIMD_I8x16_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
     768             :                                                     WASM_GET_LOCAL(new_val))),
     769             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     770             :                           old_val, old_val, old_val, old_val, old_val, old_val,
     771             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     772             :         WASM_SET_LOCAL(simd,
     773             :                        WASM_SIMD_I8x16_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
     774             :                                                     WASM_GET_LOCAL(new_val))),
     775             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     776             :                           new_val, old_val, old_val, old_val, old_val, old_val,
     777             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     778             :         WASM_SET_LOCAL(simd,
     779             :                        WASM_SIMD_I8x16_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
     780             :                                                     WASM_GET_LOCAL(new_val))),
     781             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     782             :                           new_val, new_val, old_val, old_val, old_val, old_val,
     783             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     784             :         WASM_SET_LOCAL(simd,
     785             :                        WASM_SIMD_I8x16_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
     786             :                                                     WASM_GET_LOCAL(new_val))),
     787             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     788             :                           new_val, new_val, new_val, old_val, old_val, old_val,
     789             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     790             :         WASM_SET_LOCAL(simd,
     791             :                        WASM_SIMD_I8x16_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
     792             :                                                     WASM_GET_LOCAL(new_val))),
     793             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     794             :                           new_val, new_val, new_val, new_val, old_val, old_val,
     795             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     796             :         WASM_SET_LOCAL(simd,
     797             :                        WASM_SIMD_I8x16_REPLACE_LANE(8, WASM_GET_LOCAL(simd),
     798             :                                                     WASM_GET_LOCAL(new_val))),
     799             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     800             :                           new_val, new_val, new_val, new_val, new_val, old_val,
     801             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     802             :         WASM_SET_LOCAL(simd,
     803             :                        WASM_SIMD_I8x16_REPLACE_LANE(9, WASM_GET_LOCAL(simd),
     804             :                                                     WASM_GET_LOCAL(new_val))),
     805             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     806             :                           new_val, new_val, new_val, new_val, new_val, new_val,
     807             :                           old_val, old_val, old_val, old_val, old_val, old_val),
     808             :         WASM_SET_LOCAL(simd,
     809             :                        WASM_SIMD_I8x16_REPLACE_LANE(10, WASM_GET_LOCAL(simd),
     810             :                                                     WASM_GET_LOCAL(new_val))),
     811             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     812             :                           new_val, new_val, new_val, new_val, new_val, new_val,
     813             :                           new_val, old_val, old_val, old_val, old_val, old_val),
     814             :         WASM_SET_LOCAL(simd,
     815             :                        WASM_SIMD_I8x16_REPLACE_LANE(11, WASM_GET_LOCAL(simd),
     816             :                                                     WASM_GET_LOCAL(new_val))),
     817             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     818             :                           new_val, new_val, new_val, new_val, new_val, new_val,
     819             :                           new_val, new_val, old_val, old_val, old_val, old_val),
     820             :         WASM_SET_LOCAL(simd,
     821             :                        WASM_SIMD_I8x16_REPLACE_LANE(12, WASM_GET_LOCAL(simd),
     822             :                                                     WASM_GET_LOCAL(new_val))),
     823             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     824             :                           new_val, new_val, new_val, new_val, new_val, new_val,
     825             :                           new_val, new_val, new_val, old_val, old_val, old_val),
     826             :         WASM_SET_LOCAL(simd,
     827             :                        WASM_SIMD_I8x16_REPLACE_LANE(13, WASM_GET_LOCAL(simd),
     828             :                                                     WASM_GET_LOCAL(new_val))),
     829             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     830             :                           new_val, new_val, new_val, new_val, new_val, new_val,
     831             :                           new_val, new_val, new_val, new_val, old_val, old_val),
     832             :         WASM_SET_LOCAL(simd,
     833             :                        WASM_SIMD_I8x16_REPLACE_LANE(14, WASM_GET_LOCAL(simd),
     834             :                                                     WASM_GET_LOCAL(new_val))),
     835             :         WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
     836             :                           new_val, new_val, new_val, new_val, new_val, new_val,
     837             :                           new_val, new_val, new_val, new_val, new_val, old_val),
     838             :         WASM_SET_LOCAL(simd,
     839             :                        WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd),
     840             :                                                     WASM_GET_LOCAL(new_val))),
     841             :         WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val), WASM_ONE);
     842             : 
     843          15 :   CHECK_EQ(1, r.Call(1, 2));
     844          15 : }
     845             : 
     846           0 : int32_t ConvertToInt(double val, bool unsigned_integer) {
     847        2910 :   if (std::isnan(val)) return 0;
     848           0 :   if (unsigned_integer) {
     849        1425 :     if (val < 0) return 0;
     850         630 :     if (val > kMaxUInt32) return kMaxUInt32;
     851         420 :     return static_cast<uint32_t>(val);
     852             :   } else {
     853        1425 :     if (val < kMinInt) return kMinInt;
     854        1230 :     if (val > kMaxInt) return kMaxInt;
     855        1005 :     return static_cast<int>(val);
     856             :   }
     857             : }
     858             : 
     859             : // Tests both signed and unsigned conversion.
     860       28397 : WASM_SIMD_TEST(I32x4ConvertF32x4) {
     861             :   WasmRunner<int32_t, float, int32_t, int32_t> r(execution_tier, lower_simd);
     862             :   byte a = 0;
     863             :   byte expected_signed = 1;
     864             :   byte expected_unsigned = 2;
     865             :   byte simd0 = r.AllocateLocal(kWasmS128);
     866             :   byte simd1 = r.AllocateLocal(kWasmS128);
     867             :   byte simd2 = r.AllocateLocal(kWasmS128);
     868          15 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
     869             :         WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprI32x4SConvertF32x4,
     870             :                                              WASM_GET_LOCAL(simd0))),
     871             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed),
     872             :         WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprI32x4UConvertF32x4,
     873             :                                              WASM_GET_LOCAL(simd0))),
     874             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE);
     875             : 
     876        1740 :   FOR_FLOAT32_INPUTS(i) {
     877        3450 :     if (SkipFPValue(*i)) continue;
     878        1455 :     int32_t signed_value = ConvertToInt(*i, false);
     879             :     int32_t unsigned_value = ConvertToInt(*i, true);
     880        1455 :     CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value));
     881             :   }
     882          15 : }
     883             : 
     884             : // Tests both signed and unsigned conversion from I16x8 (unpacking).
     885       28397 : WASM_SIMD_TEST(I32x4ConvertI16x8) {
     886             :   WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t> r(execution_tier,
     887             :                                                             lower_simd);
     888             :   byte a = 0;
     889             :   byte unpacked_signed = 1;
     890             :   byte unpacked_unsigned = 2;
     891             :   byte zero_value = 3;
     892             :   byte simd0 = r.AllocateLocal(kWasmS128);
     893             :   byte simd1 = r.AllocateLocal(kWasmS128);
     894             :   byte simd2 = r.AllocateLocal(kWasmS128);
     895             :   byte simd3 = r.AllocateLocal(kWasmS128);
     896             :   byte simd4 = r.AllocateLocal(kWasmS128);
     897          15 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
     898             :         WASM_SET_LOCAL(
     899             :             simd0, WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd0),
     900             :                                                 WASM_GET_LOCAL(zero_value))),
     901             :         WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprI32x4SConvertI16x8High,
     902             :                                              WASM_GET_LOCAL(simd0))),
     903             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, unpacked_signed),
     904             :         WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprI32x4UConvertI16x8High,
     905             :                                              WASM_GET_LOCAL(simd0))),
     906             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, unpacked_unsigned),
     907             :         WASM_SET_LOCAL(simd3, WASM_SIMD_UNOP(kExprI32x4SConvertI16x8Low,
     908             :                                              WASM_GET_LOCAL(simd0))),
     909             :         WASM_SIMD_CHECK4(I32x4, simd3, I32, zero_value, unpacked_signed,
     910             :                          unpacked_signed, unpacked_signed),
     911             :         WASM_SET_LOCAL(simd4, WASM_SIMD_UNOP(kExprI32x4UConvertI16x8Low,
     912             :                                              WASM_GET_LOCAL(simd0))),
     913             :         WASM_SIMD_CHECK4(I32x4, simd4, I32, zero_value, unpacked_unsigned,
     914             :                          unpacked_unsigned, unpacked_unsigned),
     915             :         WASM_ONE);
     916             : 
     917         150 :   FOR_INT16_INPUTS(i) {
     918         270 :     int32_t unpacked_signed = static_cast<int32_t>(Widen<int16_t>(*i));
     919             :     int32_t unpacked_unsigned =
     920         135 :         static_cast<int32_t>(UnsignedWiden<int16_t>(*i));
     921         135 :     CHECK_EQ(1, r.Call(*i, unpacked_signed, unpacked_unsigned, 0));
     922             :   }
     923          15 : }
     924             : 
     925          30 : void RunI32x4UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
     926             :                       WasmOpcode simd_op, Int32UnOp expected_op) {
     927             :   WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
     928             :   byte a = 0;
     929             :   byte expected = 1;
     930             :   byte simd = r.AllocateLocal(kWasmS128);
     931          30 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
     932             :         WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
     933             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
     934             : 
     935          30 :   FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
     936          30 : }
     937             : 
     938       28367 : WASM_SIMD_TEST(I32x4Neg) {
     939             :   RunI32x4UnOpTest(execution_tier, lower_simd, kExprI32x4Neg,
     940          15 :                    base::NegateWithWraparound);
     941           0 : }
     942             : 
     943       28367 : WASM_SIMD_TEST(S128Not) {
     944          15 :   RunI32x4UnOpTest(execution_tier, lower_simd, kExprS128Not, Not);
     945           0 : }
     946             : 
     947         150 : void RunI32x4BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
     948             :                        WasmOpcode simd_op, Int32BinOp expected_op) {
     949             :   WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
     950             :   byte a = 0;
     951             :   byte b = 1;
     952             :   byte expected = 2;
     953             :   byte simd0 = r.AllocateLocal(kWasmS128);
     954             :   byte simd1 = r.AllocateLocal(kWasmS128);
     955         150 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
     956             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
     957             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
     958             :                                               WASM_GET_LOCAL(simd1))),
     959             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
     960             : 
     961        8850 :   FOR_INT32_INPUTS(i) {
     962      504600 :     FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
     963             :   }
     964         150 : }
     965             : 
     966       28367 : WASM_SIMD_TEST(I32x4Add) {
     967             :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4Add,
     968          15 :                     base::AddWithWraparound);
     969           0 : }
     970             : 
     971       28367 : WASM_SIMD_TEST(I32x4Sub) {
     972             :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4Sub,
     973          15 :                     base::SubWithWraparound);
     974           0 : }
     975             : 
     976       28367 : WASM_SIMD_TEST(I32x4Mul) {
     977             :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4Mul,
     978          15 :                     base::MulWithWraparound);
     979           0 : }
     980             : 
     981       28367 : WASM_SIMD_TEST(I32x4MinS) {
     982          15 :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MinS, Minimum);
     983           0 : }
     984             : 
     985       28367 : WASM_SIMD_TEST(I32x4MaxS) {
     986          15 :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MaxS, Maximum);
     987           0 : }
     988             : 
     989       28367 : WASM_SIMD_TEST(I32x4MinU) {
     990             :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MinU,
     991          15 :                     UnsignedMinimum);
     992           0 : }
     993       28367 : WASM_SIMD_TEST(I32x4MaxU) {
     994             :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MaxU,
     995             : 
     996          15 :                     UnsignedMaximum);
     997           0 : }
     998             : 
     999       28367 : WASM_SIMD_TEST(S128And) {
    1000          15 :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprS128And, And);
    1001           0 : }
    1002             : 
    1003       28367 : WASM_SIMD_TEST(S128Or) {
    1004          15 :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprS128Or, Or);
    1005           0 : }
    1006             : 
    1007       28367 : WASM_SIMD_TEST(S128Xor) {
    1008          15 :   RunI32x4BinOpTest(execution_tier, lower_simd, kExprS128Xor, Xor);
    1009           0 : }
    1010             : 
    1011         150 : void RunI32x4CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1012             :                            WasmOpcode simd_op, Int32CompareOp expected_op) {
    1013             :   WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1014             :   byte a = 0;
    1015             :   byte b = 1;
    1016             :   byte expected = 2;
    1017             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1018             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1019         150 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
    1020             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
    1021             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
    1022             :                                               WASM_GET_LOCAL(simd1))),
    1023             :         WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
    1024             : 
    1025        8850 :   FOR_INT32_INPUTS(i) {
    1026      504600 :     FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
    1027             :   }
    1028         150 : }
    1029             : 
    1030       28367 : WASM_SIMD_TEST(I32x4Eq) {
    1031          15 :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4Eq, Equal);
    1032           0 : }
    1033             : 
    1034       28367 : WASM_SIMD_TEST(I32x4Ne) {
    1035          15 :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4Ne, NotEqual);
    1036           0 : }
    1037             : 
    1038       28367 : WASM_SIMD_TEST(I32x4LtS) {
    1039          15 :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LtS, Less);
    1040           0 : }
    1041             : 
    1042       28367 : WASM_SIMD_TEST(I32x4LeS) {
    1043          15 :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LeS, LessEqual);
    1044           0 : }
    1045             : 
    1046       28367 : WASM_SIMD_TEST(I32x4GtS) {
    1047          15 :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GtS, Greater);
    1048           0 : }
    1049             : 
    1050       28367 : WASM_SIMD_TEST(I32x4GeS) {
    1051             :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GeS,
    1052          15 :                         GreaterEqual);
    1053           0 : }
    1054             : 
    1055       28367 : WASM_SIMD_TEST(I32x4LtU) {
    1056             :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LtU,
    1057          15 :                         UnsignedLess);
    1058           0 : }
    1059             : 
    1060       28367 : WASM_SIMD_TEST(I32x4LeU) {
    1061             :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LeU,
    1062          15 :                         UnsignedLessEqual);
    1063           0 : }
    1064             : 
    1065       28367 : WASM_SIMD_TEST(I32x4GtU) {
    1066             :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GtU,
    1067          15 :                         UnsignedGreater);
    1068           0 : }
    1069             : 
    1070       28367 : WASM_SIMD_TEST(I32x4GeU) {
    1071             :   RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GeU,
    1072          15 :                         UnsignedGreaterEqual);
    1073           0 : }
    1074             : 
    1075          45 : void RunI32x4ShiftOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1076             :                          WasmOpcode simd_op, Int32ShiftOp expected_op) {
    1077        1440 :   for (int shift = 1; shift < 32; ++shift) {
    1078             :     WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1079             :     byte a = 0;
    1080             :     byte expected = 1;
    1081             :     byte simd = r.AllocateLocal(kWasmS128);
    1082        1395 :     BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
    1083             :           WASM_SET_LOCAL(
    1084             :               simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
    1085             :           WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
    1086             : 
    1087        1395 :     FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); }
    1088             :   }
    1089          45 : }
    1090             : 
    1091       28367 : WASM_SIMD_TEST(I32x4Shl) {
    1092             :   RunI32x4ShiftOpTest(execution_tier, lower_simd, kExprI32x4Shl,
    1093          15 :                       LogicalShiftLeft);
    1094           0 : }
    1095             : 
    1096       28367 : WASM_SIMD_TEST(I32x4ShrS) {
    1097             :   RunI32x4ShiftOpTest(execution_tier, lower_simd, kExprI32x4ShrS,
    1098          15 :                       ArithmeticShiftRight);
    1099           0 : }
    1100             : 
    1101       28367 : WASM_SIMD_TEST(I32x4ShrU) {
    1102             :   RunI32x4ShiftOpTest(execution_tier, lower_simd, kExprI32x4ShrU,
    1103          15 :                       LogicalShiftRight);
    1104           0 : }
    1105             : 
    1106             : // Tests both signed and unsigned conversion from I8x16 (unpacking).
    1107       28397 : WASM_SIMD_TEST(I16x8ConvertI8x16) {
    1108             :   WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t> r(execution_tier,
    1109             :                                                             lower_simd);
    1110             :   byte a = 0;
    1111             :   byte unpacked_signed = 1;
    1112             :   byte unpacked_unsigned = 2;
    1113             :   byte zero_value = 3;
    1114             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1115             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1116             :   byte simd2 = r.AllocateLocal(kWasmS128);
    1117             :   byte simd3 = r.AllocateLocal(kWasmS128);
    1118             :   byte simd4 = r.AllocateLocal(kWasmS128);
    1119          15 :   BUILD(
    1120             :       r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
    1121             :       WASM_SET_LOCAL(simd0,
    1122             :                      WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd0),
    1123             :                                                   WASM_GET_LOCAL(zero_value))),
    1124             :       WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprI16x8SConvertI8x16High,
    1125             :                                            WASM_GET_LOCAL(simd0))),
    1126             :       WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, unpacked_signed),
    1127             :       WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprI16x8UConvertI8x16High,
    1128             :                                            WASM_GET_LOCAL(simd0))),
    1129             :       WASM_SIMD_CHECK_SPLAT8(I16x8, simd2, I32, unpacked_unsigned),
    1130             :       WASM_SET_LOCAL(simd3, WASM_SIMD_UNOP(kExprI16x8SConvertI8x16Low,
    1131             :                                            WASM_GET_LOCAL(simd0))),
    1132             :       WASM_SIMD_CHECK8(I16x8, simd3, I32, zero_value, unpacked_signed,
    1133             :                        unpacked_signed, unpacked_signed, unpacked_signed,
    1134             :                        unpacked_signed, unpacked_signed, unpacked_signed),
    1135             :       WASM_SET_LOCAL(simd4, WASM_SIMD_UNOP(kExprI16x8UConvertI8x16Low,
    1136             :                                            WASM_GET_LOCAL(simd0))),
    1137             :       WASM_SIMD_CHECK8(I16x8, simd4, I32, zero_value, unpacked_unsigned,
    1138             :                        unpacked_unsigned, unpacked_unsigned, unpacked_unsigned,
    1139             :                        unpacked_unsigned, unpacked_unsigned, unpacked_unsigned),
    1140             :       WASM_ONE);
    1141             : 
    1142         150 :   FOR_INT8_INPUTS(i) {
    1143         270 :     int32_t unpacked_signed = static_cast<int32_t>(Widen<int8_t>(*i));
    1144         135 :     int32_t unpacked_unsigned = static_cast<int32_t>(UnsignedWiden<int8_t>(*i));
    1145         135 :     CHECK_EQ(1, r.Call(*i, unpacked_signed, unpacked_unsigned, 0));
    1146             :   }
    1147          15 : }
    1148             : 
    1149          15 : void RunI16x8UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1150             :                       WasmOpcode simd_op, Int16UnOp expected_op) {
    1151             :   WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1152             :   byte a = 0;
    1153             :   byte expected = 1;
    1154             :   byte simd = r.AllocateLocal(kWasmS128);
    1155          15 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
    1156             :         WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
    1157             :         WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE);
    1158             : 
    1159          15 :   FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
    1160          15 : }
    1161             : 
    1162       28367 : WASM_SIMD_TEST(I16x8Neg) {
    1163             :   RunI16x8UnOpTest(execution_tier, lower_simd, kExprI16x8Neg,
    1164          15 :                    base::NegateWithWraparound);
    1165           0 : }
    1166             : 
    1167             : // Tests both signed and unsigned conversion from I32x4 (packing).
    1168       28397 : WASM_SIMD_TEST(I16x8ConvertI32x4) {
    1169             :   WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t> r(
    1170             :       execution_tier, lower_simd);
    1171             :   byte a = 0;
    1172             :   byte b = 1;
    1173             :   // indices for packed signed params
    1174             :   byte ps_a = 2;
    1175             :   byte ps_b = 3;
    1176             :   // indices for packed unsigned params
    1177             :   byte pu_a = 4;
    1178             :   byte pu_b = 5;
    1179             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1180             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1181             :   byte simd2 = r.AllocateLocal(kWasmS128);
    1182          15 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
    1183             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
    1184             :         WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI16x8SConvertI32x4,
    1185             :                                               WASM_GET_LOCAL(simd0),
    1186             :                                               WASM_GET_LOCAL(simd1))),
    1187             :         WASM_SIMD_CHECK8(I16x8, simd2, I32, ps_a, ps_a, ps_a, ps_a, ps_b, ps_b,
    1188             :                          ps_b, ps_b),
    1189             :         WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI16x8UConvertI32x4,
    1190             :                                               WASM_GET_LOCAL(simd0),
    1191             :                                               WASM_GET_LOCAL(simd1))),
    1192             :         WASM_SIMD_CHECK8(I16x8, simd2, I32, pu_a, pu_a, pu_a, pu_a, pu_b, pu_b,
    1193             :                          pu_b, pu_b),
    1194             :         WASM_ONE);
    1195             : 
    1196         885 :   FOR_INT32_INPUTS(i) {
    1197       50460 :     FOR_INT32_INPUTS(j) {
    1198             :       // packed signed values
    1199      100920 :       int32_t ps_a = Narrow<int16_t>(*i);
    1200      100920 :       int32_t ps_b = Narrow<int16_t>(*j);
    1201             :       // packed unsigned values
    1202      100920 :       int32_t pu_a = UnsignedNarrow<int16_t>(*i);
    1203       50460 :       int32_t pu_b = UnsignedNarrow<int16_t>(*j);
    1204             :       // Sign-extend here, since ExtractLane sign extends.
    1205       50460 :       if (pu_a & 0x8000) pu_a |= 0xFFFF0000;
    1206       50460 :       if (pu_b & 0x8000) pu_b |= 0xFFFF0000;
    1207       50460 :       CHECK_EQ(1, r.Call(*i, *j, ps_a, ps_b, pu_a, pu_b));
    1208             :     }
    1209             :   }
    1210          15 : }
    1211             : 
    1212         165 : void RunI16x8BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1213             :                        WasmOpcode simd_op, Int16BinOp expected_op) {
    1214             :   WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1215             :   byte a = 0;
    1216             :   byte b = 1;
    1217             :   byte expected = 2;
    1218             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1219             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1220         165 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
    1221             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
    1222             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
    1223             :                                               WASM_GET_LOCAL(simd1))),
    1224             :         WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected), WASM_ONE);
    1225             : 
    1226        1650 :   FOR_INT16_INPUTS(i) {
    1227       13365 :     FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
    1228             :   }
    1229         165 : }
    1230             : 
    1231       28367 : WASM_SIMD_TEST(I16x8Add) {
    1232             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8Add,
    1233          15 :                     base::AddWithWraparound);
    1234           0 : }
    1235             : 
    1236       28367 : WASM_SIMD_TEST(I16x8AddSaturateS) {
    1237             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8AddSaturateS,
    1238          15 :                     AddSaturate);
    1239           0 : }
    1240             : 
    1241       28367 : WASM_SIMD_TEST(I16x8Sub) {
    1242             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8Sub,
    1243          15 :                     base::SubWithWraparound);
    1244           0 : }
    1245             : 
    1246       28367 : WASM_SIMD_TEST(I16x8SubSaturateS) {
    1247             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8SubSaturateS,
    1248          15 :                     SubSaturate);
    1249           0 : }
    1250             : 
    1251       28367 : WASM_SIMD_TEST(I16x8Mul) {
    1252             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8Mul,
    1253          15 :                     base::MulWithWraparound);
    1254           0 : }
    1255             : 
    1256       28367 : WASM_SIMD_TEST(I16x8MinS) {
    1257          15 :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MinS, Minimum);
    1258           0 : }
    1259             : 
    1260       28367 : WASM_SIMD_TEST(I16x8MaxS) {
    1261          15 :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MaxS, Maximum);
    1262           0 : }
    1263             : 
    1264       28367 : WASM_SIMD_TEST(I16x8AddSaturateU) {
    1265             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8AddSaturateU,
    1266          15 :                     UnsignedAddSaturate);
    1267           0 : }
    1268             : 
    1269       28367 : WASM_SIMD_TEST(I16x8SubSaturateU) {
    1270             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8SubSaturateU,
    1271          15 :                     UnsignedSubSaturate);
    1272           0 : }
    1273             : 
    1274       28367 : WASM_SIMD_TEST(I16x8MinU) {
    1275             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MinU,
    1276          15 :                     UnsignedMinimum);
    1277           0 : }
    1278             : 
    1279       28367 : WASM_SIMD_TEST(I16x8MaxU) {
    1280             :   RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MaxU,
    1281          15 :                     UnsignedMaximum);
    1282           0 : }
    1283             : 
    1284         150 : void RunI16x8CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1285             :                            WasmOpcode simd_op, Int16CompareOp expected_op) {
    1286             :   WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1287             :   byte a = 0;
    1288             :   byte b = 1;
    1289             :   byte expected = 2;
    1290             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1291             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1292         150 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
    1293             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
    1294             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
    1295             :                                               WASM_GET_LOCAL(simd1))),
    1296             :         WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected), WASM_ONE);
    1297             : 
    1298        1500 :   FOR_INT16_INPUTS(i) {
    1299       12150 :     FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
    1300             :   }
    1301         150 : }
    1302             : 
    1303       28367 : WASM_SIMD_TEST(I16x8Eq) {
    1304          15 :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8Eq, Equal);
    1305           0 : }
    1306             : 
    1307       28367 : WASM_SIMD_TEST(I16x8Ne) {
    1308          15 :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8Ne, NotEqual);
    1309           0 : }
    1310             : 
    1311       28367 : WASM_SIMD_TEST(I16x8LtS) {
    1312          15 :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LtS, Less);
    1313           0 : }
    1314             : 
    1315       28367 : WASM_SIMD_TEST(I16x8LeS) {
    1316          15 :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LeS, LessEqual);
    1317           0 : }
    1318             : 
    1319       28367 : WASM_SIMD_TEST(I16x8GtS) {
    1320          15 :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GtS, Greater);
    1321           0 : }
    1322             : 
    1323       28367 : WASM_SIMD_TEST(I16x8GeS) {
    1324             :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GeS,
    1325          15 :                         GreaterEqual);
    1326           0 : }
    1327             : 
    1328       28367 : WASM_SIMD_TEST(I16x8GtU) {
    1329             :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GtU,
    1330          15 :                         UnsignedGreater);
    1331           0 : }
    1332             : 
    1333       28367 : WASM_SIMD_TEST(I16x8GeU) {
    1334             :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GeU,
    1335          15 :                         UnsignedGreaterEqual);
    1336           0 : }
    1337             : 
    1338       28367 : WASM_SIMD_TEST(I16x8LtU) {
    1339             :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LtU,
    1340          15 :                         UnsignedLess);
    1341           0 : }
    1342             : 
    1343       28367 : WASM_SIMD_TEST(I16x8LeU) {
    1344             :   RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LeU,
    1345          15 :                         UnsignedLessEqual);
    1346           0 : }
    1347             : 
    1348          45 : void RunI16x8ShiftOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1349             :                          WasmOpcode simd_op, Int16ShiftOp expected_op) {
    1350         720 :   for (int shift = 1; shift < 16; ++shift) {
    1351             :     WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1352             :     byte a = 0;
    1353             :     byte expected = 1;
    1354             :     byte simd = r.AllocateLocal(kWasmS128);
    1355         675 :     BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
    1356             :           WASM_SET_LOCAL(
    1357             :               simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
    1358             :           WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE);
    1359             : 
    1360         675 :     FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); }
    1361             :   }
    1362          45 : }
    1363             : 
    1364       28367 : WASM_SIMD_TEST(I16x8Shl) {
    1365             :   RunI16x8ShiftOpTest(execution_tier, lower_simd, kExprI16x8Shl,
    1366          15 :                       LogicalShiftLeft);
    1367           0 : }
    1368             : 
    1369       28367 : WASM_SIMD_TEST(I16x8ShrS) {
    1370             :   RunI16x8ShiftOpTest(execution_tier, lower_simd, kExprI16x8ShrS,
    1371          15 :                       ArithmeticShiftRight);
    1372           0 : }
    1373             : 
    1374       28367 : WASM_SIMD_TEST(I16x8ShrU) {
    1375             :   RunI16x8ShiftOpTest(execution_tier, lower_simd, kExprI16x8ShrU,
    1376          15 :                       LogicalShiftRight);
    1377           0 : }
    1378             : 
    1379          15 : void RunI8x16UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1380             :                       WasmOpcode simd_op, Int8UnOp expected_op) {
    1381             :   WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1382             :   byte a = 0;
    1383             :   byte expected = 1;
    1384             :   byte simd = r.AllocateLocal(kWasmS128);
    1385          15 :   BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
    1386             :         WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
    1387             :         WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE);
    1388             : 
    1389          15 :   FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
    1390          15 : }
    1391             : 
    1392       28367 : WASM_SIMD_TEST(I8x16Neg) {
    1393             :   RunI8x16UnOpTest(execution_tier, lower_simd, kExprI8x16Neg,
    1394          15 :                    base::NegateWithWraparound);
    1395           0 : }
    1396             : 
    1397             : // Tests both signed and unsigned conversion from I16x8 (packing).
    1398       28397 : WASM_SIMD_TEST(I8x16ConvertI16x8) {
    1399             :   WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t> r(
    1400             :       execution_tier, lower_simd);
    1401             :   byte a = 0;
    1402             :   byte b = 1;
    1403             :   // indices for packed signed params
    1404             :   byte ps_a = 2;
    1405             :   byte ps_b = 3;
    1406             :   // indices for packed unsigned params
    1407             :   byte pu_a = 4;
    1408             :   byte pu_b = 5;
    1409             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1410             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1411             :   byte simd2 = r.AllocateLocal(kWasmS128);
    1412          15 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
    1413             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
    1414             :         WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI8x16SConvertI16x8,
    1415             :                                               WASM_GET_LOCAL(simd0),
    1416             :                                               WASM_GET_LOCAL(simd1))),
    1417             :         WASM_SIMD_CHECK16(I8x16, simd2, I32, ps_a, ps_a, ps_a, ps_a, ps_a, ps_a,
    1418             :                           ps_a, ps_a, ps_b, ps_b, ps_b, ps_b, ps_b, ps_b, ps_b,
    1419             :                           ps_b),
    1420             :         WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI8x16UConvertI16x8,
    1421             :                                               WASM_GET_LOCAL(simd0),
    1422             :                                               WASM_GET_LOCAL(simd1))),
    1423             :         WASM_SIMD_CHECK16(I8x16, simd2, I32, pu_a, pu_a, pu_a, pu_a, pu_a, pu_a,
    1424             :                           pu_a, pu_a, pu_b, pu_b, pu_b, pu_b, pu_b, pu_b, pu_b,
    1425             :                           pu_b),
    1426             :         WASM_ONE);
    1427             : 
    1428         150 :   FOR_INT16_INPUTS(i) {
    1429        1215 :     FOR_INT16_INPUTS(j) {
    1430             :       // packed signed values
    1431        2430 :       int32_t ps_a = Narrow<int8_t>(*i);
    1432        2430 :       int32_t ps_b = Narrow<int8_t>(*j);
    1433             :       // packed unsigned values
    1434        2430 :       int32_t pu_a = UnsignedNarrow<int8_t>(*i);
    1435        1215 :       int32_t pu_b = UnsignedNarrow<int8_t>(*j);
    1436             :       // Sign-extend here, since ExtractLane sign extends.
    1437        1215 :       if (pu_a & 0x80) pu_a |= 0xFFFFFF00;
    1438        1215 :       if (pu_b & 0x80) pu_b |= 0xFFFFFF00;
    1439        1215 :       CHECK_EQ(1, r.Call(*i, *j, ps_a, ps_b, pu_a, pu_b));
    1440             :     }
    1441             :   }
    1442          15 : }
    1443             : 
    1444         165 : void RunI8x16BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1445             :                        WasmOpcode simd_op, Int8BinOp expected_op) {
    1446             :   WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1447             :   byte a = 0;
    1448             :   byte b = 1;
    1449             :   byte expected = 2;
    1450             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1451             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1452         165 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
    1453             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
    1454             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
    1455             :                                               WASM_GET_LOCAL(simd1))),
    1456             :         WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected), WASM_ONE);
    1457             : 
    1458        1650 :   FOR_INT8_INPUTS(i) {
    1459       13365 :     FOR_INT8_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
    1460             :   }
    1461         165 : }
    1462             : 
    1463       28367 : WASM_SIMD_TEST(I8x16Add) {
    1464             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16Add,
    1465          15 :                     base::AddWithWraparound);
    1466           0 : }
    1467             : 
    1468       28367 : WASM_SIMD_TEST(I8x16AddSaturateS) {
    1469             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16AddSaturateS,
    1470          15 :                     AddSaturate);
    1471           0 : }
    1472             : 
    1473       28367 : WASM_SIMD_TEST(I8x16Sub) {
    1474             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16Sub,
    1475          15 :                     base::SubWithWraparound);
    1476           0 : }
    1477             : 
    1478       28367 : WASM_SIMD_TEST(I8x16SubSaturateS) {
    1479             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16SubSaturateS,
    1480          15 :                     SubSaturate);
    1481           0 : }
    1482             : 
    1483       28367 : WASM_SIMD_TEST(I8x16MinS) {
    1484          15 :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MinS, Minimum);
    1485           0 : }
    1486             : 
    1487       28367 : WASM_SIMD_TEST(I8x16MaxS) {
    1488          15 :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MaxS, Maximum);
    1489           0 : }
    1490             : 
    1491       28367 : WASM_SIMD_TEST(I8x16AddSaturateU) {
    1492             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16AddSaturateU,
    1493          15 :                     UnsignedAddSaturate);
    1494           0 : }
    1495             : 
    1496       28367 : WASM_SIMD_TEST(I8x16SubSaturateU) {
    1497             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16SubSaturateU,
    1498          15 :                     UnsignedSubSaturate);
    1499           0 : }
    1500             : 
    1501       28367 : WASM_SIMD_TEST(I8x16MinU) {
    1502             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MinU,
    1503          15 :                     UnsignedMinimum);
    1504           0 : }
    1505             : 
    1506       28367 : WASM_SIMD_TEST(I8x16MaxU) {
    1507             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MaxU,
    1508          15 :                     UnsignedMaximum);
    1509           0 : }
    1510             : 
    1511         150 : void RunI8x16CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1512             :                            WasmOpcode simd_op, Int8CompareOp expected_op) {
    1513             :   WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1514             :   byte a = 0;
    1515             :   byte b = 1;
    1516             :   byte expected = 2;
    1517             :   byte simd0 = r.AllocateLocal(kWasmS128);
    1518             :   byte simd1 = r.AllocateLocal(kWasmS128);
    1519         150 :   BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
    1520             :         WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
    1521             :         WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
    1522             :                                               WASM_GET_LOCAL(simd1))),
    1523             :         WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected), WASM_ONE);
    1524             : 
    1525        1500 :   FOR_INT8_INPUTS(i) {
    1526       12150 :     FOR_INT8_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
    1527             :   }
    1528         150 : }
    1529             : 
    1530       28367 : WASM_SIMD_TEST(I8x16Eq) {
    1531          15 :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16Eq, Equal);
    1532           0 : }
    1533             : 
    1534       28367 : WASM_SIMD_TEST(I8x16Ne) {
    1535          15 :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16Ne, NotEqual);
    1536           0 : }
    1537             : 
    1538       28367 : WASM_SIMD_TEST(I8x16GtS) {
    1539          15 :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GtS, Greater);
    1540           0 : }
    1541             : 
    1542       28367 : WASM_SIMD_TEST(I8x16GeS) {
    1543             :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GeS,
    1544          15 :                         GreaterEqual);
    1545           0 : }
    1546             : 
    1547       28367 : WASM_SIMD_TEST(I8x16LtS) {
    1548          15 :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LtS, Less);
    1549           0 : }
    1550             : 
    1551       28367 : WASM_SIMD_TEST(I8x16LeS) {
    1552          15 :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LeS, LessEqual);
    1553           0 : }
    1554             : 
    1555       28367 : WASM_SIMD_TEST(I8x16GtU) {
    1556             :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GtU,
    1557          15 :                         UnsignedGreater);
    1558           0 : }
    1559             : 
    1560       28367 : WASM_SIMD_TEST(I8x16GeU) {
    1561             :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GeU,
    1562          15 :                         UnsignedGreaterEqual);
    1563           0 : }
    1564             : 
    1565       28367 : WASM_SIMD_TEST(I8x16LtU) {
    1566             :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LtU,
    1567          15 :                         UnsignedLess);
    1568           0 : }
    1569             : 
    1570       28367 : WASM_SIMD_TEST(I8x16LeU) {
    1571             :   RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LeU,
    1572          15 :                         UnsignedLessEqual);
    1573           0 : }
    1574             : 
    1575       28367 : WASM_SIMD_TEST(I8x16Mul) {
    1576             :   RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16Mul,
    1577          15 :                     base::MulWithWraparound);
    1578           0 : }
    1579             : 
    1580          45 : void RunI8x16ShiftOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1581             :                          WasmOpcode simd_op, Int8ShiftOp expected_op) {
    1582         360 :   for (int shift = 1; shift < 8; ++shift) {
    1583             :     WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
    1584             :     byte a = 0;
    1585             :     byte expected = 1;
    1586             :     byte simd = r.AllocateLocal(kWasmS128);
    1587         315 :     BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
    1588             :           WASM_SET_LOCAL(
    1589             :               simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
    1590             :           WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE);
    1591             : 
    1592         315 :     FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); }
    1593             :   }
    1594          45 : }
    1595             : 
    1596       28367 : WASM_SIMD_TEST(I8x16Shl) {
    1597             :   RunI8x16ShiftOpTest(execution_tier, lower_simd, kExprI8x16Shl,
    1598          15 :                       LogicalShiftLeft);
    1599           0 : }
    1600             : 
    1601       28367 : WASM_SIMD_TEST(I8x16ShrS) {
    1602             :   RunI8x16ShiftOpTest(execution_tier, lower_simd, kExprI8x16ShrS,
    1603          15 :                       ArithmeticShiftRight);
    1604           0 : }
    1605             : 
    1606       28367 : WASM_SIMD_TEST(I8x16ShrU) {
    1607             :   RunI8x16ShiftOpTest(execution_tier, lower_simd, kExprI8x16ShrU,
    1608          15 :                       LogicalShiftRight);
    1609           0 : }
    1610             : 
    1611             : // Test Select by making a mask where the 0th and 3rd lanes are true and the
    1612             : // rest false, and comparing for non-equality with zero to convert to a boolean
    1613             : // vector.
    1614             : #define WASM_SIMD_SELECT_TEST(format)                                        \
    1615             :   WASM_SIMD_TEST_TURBOFAN(S##format##Select) {                               \
    1616             :     WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);     \
    1617             :     byte val1 = 0;                                                           \
    1618             :     byte val2 = 1;                                                           \
    1619             :     byte src1 = r.AllocateLocal(kWasmS128);                                  \
    1620             :     byte src2 = r.AllocateLocal(kWasmS128);                                  \
    1621             :     byte zero = r.AllocateLocal(kWasmS128);                                  \
    1622             :     byte mask = r.AllocateLocal(kWasmS128);                                  \
    1623             :     BUILD(r,                                                                 \
    1624             :           WASM_SET_LOCAL(src1,                                               \
    1625             :                          WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \
    1626             :           WASM_SET_LOCAL(src2,                                               \
    1627             :                          WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \
    1628             :           WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)),      \
    1629             :           WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE(           \
    1630             :                                    1, WASM_GET_LOCAL(zero), WASM_I32V(-1))), \
    1631             :           WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE(           \
    1632             :                                    2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \
    1633             :           WASM_SET_LOCAL(                                                    \
    1634             :               mask,                                                          \
    1635             :               WASM_SIMD_SELECT(                                              \
    1636             :                   format, WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2),        \
    1637             :                   WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(mask),  \
    1638             :                                   WASM_GET_LOCAL(zero)))),                   \
    1639             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0),               \
    1640             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1),               \
    1641             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2),               \
    1642             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE);    \
    1643             :                                                                              \
    1644             :     CHECK_EQ(1, r.Call(0x12, 0x34));                                         \
    1645             :   }
    1646             : 
    1647       28372 : WASM_SIMD_SELECT_TEST(32x4)
    1648       28372 : WASM_SIMD_SELECT_TEST(16x8)
    1649       28372 : WASM_SIMD_SELECT_TEST(8x16)
    1650             : 
    1651             : // Test Select by making a mask where the 0th and 3rd lanes are non-zero and the
    1652             : // rest 0. The mask is not the result of a comparison op.
    1653             : #define WASM_SIMD_NON_CANONICAL_SELECT_TEST(format)                           \
    1654             :   WASM_SIMD_TEST_TURBOFAN(S##format##NonCanonicalSelect) {                    \
    1655             :     WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier,          \
    1656             :                                                      lower_simd);             \
    1657             :     byte val1 = 0;                                                            \
    1658             :     byte val2 = 1;                                                            \
    1659             :     byte combined = 2;                                                        \
    1660             :     byte src1 = r.AllocateLocal(kWasmS128);                                   \
    1661             :     byte src2 = r.AllocateLocal(kWasmS128);                                   \
    1662             :     byte zero = r.AllocateLocal(kWasmS128);                                   \
    1663             :     byte mask = r.AllocateLocal(kWasmS128);                                   \
    1664             :     BUILD(r,                                                                  \
    1665             :           WASM_SET_LOCAL(src1,                                                \
    1666             :                          WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))),  \
    1667             :           WASM_SET_LOCAL(src2,                                                \
    1668             :                          WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))),  \
    1669             :           WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)),       \
    1670             :           WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE(            \
    1671             :                                    1, WASM_GET_LOCAL(zero), WASM_I32V(0xF))), \
    1672             :           WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE(            \
    1673             :                                    2, WASM_GET_LOCAL(mask), WASM_I32V(0xF))), \
    1674             :           WASM_SET_LOCAL(mask, WASM_SIMD_SELECT(format, WASM_GET_LOCAL(src1), \
    1675             :                                                 WASM_GET_LOCAL(src2),         \
    1676             :                                                 WASM_GET_LOCAL(mask))),       \
    1677             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0),                \
    1678             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, combined, 1),            \
    1679             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, combined, 2),            \
    1680             :           WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE);     \
    1681             :                                                                               \
    1682             :     CHECK_EQ(1, r.Call(0x12, 0x34, 0x32));                                    \
    1683             :   }
    1684             : 
    1685       28372 : WASM_SIMD_NON_CANONICAL_SELECT_TEST(32x4)
    1686       28372 : WASM_SIMD_NON_CANONICAL_SELECT_TEST(16x8)
    1687       28372 : WASM_SIMD_NON_CANONICAL_SELECT_TEST(8x16)
    1688             : 
    1689             : // Test binary ops with two lane test patterns, all lanes distinct.
    1690             : template <typename T>
    1691        9705 : void RunBinaryLaneOpTest(
    1692             :     ExecutionTier execution_tier, LowerSimd lower_simd, WasmOpcode simd_op,
    1693             :     const std::array<T, kSimd128Size / sizeof(T)>& expected) {
    1694             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    1695             :   // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
    1696        9705 :   T* src0 = r.builder().AddGlobal<T>(kWasmS128);
    1697        9705 :   T* src1 = r.builder().AddGlobal<T>(kWasmS128);
    1698             :   static const int kElems = kSimd128Size / sizeof(T);
    1699      164505 :   for (int i = 0; i < kElems; i++) {
    1700      154800 :     WriteLittleEndianValue<T>(&src0[i], i);
    1701      154800 :     WriteLittleEndianValue<T>(&src1[i], kElems + i);
    1702             :   }
    1703        9705 :   if (simd_op == kExprS8x16Shuffle) {
    1704        9660 :     BUILD(r,
    1705             :           WASM_SET_GLOBAL(0, WASM_SIMD_S8x16_SHUFFLE_OP(simd_op, expected,
    1706             :                                                         WASM_GET_GLOBAL(0),
    1707             :                                                         WASM_GET_GLOBAL(1))),
    1708             :           WASM_ONE);
    1709             :   } else {
    1710          45 :     BUILD(r,
    1711             :           WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0),
    1712             :                                              WASM_GET_GLOBAL(1))),
    1713             :           WASM_ONE);
    1714             :   }
    1715             : 
    1716        9705 :   CHECK_EQ(1, r.Call());
    1717      154800 :   for (size_t i = 0; i < expected.size(); i++) {
    1718      154800 :     CHECK_EQ(ReadLittleEndianValue<T>(&src0[i]), expected[i]);
    1719             :   }
    1720        9705 : }
    1721             : 
    1722       28397 : WASM_SIMD_TEST(I32x4AddHoriz) {
    1723             :   // Inputs are [0 1 2 3] and [4 5 6 7].
    1724             :   RunBinaryLaneOpTest<int32_t>(execution_tier, lower_simd, kExprI32x4AddHoriz,
    1725          15 :                                {{1, 5, 9, 13}});
    1726          15 : }
    1727             : 
    1728       28397 : WASM_SIMD_TEST(I16x8AddHoriz) {
    1729             :   // Inputs are [0 1 2 3 4 5 6 7] and [8 9 10 11 12 13 14 15].
    1730             :   RunBinaryLaneOpTest<int16_t>(execution_tier, lower_simd, kExprI16x8AddHoriz,
    1731          15 :                                {{1, 5, 9, 13, 17, 21, 25, 29}});
    1732          15 : }
    1733             : 
    1734       28397 : WASM_SIMD_TEST(F32x4AddHoriz) {
    1735             :   // Inputs are [0.0f 1.0f 2.0f 3.0f] and [4.0f 5.0f 6.0f 7.0f].
    1736             :   RunBinaryLaneOpTest<float>(execution_tier, lower_simd, kExprF32x4AddHoriz,
    1737          15 :                              {{1.0f, 5.0f, 9.0f, 13.0f}});
    1738          15 : }
    1739             : 
    1740             : // Test shuffle ops.
    1741        2415 : void RunShuffleOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
    1742             :                       WasmOpcode simd_op,
    1743             :                       const std::array<int8_t, kSimd128Size>& shuffle) {
    1744             :   // Test the original shuffle.
    1745        2415 :   RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op, shuffle);
    1746             : 
    1747             :   // Test a non-canonical (inputs reversed) version of the shuffle.
    1748        2415 :   std::array<int8_t, kSimd128Size> other_shuffle(shuffle);
    1749        2415 :   for (size_t i = 0; i < shuffle.size(); ++i) other_shuffle[i] ^= kSimd128Size;
    1750             :   RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op,
    1751        2415 :                               other_shuffle);
    1752             : 
    1753             :   // Test the swizzle (one-operand) version of the shuffle.
    1754        2415 :   std::array<int8_t, kSimd128Size> swizzle(shuffle);
    1755        2415 :   for (size_t i = 0; i < shuffle.size(); ++i) swizzle[i] &= (kSimd128Size - 1);
    1756        2415 :   RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op, swizzle);
    1757             : 
    1758             :   // Test the non-canonical swizzle (one-operand) version of the shuffle.
    1759        2415 :   std::array<int8_t, kSimd128Size> other_swizzle(shuffle);
    1760        2415 :   for (size_t i = 0; i < shuffle.size(); ++i) other_swizzle[i] |= kSimd128Size;
    1761             :   RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op,
    1762        2415 :                               other_swizzle);
    1763        2415 : }
    1764             : 
    1765             : #define SHUFFLE_LIST(V)  \
    1766             :   V(S128Identity)        \
    1767             :   V(S32x4Dup)            \
    1768             :   V(S32x4ZipLeft)        \
    1769             :   V(S32x4ZipRight)       \
    1770             :   V(S32x4UnzipLeft)      \
    1771             :   V(S32x4UnzipRight)     \
    1772             :   V(S32x4TransposeLeft)  \
    1773             :   V(S32x4TransposeRight) \
    1774             :   V(S32x2Reverse)        \
    1775             :   V(S32x4Irregular)      \
    1776             :   V(S16x8Dup)            \
    1777             :   V(S16x8ZipLeft)        \
    1778             :   V(S16x8ZipRight)       \
    1779             :   V(S16x8UnzipLeft)      \
    1780             :   V(S16x8UnzipRight)     \
    1781             :   V(S16x8TransposeLeft)  \
    1782             :   V(S16x8TransposeRight) \
    1783             :   V(S16x4Reverse)        \
    1784             :   V(S16x2Reverse)        \
    1785             :   V(S16x8Irregular)      \
    1786             :   V(S8x16Dup)            \
    1787             :   V(S8x16ZipLeft)        \
    1788             :   V(S8x16ZipRight)       \
    1789             :   V(S8x16UnzipLeft)      \
    1790             :   V(S8x16UnzipRight)     \
    1791             :   V(S8x16TransposeLeft)  \
    1792             :   V(S8x16TransposeRight) \
    1793             :   V(S8x8Reverse)         \
    1794             :   V(S8x4Reverse)         \
    1795             :   V(S8x2Reverse)         \
    1796             :   V(S8x16Irregular)
    1797             : 
    1798             : enum ShuffleKey {
    1799             : #define SHUFFLE_ENUM_VALUE(Name) k##Name,
    1800             :   SHUFFLE_LIST(SHUFFLE_ENUM_VALUE)
    1801             : #undef SHUFFLE_ENUM_VALUE
    1802             :       kNumShuffleKeys
    1803             : };
    1804             : 
    1805             : using Shuffle = std::array<int8_t, kSimd128Size>;
    1806             : using ShuffleMap = std::map<ShuffleKey, const Shuffle>;
    1807             : 
    1808       28337 : ShuffleMap test_shuffles = {
    1809             :     {kS128Identity,
    1810             :      {{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}}},
    1811             :     {kS32x4Dup,
    1812             :      {{16, 17, 18, 19, 16, 17, 18, 19, 16, 17, 18, 19, 16, 17, 18, 19}}},
    1813             :     {kS32x4ZipLeft, {{0, 1, 2, 3, 16, 17, 18, 19, 4, 5, 6, 7, 20, 21, 22, 23}}},
    1814             :     {kS32x4ZipRight,
    1815             :      {{8, 9, 10, 11, 24, 25, 26, 27, 12, 13, 14, 15, 28, 29, 30, 31}}},
    1816             :     {kS32x4UnzipLeft,
    1817             :      {{0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27}}},
    1818             :     {kS32x4UnzipRight,
    1819             :      {{4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31}}},
    1820             :     {kS32x4TransposeLeft,
    1821             :      {{0, 1, 2, 3, 16, 17, 18, 19, 8, 9, 10, 11, 24, 25, 26, 27}}},
    1822             :     {kS32x4TransposeRight,
    1823             :      {{4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31}}},
    1824             :     {kS32x2Reverse,  // swizzle only
    1825             :      {{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}}},
    1826             :     {kS32x4Irregular,
    1827             :      {{0, 1, 2, 3, 16, 17, 18, 19, 16, 17, 18, 19, 20, 21, 22, 23}}},
    1828             :     {kS16x8Dup,
    1829             :      {{18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19}}},
    1830             :     {kS16x8ZipLeft, {{0, 1, 16, 17, 2, 3, 18, 19, 4, 5, 20, 21, 6, 7, 22, 23}}},
    1831             :     {kS16x8ZipRight,
    1832             :      {{8, 9, 24, 25, 10, 11, 26, 27, 12, 13, 28, 29, 14, 15, 30, 31}}},
    1833             :     {kS16x8UnzipLeft,
    1834             :      {{0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29}}},
    1835             :     {kS16x8UnzipRight,
    1836             :      {{2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31}}},
    1837             :     {kS16x8TransposeLeft,
    1838             :      {{0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29}}},
    1839             :     {kS16x8TransposeRight,
    1840             :      {{2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31}}},
    1841             :     {kS16x4Reverse,  // swizzle only
    1842             :      {{6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9}}},
    1843             :     {kS16x2Reverse,  // swizzle only
    1844             :      {{2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13}}},
    1845             :     {kS16x8Irregular,
    1846             :      {{0, 1, 16, 17, 16, 17, 0, 1, 4, 5, 20, 21, 6, 7, 22, 23}}},
    1847             :     {kS8x16Dup,
    1848             :      {{19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19}}},
    1849             :     {kS8x16ZipLeft, {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}},
    1850             :     {kS8x16ZipRight,
    1851             :      {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}},
    1852             :     {kS8x16UnzipLeft,
    1853             :      {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}},
    1854             :     {kS8x16UnzipRight,
    1855             :      {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}},
    1856             :     {kS8x16TransposeLeft,
    1857             :      {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}},
    1858             :     {kS8x16TransposeRight,
    1859             :      {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}},
    1860             :     {kS8x8Reverse,  // swizzle only
    1861             :      {{7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8}}},
    1862             :     {kS8x4Reverse,  // swizzle only
    1863             :      {{3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12}}},
    1864             :     {kS8x2Reverse,  // swizzle only
    1865             :      {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14}}},
    1866             :     {kS8x16Irregular,
    1867             :      {{0, 16, 0, 16, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}},
    1868             : };
    1869             : 
    1870             : #define SHUFFLE_TEST(Name)                                          \
    1871             :   WASM_SIMD_TEST(Name) {                                            \
    1872             :     ShuffleMap::const_iterator it = test_shuffles.find(k##Name);    \
    1873             :     DCHECK_NE(it, test_shuffles.end());                             \
    1874             :     RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, \
    1875             :                      it->second);                                   \
    1876             :   }
    1877       30662 : SHUFFLE_LIST(SHUFFLE_TEST)
    1878             : #undef SHUFFLE_TEST
    1879             : #undef SHUFFLE_LIST
    1880             : 
    1881             : // Test shuffles that blend the two vectors (elements remain in their lanes.)
    1882       28397 : WASM_SIMD_TEST(S8x16Blend) {
    1883             :   std::array<int8_t, kSimd128Size> expected;
    1884         240 :   for (int bias = 1; bias < kSimd128Size; bias++) {
    1885        1800 :     for (int i = 0; i < bias; i++) expected[i] = i;
    1886        1800 :     for (int i = bias; i < kSimd128Size; i++) expected[i] = i + kSimd128Size;
    1887         225 :     RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, expected);
    1888             :   }
    1889          15 : }
    1890             : 
    1891             : // Test shuffles that concatenate the two vectors.
    1892       28397 : WASM_SIMD_TEST(S8x16Concat) {
    1893             :   std::array<int8_t, kSimd128Size> expected;
    1894             :   // n is offset or bias of concatenation.
    1895         240 :   for (int n = 1; n < kSimd128Size; ++n) {
    1896             :     int i = 0;
    1897             :     // last kLanes - n bytes of first vector.
    1898        1800 :     for (int j = n; j < kSimd128Size; ++j) {
    1899        1800 :       expected[i++] = j;
    1900             :     }
    1901             :     // first n bytes of second vector
    1902        1800 :     for (int j = 0; j < n; ++j) {
    1903        1800 :       expected[i++] = j + kSimd128Size;
    1904             :     }
    1905         225 :     RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, expected);
    1906             :   }
    1907          15 : }
    1908             : 
    1909             : // Combine 3 shuffles a, b, and c by applying both a and b and then applying c
    1910             : // to those two results.
    1911           0 : Shuffle Combine(const Shuffle& a, const Shuffle& b, const Shuffle& c) {
    1912             :   Shuffle result;
    1913       24000 :   for (int i = 0; i < kSimd128Size; ++i) {
    1914       24000 :     result[i] = c[i] < kSimd128Size ? a[c[i]] : b[c[i] - kSimd128Size];
    1915             :   }
    1916        1500 :   return result;
    1917             : }
    1918             : 
    1919       16560 : const Shuffle& GetRandomTestShuffle(v8::base::RandomNumberGenerator* rng) {
    1920       16560 :   return test_shuffles[static_cast<ShuffleKey>(rng->NextInt(kNumShuffleKeys))];
    1921             : }
    1922             : 
    1923             : // Test shuffles that are random combinations of 3 test shuffles. Completely
    1924             : // random shuffles almost always generate the slow general shuffle code, so
    1925             : // don't exercise as many code paths.
    1926       28397 : WASM_SIMD_TEST(S8x16ShuffleFuzz) {
    1927          15 :   v8::base::RandomNumberGenerator* rng = CcTest::random_number_generator();
    1928             :   static const int kTests = 100;
    1929        1515 :   for (int i = 0; i < kTests; ++i) {
    1930        1500 :     auto shuffle = Combine(GetRandomTestShuffle(rng), GetRandomTestShuffle(rng),
    1931        3000 :                            GetRandomTestShuffle(rng));
    1932        1500 :     RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, shuffle);
    1933             :   }
    1934          15 : }
    1935             : 
    1936       12060 : void AppendShuffle(const Shuffle& shuffle, std::vector<byte>* buffer) {
    1937       12060 :   byte opcode[] = {WASM_SIMD_OP(kExprS8x16Shuffle)};
    1938       12060 :   for (size_t i = 0; i < arraysize(opcode); ++i) buffer->push_back(opcode[i]);
    1939      385920 :   for (size_t i = 0; i < kSimd128Size; ++i) buffer->push_back((shuffle[i]));
    1940       12060 : }
    1941             : 
    1942       20590 : void BuildShuffle(std::vector<Shuffle>& shuffles, std::vector<byte>* buffer) {
    1943             :   // Perform the leaf shuffles on globals 0 and 1.
    1944        1000 :   size_t row_index = (shuffles.size() - 1) / 2;
    1945       15060 :   for (size_t i = row_index; i < shuffles.size(); ++i) {
    1946        6530 :     byte operands[] = {WASM_GET_GLOBAL(0), WASM_GET_GLOBAL(1)};
    1947       32650 :     for (size_t j = 0; j < arraysize(operands); ++j)
    1948       26120 :       buffer->push_back(operands[j]);
    1949        6530 :     AppendShuffle(shuffles[i], buffer);
    1950             :   }
    1951             :   // Now perform inner shuffles in the correct order on operands on the stack.
    1952        2920 :   do {
    1953        8450 :     for (size_t i = row_index / 2; i < row_index; ++i) {
    1954        5530 :       AppendShuffle(shuffles[i], buffer);
    1955             :     }
    1956             :     row_index /= 2;
    1957             :   } while (row_index != 0);
    1958        1000 :   byte epilog[] = {kExprSetGlobal, static_cast<byte>(0), WASM_ONE};
    1959        1000 :   for (size_t j = 0; j < arraysize(epilog); ++j) buffer->push_back(epilog[j]);
    1960        1000 : }
    1961             : 
    1962        2000 : void RunWasmCode(ExecutionTier execution_tier, LowerSimd lower_simd,
    1963        2000 :                  const std::vector<byte>& code,
    1964             :                  std::array<int8_t, kSimd128Size>* result) {
    1965             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    1966             :   // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
    1967        2000 :   int8_t* src0 = r.builder().AddGlobal<int8_t>(kWasmS128);
    1968        2000 :   int8_t* src1 = r.builder().AddGlobal<int8_t>(kWasmS128);
    1969       34000 :   for (int i = 0; i < kSimd128Size; ++i) {
    1970       32000 :     WriteLittleEndianValue<int8_t>(&src0[i], i);
    1971       32000 :     WriteLittleEndianValue<int8_t>(&src1[i], kSimd128Size + i);
    1972             :   }
    1973        2000 :   r.Build(code.data(), code.data() + code.size());
    1974        2000 :   CHECK_EQ(1, r.Call());
    1975       32000 :   for (size_t i = 0; i < kSimd128Size; i++) {
    1976       32000 :     (*result)[i] = ReadLittleEndianValue<int8_t>(&src0[i]);
    1977             :   }
    1978        2000 : }
    1979             : 
    1980             : // Test multiple shuffles executed in sequence.
    1981       28377 : WASM_SIMD_COMPILED_TEST(S8x16MultiShuffleFuzz) {
    1982          10 :   v8::base::RandomNumberGenerator* rng = CcTest::random_number_generator();
    1983             :   static const int kShuffles = 100;
    1984        1010 :   for (int i = 0; i < kShuffles; ++i) {
    1985             :     // Create an odd number in [3..23] of random test shuffles so we can build
    1986             :     // a complete binary tree (stored as a heap) of shuffle operations. The leaf
    1987             :     // shuffles operate on the test pattern inputs, while the interior shuffles
    1988             :     // operate on the results of the two child shuffles.
    1989        1000 :     int num_shuffles = rng->NextInt(10) * 2 + 3;
    1990             :     std::vector<Shuffle> shuffles;
    1991       13060 :     for (int j = 0; j < num_shuffles; ++j) {
    1992       12060 :       shuffles.push_back(GetRandomTestShuffle(rng));
    1993             :     }
    1994             :     // Generate the code for the shuffle expression.
    1995             :     std::vector<byte> buffer;
    1996        1000 :     BuildShuffle(shuffles, &buffer);
    1997             : 
    1998             :     // Run the code using the interpreter to get the expected result.
    1999             :     std::array<int8_t, kSimd128Size> expected;
    2000        1000 :     RunWasmCode(ExecutionTier::kInterpreter, kNoLowerSimd, buffer, &expected);
    2001             :     // Run the SIMD or scalar lowered compiled code and compare results.
    2002             :     std::array<int8_t, kSimd128Size> result;
    2003        1000 :     RunWasmCode(execution_tier, lower_simd, buffer, &result);
    2004       17000 :     for (size_t i = 0; i < kSimd128Size; ++i) {
    2005       16000 :       CHECK_EQ(result[i], expected[i]);
    2006             :     }
    2007             :   }
    2008          10 : }
    2009             : 
    2010             : // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer
    2011             : // result. Use relational ops on numeric vectors to create the boolean vector
    2012             : // test inputs. Test inputs with all true, all false, one true, and one false.
    2013             : #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes)                           \
    2014             :   WASM_SIMD_TEST(ReductionTest##lanes) {                                       \
    2015             :     WasmRunner<int32_t> r(execution_tier, lower_simd);                         \
    2016             :     byte zero = r.AllocateLocal(kWasmS128);                                    \
    2017             :     byte one_one = r.AllocateLocal(kWasmS128);                                 \
    2018             :     byte reduced = r.AllocateLocal(kWasmI32);                                  \
    2019             :     BUILD(r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)),     \
    2020             :           WASM_SET_LOCAL(                                                      \
    2021             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue,                \
    2022             :                                       WASM_SIMD_BINOP(kExprI##format##Eq,      \
    2023             :                                                       WASM_GET_LOCAL(zero),    \
    2024             :                                                       WASM_GET_LOCAL(zero)))), \
    2025             :           WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2026             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2027             :           WASM_SET_LOCAL(                                                      \
    2028             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue,                \
    2029             :                                       WASM_SIMD_BINOP(kExprI##format##Ne,      \
    2030             :                                                       WASM_GET_LOCAL(zero),    \
    2031             :                                                       WASM_GET_LOCAL(zero)))), \
    2032             :           WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2033             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2034             :           WASM_SET_LOCAL(                                                      \
    2035             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue,                \
    2036             :                                       WASM_SIMD_BINOP(kExprI##format##Eq,      \
    2037             :                                                       WASM_GET_LOCAL(zero),    \
    2038             :                                                       WASM_GET_LOCAL(zero)))), \
    2039             :           WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2040             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2041             :           WASM_SET_LOCAL(                                                      \
    2042             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue,                \
    2043             :                                       WASM_SIMD_BINOP(kExprI##format##Ne,      \
    2044             :                                                       WASM_GET_LOCAL(zero),    \
    2045             :                                                       WASM_GET_LOCAL(zero)))), \
    2046             :           WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2047             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2048             :           WASM_SET_LOCAL(one_one,                                              \
    2049             :                          WASM_SIMD_I##format##_REPLACE_LANE(                   \
    2050             :                              lanes - 1, WASM_GET_LOCAL(zero), WASM_ONE)),      \
    2051             :           WASM_SET_LOCAL(                                                      \
    2052             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue,                \
    2053             :                                       WASM_SIMD_BINOP(kExprI##format##Eq,      \
    2054             :                                                       WASM_GET_LOCAL(one_one), \
    2055             :                                                       WASM_GET_LOCAL(zero)))), \
    2056             :           WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2057             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2058             :           WASM_SET_LOCAL(                                                      \
    2059             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue,                \
    2060             :                                       WASM_SIMD_BINOP(kExprI##format##Ne,      \
    2061             :                                                       WASM_GET_LOCAL(one_one), \
    2062             :                                                       WASM_GET_LOCAL(zero)))), \
    2063             :           WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2064             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2065             :           WASM_SET_LOCAL(                                                      \
    2066             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue,                \
    2067             :                                       WASM_SIMD_BINOP(kExprI##format##Eq,      \
    2068             :                                                       WASM_GET_LOCAL(one_one), \
    2069             :                                                       WASM_GET_LOCAL(zero)))), \
    2070             :           WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2071             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2072             :           WASM_SET_LOCAL(                                                      \
    2073             :               reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue,                \
    2074             :                                       WASM_SIMD_BINOP(kExprI##format##Ne,      \
    2075             :                                                       WASM_GET_LOCAL(one_one), \
    2076             :                                                       WASM_GET_LOCAL(zero)))), \
    2077             :           WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO),             \
    2078             :                   WASM_RETURN1(WASM_ZERO)),                                    \
    2079             :           WASM_ONE);                                                           \
    2080             :     CHECK_EQ(1, r.Call());                                                     \
    2081             :   }
    2082             : 
    2083       28427 : WASM_SIMD_BOOL_REDUCTION_TEST(32x4, 4)
    2084       28427 : WASM_SIMD_BOOL_REDUCTION_TEST(16x8, 8)
    2085       28427 : WASM_SIMD_BOOL_REDUCTION_TEST(8x16, 16)
    2086             : 
    2087       28397 : WASM_SIMD_TEST(SimdI32x4ExtractWithF32x4) {
    2088             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2089          15 :   BUILD(r, WASM_IF_ELSE_I(
    2090             :                WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
    2091             :                                0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
    2092             :                            WASM_I32_REINTERPRET_F32(WASM_F32(30.5))),
    2093             :                WASM_I32V(1), WASM_I32V(0)));
    2094          15 :   CHECK_EQ(1, r.Call());
    2095          15 : }
    2096             : 
    2097       28397 : WASM_SIMD_TEST(SimdF32x4ExtractWithI32x4) {
    2098             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2099          15 :   BUILD(r,
    2100             :         WASM_IF_ELSE_I(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
    2101             :                                        0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
    2102             :                                    WASM_F32_REINTERPRET_I32(WASM_I32V(15))),
    2103             :                        WASM_I32V(1), WASM_I32V(0)));
    2104          15 :   CHECK_EQ(1, r.Call());
    2105          15 : }
    2106             : 
    2107       28397 : WASM_SIMD_TEST(SimdF32x4AddWithI32x4) {
    2108             :   // Choose two floating point values whose sum is normal and exactly
    2109             :   // representable as a float.
    2110             :   const int kOne = 0x3F800000;
    2111             :   const int kTwo = 0x40000000;
    2112             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2113          15 :   BUILD(r,
    2114             :         WASM_IF_ELSE_I(
    2115             :             WASM_F32_EQ(
    2116             :                 WASM_SIMD_F32x4_EXTRACT_LANE(
    2117             :                     0, WASM_SIMD_BINOP(kExprF32x4Add,
    2118             :                                        WASM_SIMD_I32x4_SPLAT(WASM_I32V(kOne)),
    2119             :                                        WASM_SIMD_I32x4_SPLAT(WASM_I32V(kTwo)))),
    2120             :                 WASM_F32_ADD(WASM_F32_REINTERPRET_I32(WASM_I32V(kOne)),
    2121             :                              WASM_F32_REINTERPRET_I32(WASM_I32V(kTwo)))),
    2122             :             WASM_I32V(1), WASM_I32V(0)));
    2123          15 :   CHECK_EQ(1, r.Call());
    2124          15 : }
    2125             : 
    2126       28397 : WASM_SIMD_TEST(SimdI32x4AddWithF32x4) {
    2127             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2128          15 :   BUILD(r,
    2129             :         WASM_IF_ELSE_I(
    2130             :             WASM_I32_EQ(
    2131             :                 WASM_SIMD_I32x4_EXTRACT_LANE(
    2132             :                     0, WASM_SIMD_BINOP(kExprI32x4Add,
    2133             :                                        WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25)),
    2134             :                                        WASM_SIMD_F32x4_SPLAT(WASM_F32(31.5)))),
    2135             :                 WASM_I32_ADD(WASM_I32_REINTERPRET_F32(WASM_F32(21.25)),
    2136             :                              WASM_I32_REINTERPRET_F32(WASM_F32(31.5)))),
    2137             :             WASM_I32V(1), WASM_I32V(0)));
    2138          15 :   CHECK_EQ(1, r.Call());
    2139          15 : }
    2140             : 
    2141       28397 : WASM_SIMD_TEST(SimdI32x4Local) {
    2142             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2143             :   r.AllocateLocal(kWasmS128);
    2144          15 :   BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
    2145             : 
    2146             :         WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)));
    2147          15 :   CHECK_EQ(31, r.Call());
    2148          15 : }
    2149             : 
    2150       28397 : WASM_SIMD_TEST(SimdI32x4SplatFromExtract) {
    2151             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2152             :   r.AllocateLocal(kWasmI32);
    2153             :   r.AllocateLocal(kWasmS128);
    2154          15 :   BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
    2155             :                                  0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
    2156             :         WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
    2157             :         WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)));
    2158          15 :   CHECK_EQ(76, r.Call());
    2159          15 : }
    2160             : 
    2161       28397 : WASM_SIMD_TEST(SimdI32x4For) {
    2162             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2163             :   r.AllocateLocal(kWasmI32);
    2164             :   r.AllocateLocal(kWasmS128);
    2165          15 :   BUILD(r,
    2166             : 
    2167             :         WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
    2168             :         WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
    2169             :                                                        WASM_I32V(53))),
    2170             :         WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
    2171             :                                                        WASM_I32V(23))),
    2172             :         WASM_SET_LOCAL(0, WASM_I32V(0)),
    2173             :         WASM_LOOP(
    2174             :             WASM_SET_LOCAL(
    2175             :                 1, WASM_SIMD_BINOP(kExprI32x4Add, WASM_GET_LOCAL(1),
    2176             :                                    WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
    2177             :             WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)), WASM_BR(1))),
    2178             :         WASM_SET_LOCAL(0, WASM_I32V(1)),
    2179             :         WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
    2180             :                             WASM_I32V(36)),
    2181             :                 WASM_SET_LOCAL(0, WASM_I32V(0))),
    2182             :         WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
    2183             :                             WASM_I32V(58)),
    2184             :                 WASM_SET_LOCAL(0, WASM_I32V(0))),
    2185             :         WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
    2186             :                             WASM_I32V(28)),
    2187             :                 WASM_SET_LOCAL(0, WASM_I32V(0))),
    2188             :         WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
    2189             :                             WASM_I32V(36)),
    2190             :                 WASM_SET_LOCAL(0, WASM_I32V(0))),
    2191             :         WASM_GET_LOCAL(0));
    2192          15 :   CHECK_EQ(1, r.Call());
    2193          15 : }
    2194             : 
    2195       28397 : WASM_SIMD_TEST(SimdF32x4For) {
    2196             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2197             :   r.AllocateLocal(kWasmI32);
    2198             :   r.AllocateLocal(kWasmS128);
    2199          15 :   BUILD(r, WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
    2200             :         WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(1),
    2201             :                                                        WASM_F32(19.5))),
    2202             :         WASM_SET_LOCAL(0, WASM_I32V(0)),
    2203             :         WASM_LOOP(
    2204             :             WASM_SET_LOCAL(
    2205             :                 1, WASM_SIMD_BINOP(kExprF32x4Add, WASM_GET_LOCAL(1),
    2206             :                                    WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
    2207             :             WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)), WASM_BR(1))),
    2208             :         WASM_SET_LOCAL(0, WASM_I32V(1)),
    2209             :         WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
    2210             :                             WASM_F32(27.25)),
    2211             :                 WASM_SET_LOCAL(0, WASM_I32V(0))),
    2212             :         WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
    2213             :                             WASM_F32(25.5)),
    2214             :                 WASM_SET_LOCAL(0, WASM_I32V(0))),
    2215             :         WASM_GET_LOCAL(0));
    2216          15 :   CHECK_EQ(1, r.Call());
    2217          15 : }
    2218             : 
    2219             : template <typename T, int numLanes = 4>
    2220             : void SetVectorByLanes(T* v, const std::array<T, numLanes>& arr) {
    2221         120 :   for (int lane = 0; lane < numLanes; lane++) {
    2222         120 :     WriteLittleEndianValue<T>(&v[lane], arr[lane]);
    2223             :   }
    2224             : }
    2225             : 
    2226             : template <typename T>
    2227             : const T GetScalar(T* v, int lane) {
    2228             :   constexpr int kElems = kSimd128Size / sizeof(T);
    2229             :   const int index = lane;
    2230             :   USE(kElems);
    2231             :   DCHECK(index >= 0 && index < kElems);
    2232         120 :   return ReadLittleEndianValue<T>(&v[index]);
    2233             : }
    2234             : 
    2235       28397 : WASM_SIMD_TEST(SimdI32x4GetGlobal) {
    2236             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
    2237             :   // Pad the globals with a few unused slots to get a non-zero offset.
    2238             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2239             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2240             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2241             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2242          15 :   int32_t* global = r.builder().AddGlobal<int32_t>(kWasmS128);
    2243          30 :   SetVectorByLanes(global, {{0, 1, 2, 3}});
    2244             :   r.AllocateLocal(kWasmI32);
    2245          15 :   BUILD(
    2246             :       r, WASM_SET_LOCAL(1, WASM_I32V(1)),
    2247             :       WASM_IF(WASM_I32_NE(WASM_I32V(0),
    2248             :                           WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(4))),
    2249             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2250             :       WASM_IF(WASM_I32_NE(WASM_I32V(1),
    2251             :                           WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(4))),
    2252             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2253             :       WASM_IF(WASM_I32_NE(WASM_I32V(2),
    2254             :                           WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(4))),
    2255             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2256             :       WASM_IF(WASM_I32_NE(WASM_I32V(3),
    2257             :                           WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(4))),
    2258             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2259             :       WASM_GET_LOCAL(1));
    2260          15 :   CHECK_EQ(1, r.Call(0));
    2261          15 : }
    2262             : 
    2263       28397 : WASM_SIMD_TEST(SimdI32x4SetGlobal) {
    2264             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
    2265             :   // Pad the globals with a few unused slots to get a non-zero offset.
    2266             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2267             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2268             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2269             :   r.builder().AddGlobal<int32_t>(kWasmI32);  // purposefully unused
    2270          15 :   int32_t* global = r.builder().AddGlobal<int32_t>(kWasmS128);
    2271          15 :   BUILD(r, WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
    2272             :         WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(4),
    2273             :                                                         WASM_I32V(34))),
    2274             :         WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(4),
    2275             :                                                         WASM_I32V(45))),
    2276             :         WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(4),
    2277             :                                                         WASM_I32V(56))),
    2278             :         WASM_I32V(1));
    2279          15 :   CHECK_EQ(1, r.Call(0));
    2280          15 :   CHECK_EQ(GetScalar(global, 0), 23);
    2281          15 :   CHECK_EQ(GetScalar(global, 1), 34);
    2282          15 :   CHECK_EQ(GetScalar(global, 2), 45);
    2283          15 :   CHECK_EQ(GetScalar(global, 3), 56);
    2284          15 : }
    2285             : 
    2286       28397 : WASM_SIMD_TEST(SimdF32x4GetGlobal) {
    2287             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
    2288          15 :   float* global = r.builder().AddGlobal<float>(kWasmS128);
    2289          30 :   SetVectorByLanes<float>(global, {{0.0, 1.5, 2.25, 3.5}});
    2290             :   r.AllocateLocal(kWasmI32);
    2291          15 :   BUILD(
    2292             :       r, WASM_SET_LOCAL(1, WASM_I32V(1)),
    2293             :       WASM_IF(WASM_F32_NE(WASM_F32(0.0),
    2294             :                           WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
    2295             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2296             :       WASM_IF(WASM_F32_NE(WASM_F32(1.5),
    2297             :                           WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
    2298             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2299             :       WASM_IF(WASM_F32_NE(WASM_F32(2.25),
    2300             :                           WASM_SIMD_F32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(0))),
    2301             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2302             :       WASM_IF(WASM_F32_NE(WASM_F32(3.5),
    2303             :                           WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(0))),
    2304             :               WASM_SET_LOCAL(1, WASM_I32V(0))),
    2305             :       WASM_GET_LOCAL(1));
    2306          15 :   CHECK_EQ(1, r.Call(0));
    2307          15 : }
    2308             : 
    2309       28397 : WASM_SIMD_TEST(SimdF32x4SetGlobal) {
    2310             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
    2311          15 :   float* global = r.builder().AddGlobal<float>(kWasmS128);
    2312          15 :   BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
    2313             :         WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
    2314             :                                                         WASM_F32(45.5))),
    2315             :         WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
    2316             :                                                         WASM_F32(32.25))),
    2317             :         WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
    2318             :                                                         WASM_F32(65.0))),
    2319             :         WASM_I32V(1));
    2320          15 :   CHECK_EQ(1, r.Call(0));
    2321          15 :   CHECK_EQ(GetScalar(global, 0), 13.5f);
    2322          15 :   CHECK_EQ(GetScalar(global, 1), 45.5f);
    2323          15 :   CHECK_EQ(GetScalar(global, 2), 32.25f);
    2324          15 :   CHECK_EQ(GetScalar(global, 3), 65.0f);
    2325          15 : }
    2326             : 
    2327       28377 : WASM_SIMD_COMPILED_TEST(SimdLoadStoreLoad) {
    2328             :   WasmRunner<int32_t> r(execution_tier, lower_simd);
    2329             :   int32_t* memory =
    2330             :       r.builder().AddMemoryElems<int32_t>(kWasmPageSize / sizeof(int32_t));
    2331             :   // Load memory, store it, then reload it and extract the first lane. Use a
    2332             :   // non-zero offset into the memory of 1 lane (4 bytes) to test indexing.
    2333          10 :   BUILD(r, WASM_SIMD_STORE_MEM(WASM_I32V(4), WASM_SIMD_LOAD_MEM(WASM_I32V(4))),
    2334             :         WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_LOAD_MEM(WASM_I32V(4))));
    2335             : 
    2336         590 :   FOR_INT32_INPUTS(i) {
    2337         580 :     int32_t expected = *i;
    2338             :     r.builder().WriteMemory(&memory[1], expected);
    2339         580 :     CHECK_EQ(expected, r.Call());
    2340             :   }
    2341          10 : }
    2342             : 
    2343             : #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
    2344             : // V8:8665 - Tracking bug to enable reduction tests in the interpreter,
    2345             : // and for SIMD lowering.
    2346             : // TODO(gdeepti): Enable these tests for ARM/ARM64
    2347             : #define WASM_SIMD_ANYTRUE_TEST(format, lanes, max)                            \
    2348             :   WASM_SIMD_TEST_TURBOFAN(S##format##AnyTrue) {                               \
    2349             :     WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);               \
    2350             :     byte simd = r.AllocateLocal(kWasmS128);                                   \
    2351             :     BUILD(                                                                    \
    2352             :         r,                                                                    \
    2353             :         WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(0))), \
    2354             :         WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, WASM_GET_LOCAL(simd)));      \
    2355             :     DCHECK_EQ(1, r.Call(max));                                                \
    2356             :     DCHECK_EQ(1, r.Call(5));                                                  \
    2357             :     DCHECK_EQ(0, r.Call(0));                                                  \
    2358             :   }
    2359       28372 : WASM_SIMD_ANYTRUE_TEST(32x4, 4, 0xffffffff);
    2360       28372 : WASM_SIMD_ANYTRUE_TEST(16x8, 8, 0xffff);
    2361       28372 : WASM_SIMD_ANYTRUE_TEST(8x16, 16, 0xff);
    2362             : 
    2363             : #define WASM_SIMD_ALLTRUE_TEST(format, lanes, max)                            \
    2364             :   WASM_SIMD_TEST_TURBOFAN(S##format##AllTrue) {                               \
    2365             :     WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);               \
    2366             :     byte simd = r.AllocateLocal(kWasmS128);                                   \
    2367             :     BUILD(                                                                    \
    2368             :         r,                                                                    \
    2369             :         WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(0))), \
    2370             :         WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, WASM_GET_LOCAL(simd)));      \
    2371             :     DCHECK_EQ(1, r.Call(max));                                                \
    2372             :     DCHECK_EQ(0, r.Call(21));                                                 \
    2373             :     DCHECK_EQ(0, r.Call(0));                                                  \
    2374             :   }
    2375       28372 : WASM_SIMD_ALLTRUE_TEST(32x4, 4, 0xffffffff);
    2376       28372 : WASM_SIMD_ALLTRUE_TEST(16x8, 8, 0xffff);
    2377       28372 : WASM_SIMD_ALLTRUE_TEST(8x16, 16, 0xff);
    2378             : #endif  // V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
    2379             : 
    2380       28362 : WASM_SIMD_TEST_TURBOFAN(BitSelect) {
    2381             :   WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
    2382             :   byte simd = r.AllocateLocal(kWasmS128);
    2383           5 :   BUILD(r,
    2384             :         WASM_SET_LOCAL(
    2385             :             simd,
    2386             :             WASM_SIMD_SELECT(32x4, WASM_SIMD_I32x4_SPLAT(WASM_I32V(0x01020304)),
    2387             :                              WASM_SIMD_I32x4_SPLAT(WASM_I32V(0)),
    2388             :                              WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0)))),
    2389             :         WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(simd)));
    2390             :   DCHECK_EQ(0x01020304, r.Call(0xFFFFFFFF));
    2391           5 : }
    2392             : 
    2393             : #undef WASM_SIMD_TEST
    2394             : #undef WASM_SIMD_CHECK_LANE
    2395             : #undef WASM_SIMD_CHECK4
    2396             : #undef WASM_SIMD_CHECK_SPLAT4
    2397             : #undef WASM_SIMD_CHECK8
    2398             : #undef WASM_SIMD_CHECK_SPLAT8
    2399             : #undef WASM_SIMD_CHECK16
    2400             : #undef WASM_SIMD_CHECK_SPLAT16
    2401             : #undef WASM_SIMD_CHECK_F32_LANE
    2402             : #undef WASM_SIMD_CHECK_F32x4
    2403             : #undef WASM_SIMD_CHECK_SPLAT_F32x4
    2404             : #undef WASM_SIMD_CHECK_F32_LANE_ESTIMATE
    2405             : #undef WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE
    2406             : #undef TO_BYTE
    2407             : #undef WASM_SIMD_OP
    2408             : #undef WASM_SIMD_SPLAT
    2409             : #undef WASM_SIMD_UNOP
    2410             : #undef WASM_SIMD_BINOP
    2411             : #undef WASM_SIMD_SHIFT_OP
    2412             : #undef WASM_SIMD_CONCAT_OP
    2413             : #undef WASM_SIMD_SELECT
    2414             : #undef WASM_SIMD_F32x4_SPLAT
    2415             : #undef WASM_SIMD_F32x4_EXTRACT_LANE
    2416             : #undef WASM_SIMD_F32x4_REPLACE_LANE
    2417             : #undef WASM_SIMD_I32x4_SPLAT
    2418             : #undef WASM_SIMD_I32x4_EXTRACT_LANE
    2419             : #undef WASM_SIMD_I32x4_REPLACE_LANE
    2420             : #undef WASM_SIMD_I16x8_SPLAT
    2421             : #undef WASM_SIMD_I16x8_EXTRACT_LANE
    2422             : #undef WASM_SIMD_I16x8_REPLACE_LANE
    2423             : #undef WASM_SIMD_I8x16_SPLAT
    2424             : #undef WASM_SIMD_I8x16_EXTRACT_LANE
    2425             : #undef WASM_SIMD_I8x16_REPLACE_LANE
    2426             : #undef WASM_SIMD_S8x16_SHUFFLE_OP
    2427             : #undef WASM_SIMD_LOAD_MEM
    2428             : #undef WASM_SIMD_STORE_MEM
    2429             : #undef WASM_SIMD_SELECT_TEST
    2430             : #undef WASM_SIMD_NON_CANONICAL_SELECT_TEST
    2431             : #undef WASM_SIMD_COMPILED_TEST
    2432             : #undef WASM_SIMD_BOOL_REDUCTION_TEST
    2433             : #undef WASM_SIMD_TEST_TURBOFAN
    2434             : #undef WASM_SIMD_ANYTRUE_TEST
    2435             : #undef WASM_SIMD_ALLTRUE_TEST
    2436             : 
    2437             : }  // namespace test_run_wasm_simd
    2438             : }  // namespace wasm
    2439             : }  // namespace internal
    2440       85011 : }  // namespace v8

Generated by: LCOV version 1.10