Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[wasm] Improve SIMD vector equality operator #79719

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/mono/mono/mini/llvm-intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ INTRINS_OVR(SSE_SSUB_SATI16, ssub_sat, Generic, v128_i2_t)
INTRINS_OVR(SSE_USUB_SATI16, usub_sat, Generic, v128_i2_t)
#endif
#if defined(TARGET_WASM)
INTRINS_OVR(WASM_ALLTRUE_V16, wasm_alltrue, Wasm, sse_i1_t)
INTRINS_OVR(WASM_ALLTRUE_V8, wasm_alltrue, Wasm, sse_i2_t)
INTRINS_OVR(WASM_ALLTRUE_V4, wasm_alltrue, Wasm, sse_i4_t)
INTRINS_OVR(WASM_ALLTRUE_V2, wasm_alltrue, Wasm, sse_i8_t)
INTRINS_OVR(WASM_ANYTRUE_V16, wasm_anytrue, Wasm, sse_i1_t)
INTRINS_OVR(WASM_ANYTRUE_V8, wasm_anytrue, Wasm, sse_i2_t)
INTRINS_OVR(WASM_ANYTRUE_V4, wasm_anytrue, Wasm, sse_i4_t)
Expand Down
29 changes: 24 additions & 5 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -9791,13 +9791,10 @@ MONO_RESTORE_WARNING
int nelems;

#if defined(TARGET_WASM)
IntrinsicId intrins = (IntrinsicId)0;
nelems = LLVMGetVectorSize (LLVMTypeOf (lhs));
/* The wasm code generator doesn't understand the shuffle/and code sequence below */
LLVMValueRef val;
if (LLVMIsNull (lhs) || LLVMIsNull (rhs)) {
val = LLVMIsNull (lhs) ? rhs : lhs;
nelems = LLVMGetVectorSize (LLVMTypeOf (lhs));

IntrinsicId intrins = (IntrinsicId)0;
switch (nelems) {
case 16:
intrins = INTRINS_WASM_ANYTRUE_V16;
Expand All @@ -9814,6 +9811,8 @@ MONO_RESTORE_WARNING
default:
g_assert_not_reached ();
}
LLVMValueRef val = LLVMIsNull (lhs) ? rhs : lhs;

/* res = !wasm.anytrue (val) */
values [ins->dreg] = call_intrins (ctx, intrins, &val, "");
values [ins->dreg] = LLVMBuildZExt (builder, LLVMBuildICmp (builder, LLVMIntEQ, values [ins->dreg], const_int32 (0), ""), LLVMInt32Type (), dname);
Expand All @@ -9839,6 +9838,26 @@ MONO_RESTORE_WARNING

t = LLVMVectorType (elemt, nelems);
cmp = LLVMBuildSExt (builder, cmp, t, "");
#if defined(TARGET_WASM)
switch (nelems) {
case 16:
intrins = INTRINS_WASM_ALLTRUE_V16;
break;
case 8:
intrins = INTRINS_WASM_ALLTRUE_V8;
break;
case 4:
intrins = INTRINS_WASM_ALLTRUE_V4;
break;
case 2:
intrins = INTRINS_WASM_ALLTRUE_V2;
break;
default:
g_assert_not_reached ();
}
values [ins->dreg] = call_intrins (ctx, intrins, &cmp, "");
break;
#endif
// cmp is a <nelems x elemt> vector, each element is either 0xff... or 0
int half = nelems / 2;
while (half >= 1) {
Expand Down