Skip to content

Commit f696eb3

Browse files
Add support for other same size vector bitcasts to Mono (#104309)
* Add support for other same size vector bitcasts to Mono * Ensure get_common_simd_info handles non-generic input parameters * Ensure emit_sri_vector128 correctly checks for the generic type argument
1 parent 284aeaf commit f696eb3

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

src/mono/mono/mini/interp/simd-methods.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ SIMD_METHOD(AsInt32)
3131
SIMD_METHOD(AsInt64)
3232
SIMD_METHOD(AsNInt)
3333
SIMD_METHOD(AsNUInt)
34+
SIMD_METHOD(AsPlane)
35+
SIMD_METHOD(AsQuaternion)
3436
SIMD_METHOD(AsSByte)
3537
SIMD_METHOD(AsSingle)
3638
SIMD_METHOD(AsUInt16)
3739
SIMD_METHOD(AsUInt32)
3840
SIMD_METHOD(AsUInt64)
41+
SIMD_METHOD(AsVector)
42+
SIMD_METHOD(AsVector4)
43+
SIMD_METHOD(AsVector128)
3944
SIMD_METHOD(ConditionalSelect)
4045
SIMD_METHOD(Create)
4146
SIMD_METHOD(CreateScalar)

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@ static guint16 sri_vector128_methods [] = {
6464
SN_AsInt64,
6565
SN_AsNInt,
6666
SN_AsNUInt,
67+
SN_AsPlane,
68+
SN_AsQuaternion,
6769
SN_AsSByte,
6870
SN_AsSingle,
6971
SN_AsUInt16,
7072
SN_AsUInt32,
7173
SN_AsUInt64,
74+
SN_AsVector,
75+
SN_AsVector4,
76+
SN_AsVector128,
7277
SN_ConditionalSelect,
7378
SN_Create,
7479
SN_CreateScalar,
@@ -424,7 +429,13 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
424429
gint16 simd_opcode = -1;
425430
gint16 simd_intrins = -1;
426431

427-
vector_klass = mono_class_from_mono_type_internal (csignature->ret);
432+
if (csignature->ret->type == MONO_TYPE_GENERICINST) {
433+
vector_klass = mono_class_from_mono_type_internal (csignature->ret);
434+
} else if (csignature->params [0]->type == MONO_TYPE_GENERICINST) {
435+
vector_klass = mono_class_from_mono_type_internal (csignature->params [0]);
436+
} else {
437+
return FALSE;
438+
}
428439

429440
MonoTypeEnum atype;
430441
int arg_size, scalar_arg;
@@ -444,6 +455,8 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
444455
case SN_AsInt64:
445456
case SN_AsNInt:
446457
case SN_AsNUInt:
458+
case SN_AsPlane:
459+
case SN_AsQuaternion:
447460
case SN_AsSByte:
448461
case SN_AsSingle:
449462
case SN_AsUInt16:
@@ -455,6 +468,25 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
455468
simd_intrins = INTERP_SIMD_INTRINSIC_V128_BITCAST;
456469
break;
457470
}
471+
case SN_AsVector:
472+
case SN_AsVector128:
473+
case SN_AsVector4: {
474+
if (!is_element_type_primitive (csignature->ret) || !is_element_type_primitive (csignature->params [0]))
475+
return FALSE;
476+
477+
MonoClass *ret_class = mono_class_from_mono_type_internal (csignature->ret);
478+
int ret_size = mono_class_value_size (ret_class, NULL);
479+
480+
MonoClass *arg_class = mono_class_from_mono_type_internal (csignature->params [0]);
481+
int arg_size = mono_class_value_size (arg_class, NULL);
482+
483+
if (arg_size == ret_size) {
484+
simd_opcode = MINT_SIMD_INTRINS_P_P;
485+
simd_intrins = INTERP_SIMD_INTRINSIC_V128_BITCAST;
486+
break;
487+
}
488+
return FALSE;
489+
}
458490
case SN_ConditionalSelect:
459491
simd_opcode = MINT_SIMD_INTRINS_P_PPP;
460492
simd_intrins = INTERP_SIMD_INTRINSIC_V128_CONDITIONAL_SELECT;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,11 +1187,16 @@ static guint16 sri_vector_methods [] = {
11871187
SN_AsInt64,
11881188
SN_AsNInt,
11891189
SN_AsNUInt,
1190+
SN_AsPlane,
1191+
SN_AsQuaternion,
11901192
SN_AsSByte,
11911193
SN_AsSingle,
11921194
SN_AsUInt16,
11931195
SN_AsUInt32,
11941196
SN_AsUInt64,
1197+
SN_AsVector,
1198+
SN_AsVector128,
1199+
SN_AsVector4,
11951200
SN_BitwiseAnd,
11961201
SN_BitwiseOr,
11971202
SN_Ceiling,
@@ -1622,6 +1627,8 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
16221627
case SN_AsInt64:
16231628
case SN_AsNInt:
16241629
case SN_AsNUInt:
1630+
case SN_AsPlane:
1631+
case SN_AsQuaternion:
16251632
case SN_AsSByte:
16261633
case SN_AsSingle:
16271634
case SN_AsUInt16:
@@ -1631,6 +1638,23 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
16311638
return NULL;
16321639
return emit_simd_ins (cfg, klass, OP_XCAST, args [0]->dreg, -1);
16331640
}
1641+
case SN_AsVector:
1642+
case SN_AsVector128:
1643+
case SN_AsVector4: {
1644+
if (!is_element_type_primitive (fsig->ret) || !is_element_type_primitive (fsig->params [0]))
1645+
return NULL;
1646+
1647+
MonoClass *ret_class = mono_class_from_mono_type_internal (fsig->ret);
1648+
int ret_size = mono_class_value_size (ret_class, NULL);
1649+
1650+
MonoClass *arg_class = mono_class_from_mono_type_internal (fsig->params [0]);
1651+
int arg_size = mono_class_value_size (arg_class, NULL);
1652+
1653+
if (arg_size == ret_size)
1654+
return emit_simd_ins (cfg, klass, OP_XCAST, args [0]->dreg, -1);
1655+
1656+
return NULL;
1657+
}
16341658
case SN_Ceiling:
16351659
case SN_Floor: {
16361660
if (!type_enum_is_float (arg0_type))

src/mono/mono/mini/simd-methods.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ METHOD(AsInt32)
7373
METHOD(AsInt64)
7474
METHOD(AsNInt)
7575
METHOD(AsNUInt)
76+
METHOD(AsPlane)
77+
METHOD(AsQuaternion)
7678
METHOD(AsSByte)
7779
METHOD(AsSingle)
7880
METHOD(AsUInt16)
7981
METHOD(AsUInt32)
8082
METHOD(AsUInt64)
83+
METHOD(AsVector)
8184
METHOD(AsVector128)
8285
METHOD(AsVector2)
8386
METHOD(AsVector256)

0 commit comments

Comments
 (0)