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

[wasm] Add simd compare ops to wasm interpreter

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

Change-Id: I9d307a70d44504dc0e84e3e09d48bcc9b9542462
Reviewed-on: https://chromium-review.googlesource.com/1071095
Commit-Queue: Aseem Garg <aseemgarg@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53375}
parent f8445719
...@@ -1751,6 +1751,82 @@ class ThreadImpl { ...@@ -1751,6 +1751,82 @@ class ThreadImpl {
UNOP_CASE(I16x8Neg, i16x8, int8, 8, -a) UNOP_CASE(I16x8Neg, i16x8, int8, 8, -a)
UNOP_CASE(I8x16Neg, i8x16, int16, 16, -a) UNOP_CASE(I8x16Neg, i8x16, int16, 16, -a)
#undef UNOP_CASE #undef UNOP_CASE
#define CMPOP_CASE(op, name, stype, out_stype, count, expr) \
case kExpr##op: { \
WasmValue v2 = Pop(); \
WasmValue v1 = Pop(); \
stype s1 = v1.to_s128().to_##name(); \
stype s2 = v2.to_s128().to_##name(); \
out_stype res; \
for (size_t i = 0; i < count; ++i) { \
auto a = s1.val[i]; \
auto b = s2.val[i]; \
res.val[i] = expr ? -1 : 0; \
} \
Push(WasmValue(Simd128(res))); \
return true; \
}
CMPOP_CASE(F32x4Eq, f32x4, float4, int4, 4, a == b)
CMPOP_CASE(F32x4Ne, f32x4, float4, int4, 4, a != b)
CMPOP_CASE(F32x4Gt, f32x4, float4, int4, 4, a > b)
CMPOP_CASE(F32x4Ge, f32x4, float4, int4, 4, a >= b)
CMPOP_CASE(F32x4Lt, f32x4, float4, int4, 4, a < b)
CMPOP_CASE(F32x4Le, f32x4, float4, int4, 4, a <= b)
CMPOP_CASE(I32x4Eq, i32x4, int4, int4, 4, a == b)
CMPOP_CASE(I32x4Ne, i32x4, int4, int4, 4, a != b)
CMPOP_CASE(I32x4GtS, i32x4, int4, int4, 4, a > b)
CMPOP_CASE(I32x4GeS, i32x4, int4, int4, 4, a >= b)
CMPOP_CASE(I32x4LtS, i32x4, int4, int4, 4, a < b)
CMPOP_CASE(I32x4LeS, i32x4, int4, int4, 4, a <= b)
CMPOP_CASE(
I32x4GtU, i32x4, int4, int4, 4,
*reinterpret_cast<uint32_t*>(&a) > *reinterpret_cast<uint32_t*>(&b))
CMPOP_CASE(
I32x4GeU, i32x4, int4, int4, 4,
*reinterpret_cast<uint32_t*>(&a) >= *reinterpret_cast<uint32_t*>(&b))
CMPOP_CASE(
I32x4LtU, i32x4, int4, int4, 4,
*reinterpret_cast<uint32_t*>(&a) < *reinterpret_cast<uint32_t*>(&b))
CMPOP_CASE(
I32x4LeU, i32x4, int4, int4, 4,
*reinterpret_cast<uint32_t*>(&a) <= *reinterpret_cast<uint32_t*>(&b))
CMPOP_CASE(I16x8Eq, i16x8, int8, int8, 8, a == b)
CMPOP_CASE(I16x8Ne, i16x8, int8, int8, 8, a != b)
CMPOP_CASE(I16x8GtS, i16x8, int8, int8, 8, a > b)
CMPOP_CASE(I16x8GeS, i16x8, int8, int8, 8, a >= b)
CMPOP_CASE(I16x8LtS, i16x8, int8, int8, 8, a < b)
CMPOP_CASE(I16x8LeS, i16x8, int8, int8, 8, a <= b)
CMPOP_CASE(
I16x8GtU, i16x8, int8, int8, 8,
*reinterpret_cast<uint16_t*>(&a) > *reinterpret_cast<uint16_t*>(&b))
CMPOP_CASE(
I16x8GeU, i16x8, int8, int8, 8,
*reinterpret_cast<uint16_t*>(&a) >= *reinterpret_cast<uint16_t*>(&b))
CMPOP_CASE(
I16x8LtU, i16x8, int8, int8, 8,
*reinterpret_cast<uint16_t*>(&a) < *reinterpret_cast<uint16_t*>(&b))
CMPOP_CASE(
I16x8LeU, i16x8, int8, int8, 8,
*reinterpret_cast<uint16_t*>(&a) <= *reinterpret_cast<uint16_t*>(&b))
CMPOP_CASE(I8x16Eq, i8x16, int16, int16, 16, a == b)
CMPOP_CASE(I8x16Ne, i8x16, int16, int16, 16, a != b)
CMPOP_CASE(I8x16GtS, i8x16, int16, int16, 16, a > b)
CMPOP_CASE(I8x16GeS, i8x16, int16, int16, 16, a >= b)
CMPOP_CASE(I8x16LtS, i8x16, int16, int16, 16, a < b)
CMPOP_CASE(I8x16LeS, i8x16, int16, int16, 16, a <= b)
CMPOP_CASE(
I8x16GtU, i8x16, int16, int16, 16,
*reinterpret_cast<uint8_t*>(&a) > *reinterpret_cast<uint8_t*>(&b))
CMPOP_CASE(
I8x16GeU, i8x16, int16, int16, 16,
*reinterpret_cast<uint8_t*>(&a) >= *reinterpret_cast<uint8_t*>(&b))
CMPOP_CASE(
I8x16LtU, i8x16, int16, int16, 16,
*reinterpret_cast<uint8_t*>(&a) < *reinterpret_cast<uint8_t*>(&b))
CMPOP_CASE(
I8x16LeU, i8x16, int16, int16, 16,
*reinterpret_cast<uint8_t*>(&a) <= *reinterpret_cast<uint8_t*>(&b))
#undef CMPOP_CASE
default: default:
return false; return false;
} }
......
...@@ -598,27 +598,27 @@ void RunF32x4CompareOpTest(WasmExecutionMode execution_mode, ...@@ -598,27 +598,27 @@ void RunF32x4CompareOpTest(WasmExecutionMode execution_mode,
} }
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Eq) { WASM_SIMD_TEST(F32x4Eq) {
RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Eq, Equal); RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Eq, Equal);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Ne) { WASM_SIMD_TEST(F32x4Ne) {
RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Ne, NotEqual); RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Ne, NotEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Gt) { WASM_SIMD_TEST(F32x4Gt) {
RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Gt, Greater); RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Gt, Greater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Ge) { WASM_SIMD_TEST(F32x4Ge) {
RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Ge, GreaterEqual); RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Ge, GreaterEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Lt) { WASM_SIMD_TEST(F32x4Lt) {
RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Lt, Less); RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Lt, Less);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(F32x4Le) { WASM_SIMD_TEST(F32x4Le) {
RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Le, LessEqual); RunF32x4CompareOpTest(execution_mode, lower_simd, kExprF32x4Le, LessEqual);
} }
...@@ -1014,47 +1014,47 @@ void RunI32x4CompareOpTest(WasmExecutionMode execution_mode, ...@@ -1014,47 +1014,47 @@ void RunI32x4CompareOpTest(WasmExecutionMode execution_mode,
} }
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4Eq) { WASM_SIMD_TEST(I32x4Eq) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4Eq, Equal); RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4Eq, Equal);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4Ne) { WASM_SIMD_TEST(I32x4Ne) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4Ne, NotEqual); RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4Ne, NotEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4LtS) { WASM_SIMD_TEST(I32x4LtS) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LtS, Less); RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LtS, Less);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4LeS) { WASM_SIMD_TEST(I32x4LeS) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LeS, LessEqual); RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LeS, LessEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4GtS) { WASM_SIMD_TEST(I32x4GtS) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GtS, Greater); RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GtS, Greater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4GeS) { WASM_SIMD_TEST(I32x4GeS) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GeS, RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GeS,
GreaterEqual); GreaterEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4LtU) { WASM_SIMD_TEST(I32x4LtU) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LtU, RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LtU,
UnsignedLess); UnsignedLess);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4LeU) { WASM_SIMD_TEST(I32x4LeU) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LeU, RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4LeU,
UnsignedLessEqual); UnsignedLessEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4GtU) { WASM_SIMD_TEST(I32x4GtU) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GtU, RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GtU,
UnsignedGreater); UnsignedGreater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I32x4GeU) { WASM_SIMD_TEST(I32x4GeU) {
RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GeU, RunI32x4CompareOpTest(execution_mode, lower_simd, kExprI32x4GeU,
UnsignedGreaterEqual); UnsignedGreaterEqual);
} }
...@@ -1255,47 +1255,47 @@ void RunI16x8CompareOpTest(WasmExecutionMode execution_mode, ...@@ -1255,47 +1255,47 @@ void RunI16x8CompareOpTest(WasmExecutionMode execution_mode,
} }
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8Eq) { WASM_SIMD_TEST(I16x8Eq) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8Eq, Equal); RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8Eq, Equal);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8Ne) { WASM_SIMD_TEST(I16x8Ne) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8Ne, NotEqual); RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8Ne, NotEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8LtS) { WASM_SIMD_TEST(I16x8LtS) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LtS, Less); RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LtS, Less);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8LeS) { WASM_SIMD_TEST(I16x8LeS) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LeS, LessEqual); RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LeS, LessEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8GtS) { WASM_SIMD_TEST(I16x8GtS) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GtS, Greater); RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GtS, Greater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8GeS) { WASM_SIMD_TEST(I16x8GeS) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GeS, RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GeS,
GreaterEqual); GreaterEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8GtU) { WASM_SIMD_TEST(I16x8GtU) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GtU, RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GtU,
UnsignedGreater); UnsignedGreater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8GeU) { WASM_SIMD_TEST(I16x8GeU) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GeU, RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8GeU,
UnsignedGreaterEqual); UnsignedGreaterEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8LtU) { WASM_SIMD_TEST(I16x8LtU) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LtU, RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LtU,
UnsignedLess); UnsignedLess);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I16x8LeU) { WASM_SIMD_TEST(I16x8LeU) {
RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LeU, RunI16x8CompareOpTest(execution_mode, lower_simd, kExprI16x8LeU,
UnsignedLessEqual); UnsignedLessEqual);
} }
...@@ -1464,54 +1464,54 @@ void RunI8x16CompareOpTest(WasmExecutionMode execution_mode, ...@@ -1464,54 +1464,54 @@ void RunI8x16CompareOpTest(WasmExecutionMode execution_mode,
} }
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16Eq) { WASM_SIMD_TEST(I8x16Eq) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16Eq, Equal); RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16Eq, Equal);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16Ne) { WASM_SIMD_TEST(I8x16Ne) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16Ne, NotEqual); RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16Ne, NotEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16GtS) { WASM_SIMD_TEST(I8x16GtS) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GtS, Greater); RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GtS, Greater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16GeS) { WASM_SIMD_TEST(I8x16GeS) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GeS, RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GeS,
GreaterEqual); GreaterEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16LtS) { WASM_SIMD_TEST(I8x16LtS) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LtS, Less); RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LtS, Less);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16LeS) { WASM_SIMD_TEST(I8x16LeS) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LeS, LessEqual); RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LeS, LessEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16GtU) { WASM_SIMD_TEST(I8x16GtU) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GtU, RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GtU,
UnsignedGreater); UnsignedGreater);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16GeU) { WASM_SIMD_TEST(I8x16GeU) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GeU, RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16GeU,
UnsignedGreaterEqual); UnsignedGreaterEqual);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16LtU) { WASM_SIMD_TEST(I8x16LtU) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LtU, RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LtU,
UnsignedLess); UnsignedLess);
} }
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16LeU) { WASM_SIMD_TEST(I8x16LeU) {
RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LeU, RunI8x16CompareOpTest(execution_mode, lower_simd, kExprI8x16LeU,
UnsignedLessEqual); UnsignedLessEqual);
} }
#if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS || \ #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS || \
V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_IA32 V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_IA32
WASM_SIMD_COMPILED_AND_LOWERED_TEST(I8x16Mul) { WASM_SIMD_TEST(I8x16Mul) {
RunI8x16BinOpTest(execution_mode, lower_simd, kExprI8x16Mul, Mul); RunI8x16BinOpTest(execution_mode, lower_simd, kExprI8x16Mul, Mul);
} }
#endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS || #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS ||
......
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