Skip to content

Commit 51d467a

Browse files
authored
[interp] Undo damage to the simd methods bsearch list; support vectors of char (#86475)
While inspecting the performance of some vectorized BCL code, I noticed that I accidentally damaged one of the binary search lists. There also appear to be some cases where vectors of char are used, so I touched up the code to make sure that we will select the right intrinsic in that case if we already supported U2.
1 parent bc0b71c commit 51d467a

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/mono/mono/mini/interp/transform-simd.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ lookup_intrins (guint16 *intrinsics, int size, MonoMethod *cmethod)
4545
return (int)*result;
4646
}
4747

48+
// These items need to be in ASCII order, which means alphabetical order where lowercase is after uppercase
49+
// i.e. all 'get_' and 'op_' need to come after regular title-case names
4850
static guint16 sri_vector128_methods [] = {
4951
SN_AndNot,
5052
SN_ConditionalSelect,
@@ -67,6 +69,10 @@ static guint16 sri_vector128_methods [] = {
6769
};
6870

6971
static guint16 sri_vector128_t_methods [] = {
72+
SN_get_AllBitsSet,
73+
SN_get_Count,
74+
SN_get_One,
75+
SN_get_Zero,
7076
SN_op_Addition,
7177
SN_op_BitwiseAnd,
7278
SN_op_BitwiseOr,
@@ -81,10 +87,6 @@ static guint16 sri_vector128_t_methods [] = {
8187
SN_op_Subtraction,
8288
SN_op_UnaryNegation,
8389
SN_op_UnsignedRightShift,
84-
SN_get_AllBitsSet,
85-
SN_get_Count,
86-
SN_get_One,
87-
SN_get_Zero,
8890
};
8991

9092
static guint16 sri_packedsimd_methods [] = {
@@ -242,7 +244,7 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
242244
case SN_Equals:
243245
simd_opcode = MINT_SIMD_INTRINS_P_PP;
244246
if (atype == MONO_TYPE_I1 || atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_EQUALS;
245-
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_EQUALS;
247+
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_EQUALS;
246248
else if (atype == MONO_TYPE_I4 || atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_EQUALS;
247249
else if (atype == MONO_TYPE_I8 || atype == MONO_TYPE_U8) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I8_EQUALS;
248250
break;
@@ -265,7 +267,7 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
265267
break;
266268
case SN_LessThanOrEqual:
267269
simd_opcode = MINT_SIMD_INTRINS_P_PP;
268-
if (atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_U2_LESS_THAN_EQUAL;
270+
if (atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_U2_LESS_THAN_EQUAL;
269271
break;
270272
case SN_Narrow:
271273
simd_opcode = MINT_SIMD_INTRINS_P_PP;
@@ -294,7 +296,7 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
294296
else if (atype == MONO_TYPE_I2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_RIGHT_SHIFT;
295297
else if (atype == MONO_TYPE_I4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_RIGHT_SHIFT;
296298
else if (atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_URIGHT_SHIFT;
297-
else if (atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_URIGHT_SHIFT;
299+
else if (atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_URIGHT_SHIFT;
298300
else if (atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_URIGHT_SHIFT;
299301
break;
300302
case SN_Shuffle:
@@ -306,11 +308,11 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
306308
break;
307309
case SN_WidenLower:
308310
simd_opcode = MINT_SIMD_INTRINS_P_P;
309-
if (atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_U2_WIDEN_LOWER;
311+
if (atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_U2_WIDEN_LOWER;
310312
break;
311313
case SN_WidenUpper:
312314
simd_opcode = MINT_SIMD_INTRINS_P_P;
313-
if (atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_U2_WIDEN_UPPER;
315+
if (atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_U2_WIDEN_UPPER;
314316
break;
315317
default:
316318
return FALSE;
@@ -388,7 +390,7 @@ emit_sri_vector128_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignatur
388390
for (int i = 0; i < vector_size / arg_size; i++)
389391
data [i] = 1;
390392
goto opcode_added;
391-
} else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2) {
393+
} else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) {
392394
interp_add_ins (td, MINT_SIMD_V128_LDC);
393395
gint16 *data = (gint16*)&td->last_ins->data [0];
394396
for (int i = 0; i < vector_size / arg_size; i++)
@@ -415,7 +417,7 @@ emit_sri_vector128_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignatur
415417
case SN_op_Addition:
416418
simd_opcode = MINT_SIMD_INTRINS_P_PP;
417419
if (atype == MONO_TYPE_I1 || atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_ADD;
418-
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_ADD;
420+
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_ADD;
419421
else if (atype == MONO_TYPE_I4 || atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_ADD;
420422
break;
421423
case SN_op_BitwiseAnd:
@@ -462,7 +464,7 @@ emit_sri_vector128_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignatur
462464
return FALSE;
463465
simd_opcode = MINT_SIMD_INTRINS_P_PP;
464466
if (atype == MONO_TYPE_I1 || atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_MULTIPLY;
465-
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_MULTIPLY;
467+
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_MULTIPLY;
466468
else if (atype == MONO_TYPE_I4 || atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_MULTIPLY;
467469
else if (atype == MONO_TYPE_R4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_R4_MULTIPLY;
468470
break;
@@ -478,19 +480,19 @@ emit_sri_vector128_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignatur
478480
else if (atype == MONO_TYPE_I2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_RIGHT_SHIFT;
479481
else if (atype == MONO_TYPE_I4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_RIGHT_SHIFT;
480482
else if (atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_URIGHT_SHIFT;
481-
else if (atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_URIGHT_SHIFT;
483+
else if (atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_URIGHT_SHIFT;
482484
else if (atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_URIGHT_SHIFT;
483485
break;
484486
case SN_op_Subtraction:
485487
simd_opcode = MINT_SIMD_INTRINS_P_PP;
486488
if (atype == MONO_TYPE_I1 || atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_SUB;
487-
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_SUB;
489+
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_SUB;
488490
else if (atype == MONO_TYPE_I4 || atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_SUB;
489491
break;
490492
case SN_op_UnaryNegation:
491493
simd_opcode = MINT_SIMD_INTRINS_P_P;
492494
if (atype == MONO_TYPE_I1 || atype == MONO_TYPE_U1) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I1_NEGATION;
493-
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_NEGATION;
495+
else if (atype == MONO_TYPE_I2 || atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I2_NEGATION;
494496
else if (atype == MONO_TYPE_I4 || atype == MONO_TYPE_U4) simd_intrins = INTERP_SIMD_INTRINSIC_V128_I4_NEGATION;
495497
break;
496498
case SN_op_UnsignedRightShift:
@@ -686,7 +688,7 @@ emit_sri_packedsimd (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
686688
simd_opcode = MINT_SIMD_INTRINS_P_PP;
687689
if (atype == MONO_TYPE_U1)
688690
simd_intrins = INTERP_SIMD_INTRINSIC_WASM_I8X16_NARROW_I16X8_U;
689-
else if (atype == MONO_TYPE_U2)
691+
else if (atype == MONO_TYPE_U2 || atype == MONO_TYPE_CHAR)
690692
simd_intrins = INTERP_SIMD_INTRINSIC_WASM_I16X8_NARROW_I32X4_U;
691693
break;
692694
}

0 commit comments

Comments
 (0)