Skip to content

Commit 3454d8c

Browse files
authored
[wasm] Add ConditionalSelect SIMD intrinsics (#80145)
It uses existing `OP_BSL`, which does And, Not, And and Or operations. llvm emits it as `v128.bitselect` for us. So I think we don't need to use the `llvm.wasm.bitselect.*` intrinsics. This should help in few areas, SpanHelper.ReplaceValueType and IndexOfAnyAsciiSearcher.IndexOfAnyLookup'1. It improves the Json deserialization a bit: | measurement | before | after | |-:|-:|-:| | Json, non-ASCII text deserialize | 0.4343ms | 0.4275ms | | Json, small deserialize | 0.0517ms | 0.0497ms | | Json, large deserialize | 14.3995ms | 13.8217ms | Example of emitted code: > wa-info -d -f SpanHelper.*ReplaceValueType src\mono\sample\wasm\browser-bench\bin\Release\AppBundle\dotnet.wasm (func corlib_System_SpanHelpers_ReplaceValueType_uint16_uint16__uint16__uint16_uint16_uintptr(param $0 i32, $1 i32, $2 i32, $3 i32, $4 i32, $5 i32)) ... i16x8.eq [SIMD] v128.bitselect [SIMD] v128.store [SIMD] ...
1 parent 7690b0a commit 3454d8c

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/mono/mono/mini/mini-llvm.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -11305,7 +11305,7 @@ MONO_RESTORE_WARNING
1130511305
break;
1130611306
}
1130711307
#endif
11308-
#if defined(TARGET_ARM64) || defined(TARGET_AMD64)
11308+
#if defined(TARGET_ARM64) || defined(TARGET_AMD64) || defined(TARGET_WASM)
1130911309
case OP_BSL: {
1131011310
LLVMTypeRef ret_t = LLVMTypeOf (rhs);
1131111311
LLVMValueRef select = bitcast_to_integral (ctx, lhs);
@@ -11318,6 +11318,8 @@ MONO_RESTORE_WARNING
1131811318
values [ins->dreg] = result;
1131911319
break;
1132011320
}
11321+
#endif
11322+
#if defined(TARGET_ARM64) || defined(TARGET_AMD64)
1132111323
case OP_NEGATION:
1132211324
case OP_NEGATION_SCALAR: {
1132311325
gboolean scalar = ins->opcode == OP_NEGATION_SCALAR;

src/mono/mono/mini/mini-ops.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,6 @@ MINI_OP(OP_WASM_ONESCOMPLEMENT, "wasm_onescomplement", XREG, XREG, NONE)
17671767
#endif
17681768

17691769
#if defined(TARGET_ARM64) || defined(TARGET_AMD64)
1770-
MINI_OP3(OP_BSL, "bitwise_select", XREG, XREG, XREG, XREG)
17711770
MINI_OP(OP_NEGATION, "negate", XREG, XREG, NONE)
17721771
MINI_OP(OP_NEGATION_SCALAR, "negate_scalar", XREG, XREG, NONE)
17731772
MINI_OP(OP_ONES_COMPLEMENT, "ones_complement", XREG, XREG, NONE)
@@ -1782,3 +1781,7 @@ MINI_OP(OP_CVT_SI_FP, "convert_si_to_fp", XREG, XREG, NONE)
17821781
MINI_OP(OP_CVT_UI_FP_SCALAR, "convert_ui_to_fp_scalar", XREG, XREG, NONE)
17831782
MINI_OP(OP_CVT_SI_FP_SCALAR, "convert_si_to_fp_scalar", XREG, XREG, NONE)
17841783
#endif // TARGET_ARM64 || TARGET_AMD64
1784+
1785+
#if defined(TARGET_ARM64) || defined(TARGET_AMD64) || defined(TARGET_WASM)
1786+
MINI_OP3(OP_BSL, "bitwise_select", XREG, XREG, XREG, XREG)
1787+
#endif // TARGET_ARM64 || TARGET_AMD64 || TARGET_WASM

src/mono/mono/mini/simd-intrinsics.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
12531253
#endif
12541254
}
12551255
case SN_ConditionalSelect: {
1256-
#if defined(TARGET_ARM64) || defined(TARGET_AMD64)
1256+
#if defined(TARGET_ARM64) || defined(TARGET_AMD64) || defined(TARGET_WASM)
12571257
if (!is_element_type_primitive (fsig->params [0]))
12581258
return NULL;
12591259
return emit_simd_ins_for_sig (cfg, klass, OP_BSL, -1, arg0_type, fsig, args);

0 commit comments

Comments
 (0)