未验证 提交 fda566e9 编写于 作者: Z Zoltan Varga 提交者: GitHub

[mono][wasm] Make OP_WASM_SIMD_SWIZZLE use the shufflevector LLVM ins… (#75057)

* [mono][wasm] Make OP_WASM_SIMD_SWIZZLE use the shufflevector LLVM instruction.

The wasm.swizzle instrinsic always uses byte sized SIMD lanes, so it cannot represent
all the variants of Vector128.Shuffle ().

* Enable SIMD by default for testing.

* Remove an assert.

* Work around an LLVM problem.

* Revert "Enable SIMD by default for testing."

This reverts commit eebc533d4b90fdd32bbf5ea737bfa29243bdfbfe.
上级 37099411
......@@ -262,7 +262,6 @@ INTRINS_OVR(WASM_BITMASK_V8, wasm_bitmask, Wasm, sse_i1_t)
INTRINS_OVR(WASM_BITMASK_V4, wasm_bitmask, Wasm, sse_i4_t)
INTRINS_OVR(WASM_BITMASK_V2, wasm_bitmask, Wasm, sse_i8_t)
INTRINS(WASM_SHUFFLE, wasm_shuffle, Wasm)
INTRINS(WASM_SWIZZLE, wasm_swizzle, Wasm)
#endif
#if defined(TARGET_ARM64)
INTRINS_OVR(BITREVERSE_I32, bitreverse, Generic, LLVMInt32Type ())
......
......@@ -7713,6 +7713,14 @@ MONO_RESTORE_WARNING
default:
element_ix = const_int32 (ins->inst_c0);
}
#ifdef TARGET_WASM
// LLVM seems to return an invalid result when the input is undef (i.e. the result of an invalid shufflevector for example)
if (LLVMIsUndef (lhs)) {
values [ins->dreg] = LLVMConstNull (LLVMGetElementType (LLVMTypeOf (lhs)));
break;
}
#endif
LLVMTypeRef lhs_t = LLVMTypeOf (lhs);
int vec_width = mono_llvm_get_prim_size_bits (lhs_t);
int elem_width = mono_llvm_get_prim_size_bits (elt_t);
......@@ -9717,8 +9725,14 @@ MONO_RESTORE_WARNING
break;
}
case OP_WASM_SIMD_SWIZZLE: {
LLVMValueRef args [] = { lhs, rhs };
values [ins->dreg] = call_intrins (ctx, INTRINS_WASM_SWIZZLE, args, "");
int nelems = LLVMGetVectorSize (LLVMTypeOf (lhs));
LLVMValueRef indexes [16];
for (int i = 0; i < nelems; ++i)
indexes [i] = LLVMBuildExtractElement (builder, rhs, const_int32 (i), "");
LLVMValueRef shuffle_val = LLVMConstNull (LLVMVectorType (i4_t, nelems));
for (int i = 0; i < nelems; ++i)
shuffle_val = LLVMBuildInsertElement (builder, shuffle_val, convert (ctx, indexes [i], i4_t), const_int32 (i), "");
values [ins->dreg] = LLVMBuildShuffleVector (builder, lhs, LLVMGetUndef (LLVMTypeOf (lhs)), shuffle_val, "");
break;
}
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册