Commit bedcef5c authored by Aseem Garg's avatar Aseem Garg Committed by Commit Bot

[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/1070933Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Aseem Garg <aseemgarg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53346}
parent fb436a5e
......@@ -1710,6 +1710,27 @@ class ThreadImpl {
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;
}
......
......@@ -512,21 +512,21 @@ void RunF32x4UnOpTest(WasmExecutionMode execution_mode, LowerSimd lower_simd,
}
}
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 @@ void RunI32x4UnOpTest(WasmExecutionMode execution_mode, LowerSimd lower_simd,
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 @@ void RunI16x8UnOpTest(WasmExecutionMode execution_mode, LowerSimd lower_simd,
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 @@ void RunI8x16UnOpTest(WasmExecutionMode execution_mode, LowerSimd lower_simd,
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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment