Skip to content

Commit c65d921

Browse files
Update mono-interp to handle the same Vector.As APIs as mono-jit (#104217)
1 parent 7b1c0f3 commit c65d921

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ INTERP_SIMD_INTRINSIC_P_PP (INTERP_SIMD_INTRINSIC_V128_R4_MULTIPLY, interp_v128_
7070

7171
INTERP_SIMD_INTRINSIC_P_PP (INTERP_SIMD_INTRINSIC_V128_R4_DIVISION, interp_v128_r4_op_division, 231)
7272

73+
INTERP_SIMD_INTRINSIC_P_P (INTERP_SIMD_INTRINSIC_V128_BITCAST, interp_v128_bitcast, -1)
74+
7375
INTERP_SIMD_INTRINSIC_P_P (INTERP_SIMD_INTRINSIC_V128_I1_NEGATION, interp_v128_i1_op_negation, 97)
7476
INTERP_SIMD_INTRINSIC_P_P (INTERP_SIMD_INTRINSIC_V128_I2_NEGATION, interp_v128_i2_op_negation, 129)
7577
INTERP_SIMD_INTRINSIC_P_P (INTERP_SIMD_INTRINSIC_V128_I4_NEGATION, interp_v128_i4_op_negation, 161)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ interp_v128_i4_all_bits_set (gpointer res)
2828
memset (res, 0xff, SIZEOF_V128);
2929
}
3030

31+
// Vector128<TTo> As<TFrom, TTo>(Vector128<TFrom> v1)
32+
static void
33+
interp_v128_bitcast (gpointer res, gpointer v1)
34+
{
35+
*(v128_i1*)res = *(v128_i1*)v1;
36+
}
37+
3138
// op_Addition
3239
static void
3340
interp_v128_i1_op_addition (gpointer res, gpointer v1, gpointer v2)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ SIMD_METHOD(op_UnaryNegation)
2323
SIMD_METHOD(op_UnsignedRightShift)
2424

2525
SIMD_METHOD(AndNot)
26+
SIMD_METHOD(As)
27+
SIMD_METHOD(AsByte)
28+
SIMD_METHOD(AsDouble)
29+
SIMD_METHOD(AsInt16)
30+
SIMD_METHOD(AsInt32)
31+
SIMD_METHOD(AsInt64)
32+
SIMD_METHOD(AsNInt)
33+
SIMD_METHOD(AsNUInt)
34+
SIMD_METHOD(AsSByte)
35+
SIMD_METHOD(AsSingle)
36+
SIMD_METHOD(AsUInt16)
37+
SIMD_METHOD(AsUInt32)
38+
SIMD_METHOD(AsUInt64)
2639
SIMD_METHOD(ConditionalSelect)
2740
SIMD_METHOD(Create)
2841
SIMD_METHOD(CreateScalar)

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ lookup_intrins (guint16 *intrinsics, int size, MonoMethod *cmethod)
5656
// i.e. all 'get_' and 'op_' need to come after regular title-case names
5757
static guint16 sri_vector128_methods [] = {
5858
SN_AndNot,
59+
SN_As,
60+
SN_AsByte,
61+
SN_AsDouble,
62+
SN_AsInt16,
63+
SN_AsInt32,
64+
SN_AsInt64,
65+
SN_AsNInt,
66+
SN_AsNUInt,
67+
SN_AsSByte,
68+
SN_AsSingle,
69+
SN_AsUInt16,
70+
SN_AsUInt32,
71+
SN_AsUInt64,
5972
SN_ConditionalSelect,
6073
SN_Create,
6174
SN_CreateScalar,
@@ -310,6 +323,42 @@ get_common_simd_info (MonoClass *vector_klass, MonoMethodSignature *csignature,
310323
return TRUE;
311324
}
312325

326+
static MonoType*
327+
get_vector_t_elem_type (MonoType *vector_type)
328+
{
329+
MonoClass *klass;
330+
MonoType *etype;
331+
332+
g_assert (vector_type->type == MONO_TYPE_GENERICINST);
333+
klass = mono_class_from_mono_type_internal (vector_type);
334+
g_assert (
335+
!strcmp (m_class_get_name (klass), "Vector`1") ||
336+
!strcmp (m_class_get_name (klass), "Vector64`1") ||
337+
!strcmp (m_class_get_name (klass), "Vector128`1") ||
338+
!strcmp (m_class_get_name (klass), "Vector256`1") ||
339+
!strcmp (m_class_get_name (klass), "Vector512`1"));
340+
etype = mono_class_get_context (klass)->class_inst->type_argv [0];
341+
return etype;
342+
}
343+
344+
static gboolean
345+
is_element_type_primitive (MonoType *vector_type)
346+
{
347+
if (vector_type->type == MONO_TYPE_GENERICINST) {
348+
MonoType *element_type = get_vector_t_elem_type (vector_type);
349+
return MONO_TYPE_IS_VECTOR_PRIMITIVE (element_type);
350+
} else {
351+
MonoClass *klass = mono_class_from_mono_type_internal (vector_type);
352+
g_assert (
353+
!strcmp (m_class_get_name (klass), "Plane") ||
354+
!strcmp (m_class_get_name (klass), "Quaternion") ||
355+
!strcmp (m_class_get_name (klass), "Vector2") ||
356+
!strcmp (m_class_get_name (klass), "Vector3") ||
357+
!strcmp (m_class_get_name (klass), "Vector4"));
358+
return TRUE;
359+
}
360+
}
361+
313362
static void
314363
emit_common_simd_epilogue (TransformData *td, MonoClass *vector_klass, MonoMethodSignature *csignature, int vector_size, gboolean allow_void)
315364
{
@@ -387,6 +436,25 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
387436
simd_opcode = MINT_SIMD_INTRINS_P_PP;
388437
simd_intrins = INTERP_SIMD_INTRINSIC_V128_AND_NOT;
389438
break;
439+
case SN_As:
440+
case SN_AsByte:
441+
case SN_AsDouble:
442+
case SN_AsInt16:
443+
case SN_AsInt32:
444+
case SN_AsInt64:
445+
case SN_AsNInt:
446+
case SN_AsNUInt:
447+
case SN_AsSByte:
448+
case SN_AsSingle:
449+
case SN_AsUInt16:
450+
case SN_AsUInt32:
451+
case SN_AsUInt64: {
452+
if (!is_element_type_primitive (csignature->ret) || !is_element_type_primitive (csignature->params [0]))
453+
return FALSE;
454+
simd_opcode = MINT_SIMD_INTRINS_P_P;
455+
simd_intrins = INTERP_SIMD_INTRINSIC_V128_BITCAST;
456+
break;
457+
}
390458
case SN_ConditionalSelect:
391459
simd_opcode = MINT_SIMD_INTRINS_P_PPP;
392460
simd_intrins = INTERP_SIMD_INTRINSIC_V128_CONDITIONAL_SELECT;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,8 @@ static guint16 sri_vector_methods [] = {
11851185
SN_AsInt16,
11861186
SN_AsInt32,
11871187
SN_AsInt64,
1188+
SN_AsNInt,
1189+
SN_AsNUInt,
11881190
SN_AsSByte,
11891191
SN_AsSingle,
11901192
SN_AsUInt16,
@@ -1618,6 +1620,8 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
16181620
case SN_AsInt16:
16191621
case SN_AsInt32:
16201622
case SN_AsInt64:
1623+
case SN_AsNInt:
1624+
case SN_AsNUInt:
16211625
case SN_AsSByte:
16221626
case SN_AsSingle:
16231627
case SN_AsUInt16:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ METHOD(AsDouble)
7171
METHOD(AsInt16)
7272
METHOD(AsInt32)
7373
METHOD(AsInt64)
74+
METHOD(AsNInt)
75+
METHOD(AsNUInt)
7476
METHOD(AsSByte)
7577
METHOD(AsSingle)
7678
METHOD(AsUInt16)

0 commit comments

Comments
 (0)