[wasm] Add simd unops to wasm interpreter

R=gdeepti@chromium.org,bbudge@chromium.org,clemensh@chromium.org,titzer@chromium.org
BUG=v8:6020

Change-Id: Ibc4e45df65ad8fc649e42b2166545cbc5fcb4296
Reviewed-on: https://chromium-review.googlesource.com/1070933
Reviewed-by: Ben Titzer <titzer@chromium.org>
Commit-Queue: Aseem Garg <aseemgarg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53346}
diff --git a/src/wasm/wasm-interpreter.cc b/src/wasm/wasm-interpreter.cc
index 4633de5..8a019dd 100644
--- a/src/wasm/wasm-interpreter.cc
+++ b/src/wasm/wasm-interpreter.cc
@@ -1710,6 +1710,27 @@
       BINOP_CASE(I8x16SubSaturateU, ui8x16, uint16, 16,
                  SaturateSub<uint8_t>(a, b))
 #undef BINOP_CASE
+#define UNOP_CASE(op, name, stype, count, expr) \
+  case kExpr##op: {                             \
+    WasmValue v = Pop();                        \
+    stype s = v.to_s128().to_##name();          \
+    stype res;                                  \
+    for (size_t i = 0; i < count; ++i) {        \
+      auto a = s.val[i];                        \
+      res.val[i] = expr;                        \
+    }                                           \
+    Push(WasmValue(Simd128(res)));              \
+    return true;                                \
+  }
+      UNOP_CASE(F32x4Abs, f32x4, float4, 4, std::abs(a))
+      UNOP_CASE(F32x4Neg, f32x4, float4, 4, -a)
+      UNOP_CASE(I32x4Neg, i32x4, int4, 4, -a)
+      UNOP_CASE(I16x8Neg, i16x8, int8, 8, -a)
+      UNOP_CASE(I8x16Neg, i8x16, int16, 16, -a)
+      UNOP_CASE(F32x4RecipApprox, f32x4, float4, 4, 1.0f / a)
+      UNOP_CASE(F32x4RecipSqrtApprox, f32x4, float4, 4, 1.0f / std::sqrt(a))
+      UNOP_CASE(S128Not, i32x4, int4, 4, ~a)
+#undef UNOP_CASE
       default:
         return false;
     }
diff --git a/test/cctest/wasm/test-run-wasm-simd.cc b/test/cctest/wasm/test-run-wasm-simd.cc
index 0320bd3..e806fbd 100644
--- a/test/cctest/wasm/test-run-wasm-simd.cc
+++ b/test/cctest/wasm/test-run-wasm-simd.cc
@@ -512,21 +512,21 @@
   }
 }
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Abs) {
+WASM_SIMD_TEST(F32x4Abs) {
   RunF32x4UnOpTest(execution_mode, lower_simd, kExprF32x4Abs, std::abs);
 }
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Neg) {
+WASM_SIMD_TEST(F32x4Neg) {
   RunF32x4UnOpTest(execution_mode, lower_simd, kExprF32x4Neg, Negate);
 }
 
 static const float kApproxError = 0.01f;
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4RecipApprox) {
+WASM_SIMD_TEST(F32x4RecipApprox) {
   RunF32x4UnOpTest(execution_mode, lower_simd, kExprF32x4RecipApprox, Recip,
                    kApproxError);
 }
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4RecipSqrtApprox) {
+WASM_SIMD_TEST(F32x4RecipSqrtApprox) {
   RunF32x4UnOpTest(execution_mode, lower_simd, kExprF32x4RecipSqrtApprox,
                    RecipSqrt, kApproxError);
 }
@@ -925,11 +925,11 @@
   FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
 }
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4Neg) {
+WASM_SIMD_TEST(I32x4Neg) {
   RunI32x4UnOpTest(execution_mode, lower_simd, kExprI32x4Neg, Negate);
 }
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(S128Not) {
+WASM_SIMD_TEST(S128Not) {
   RunI32x4UnOpTest(execution_mode, lower_simd, kExprS128Not, Not);
 }
 
@@ -1130,7 +1130,7 @@
   FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
 }
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8Neg) {
+WASM_SIMD_TEST(I16x8Neg) {
   RunI16x8UnOpTest(execution_mode, lower_simd, kExprI16x8Neg, Negate);
 }
 
@@ -1343,7 +1343,7 @@
   FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
 }
 
-WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16Neg) {
+WASM_SIMD_TEST(I8x16Neg) {
   RunI8x16UnOpTest(execution_mode, lower_simd, kExprI8x16Neg, Negate);
 }