Skip to content

Commit 72ad664

Browse files
authored
[wasm] Add Vector128.AndNot intrinsics (#78133)
* [wasm] Add Vector128.AndNot intrinsics C# var v = Vector128.Create(System.Random.Shared.Next(), System.Random.Shared.Next(), System.Random.Shared.Next(), System.Random.Shared.Next()); var v2 = Vector128.Create(System.Random.Shared.Next(), System.Random.Shared.Next(), System.Random.Shared.Next(), System.Random.Shared.Next()); v = Vector128.AndNot(v, v2); is emitted as ... i32x4.splat [SIMD] local.get $5 i32x4.replace.lane 1 [SIMD] local.get $6 i32x4.replace.lane 2 [SIMD] local.get $7 i32x4.replace.lane 3 [SIMD] local.get $8 i32x4.splat [SIMD] local.get $9 i32x4.replace.lane 1 [SIMD] local.get $10 i32x4.replace.lane 2 [SIMD] local.get $2 i32x4.replace.lane 3 [SIMD] v128.andnot [SIMD] v128.store offset:8 align:3 [SIMD] ... * Review feedback
1 parent cd7e871 commit 72ad664

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8775,18 +8775,6 @@ MONO_RESTORE_WARNING
87758775
break;
87768776
}
87778777

8778-
case OP_SSE_ANDN: {
8779-
LLVMValueRef minus_one [2];
8780-
minus_one [0] = const_int64 (-1);
8781-
minus_one [1] = const_int64 (-1);
8782-
LLVMValueRef vec_lhs_i64 = convert (ctx, lhs, sse_i8_t);
8783-
LLVMValueRef vec_xor = LLVMBuildXor (builder, vec_lhs_i64, LLVMConstVector (minus_one, 2), "");
8784-
LLVMValueRef vec_rhs_i64 = convert (ctx, rhs, sse_i8_t);
8785-
LLVMValueRef vec_and = LLVMBuildAnd (builder, vec_rhs_i64, vec_xor, "");
8786-
values [ins->dreg] = LLVMBuildBitCast (builder, vec_and, type_to_sse_type (ins->inst_c1), "");
8787-
break;
8788-
}
8789-
87908778
case OP_SSE_ADDSS:
87918779
case OP_SSE_SUBSS:
87928780
case OP_SSE_DIVSS:
@@ -9594,6 +9582,18 @@ MONO_RESTORE_WARNING
95949582
#endif
95959583

95969584
#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_WASM)
9585+
case OP_VECTOR_ANDN: {
9586+
LLVMValueRef minus_one [2];
9587+
minus_one [0] = const_int64 (-1);
9588+
minus_one [1] = const_int64 (-1);
9589+
LLVMValueRef vec_lhs_i64 = convert (ctx, lhs, sse_i8_t);
9590+
LLVMValueRef vec_xor = LLVMBuildXor (builder, vec_lhs_i64, LLVMConstVector (minus_one, 2), "");
9591+
LLVMValueRef vec_rhs_i64 = convert (ctx, rhs, sse_i8_t);
9592+
LLVMValueRef vec_and = LLVMBuildAnd (builder, vec_rhs_i64, vec_xor, "");
9593+
values [ins->dreg] = LLVMBuildBitCast (builder, vec_and, type_to_sse_type (ins->inst_c1), "");
9594+
break;
9595+
}
9596+
95979597
case OP_VECTOR_IABS: {
95989598
// %sub = sub <16 x i8> zeroinitializer, %arg
95999599
// %cmp = icmp sgt <16 x i8> %arg, zeroinitializer

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ MINI_OP(OP_CVTTPD2DQ, "cvttpd2dq", XREG, XREG, NONE)
10271027
MINI_OP(OP_CVTTPS2DQ, "cvttps2dq", XREG, XREG, NONE)
10281028

10291029
MINI_OP(OP_VECTOR_IABS, "vector_integer_abs", XREG, XREG, NONE)
1030+
MINI_OP(OP_VECTOR_ANDN, "vector_andnot", XREG, XREG, XREG)
10301031

10311032
/* sse 1 */
10321033
/* inst_c1 is target type */
@@ -1044,7 +1045,6 @@ MINI_OP3(OP_SSE_SHUFPS, "sse_shufps", XREG, XREG, XREG, IREG)
10441045
MINI_OP(OP_SSE_AND, "sse_and", XREG, XREG, XREG)
10451046
MINI_OP(OP_SSE_OR, "sse_or", XREG, XREG, XREG)
10461047
MINI_OP(OP_SSE_XOR, "sse_xor", XREG, XREG, XREG)
1047-
MINI_OP(OP_SSE_ANDN, "sse_andn", XREG, XREG, XREG)
10481048
MINI_OP(OP_SSE_ADDSS, "sse_addss", XREG, XREG, XREG)
10491049
MINI_OP(OP_SSE_SUBSS, "sse_subss", XREG, XREG, XREG)
10501050
MINI_OP(OP_SSE_DIVSS, "sse_divss", XREG, XREG, XREG)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
11511151
// args [0] & ~vector(-0.0)
11521152
MonoInst *zero = emit_xzero(cfg, arg_class); // 0.0
11531153
zero = emit_simd_ins (cfg, klass, OP_NEGATION, zero->dreg, -1); // -0.0
1154-
MonoInst *ins = emit_simd_ins (cfg, klass, OP_SSE_ANDN, zero->dreg, args [0]->dreg);
1154+
MonoInst *ins = emit_simd_ins (cfg, klass, OP_VECTOR_ANDN, zero->dreg, args [0]->dreg);
11551155
ins->inst_c1 = arg0_type;
11561156
return ins;
11571157
} else {
@@ -1184,14 +1184,14 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
11841184
return NULL;
11851185
#ifdef TARGET_ARM64
11861186
return emit_simd_ins_for_sig (cfg, klass, OP_ARM64_BIC, -1, arg0_type, fsig, args);
1187-
#elif defined(TARGET_AMD64)
1187+
#elif defined(TARGET_AMD64) || defined(TARGET_WASM)
11881188
/* Swap lhs and rhs because Vector128 needs lhs & !rhs
11891189
whereas SSE2 does !lhs & rhs */
11901190
MonoInst *tmp = args[0];
11911191
args[0] = args[1];
11921192
args[1] = tmp;
11931193

1194-
return emit_simd_ins_for_sig (cfg, klass, OP_SSE_ANDN, -1, arg0_type, fsig, args);
1194+
return emit_simd_ins_for_sig (cfg, klass, OP_VECTOR_ANDN, -1, arg0_type, fsig, args);
11951195
#else
11961196
return NULL;
11971197
#endif
@@ -3199,7 +3199,7 @@ static SimdIntrinsic sse_methods [] = {
31993199
{SN_Add, OP_XBINOP, OP_FADD},
32003200
{SN_AddScalar, OP_SSE_ADDSS},
32013201
{SN_And, OP_SSE_AND},
3202-
{SN_AndNot, OP_SSE_ANDN},
3202+
{SN_AndNot, OP_VECTOR_ANDN},
32033203
{SN_CompareEqual, OP_XCOMPARE_FP, CMP_EQ},
32043204
{SN_CompareGreaterThan, OP_XCOMPARE_FP,CMP_GT},
32053205
{SN_CompareGreaterThanOrEqual, OP_XCOMPARE_FP, CMP_GE},
@@ -3290,7 +3290,7 @@ static SimdIntrinsic sse2_methods [] = {
32903290
{SN_AddSaturate, OP_SSE2_ADDS},
32913291
{SN_AddScalar, OP_SSE2_ADDSD},
32923292
{SN_And, OP_SSE_AND},
3293-
{SN_AndNot, OP_SSE_ANDN},
3293+
{SN_AndNot, OP_VECTOR_ANDN},
32943294
{SN_Average},
32953295
{SN_CompareEqual},
32963296
{SN_CompareGreaterThan},

0 commit comments

Comments
 (0)