Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Fix Vector<T>.IsSupported intrinsic #90023

Merged
merged 7 commits into from
Aug 14, 2023
Merged
48 changes: 5 additions & 43 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,58 +2141,20 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
!strcmp ("System", cmethod_klass_name_space) &&
!strcmp ("ThrowHelper", cmethod_klass_name)) {

if (!strcmp ("ThrowForUnsupportedNumericsVectorBaseType", cmethod->name)) {
if (!strcmp ("ThrowForUnsupportedNumericsVectorBaseType", cmethod->name) ||
!strcmp ("ThrowForUnsupportedIntrinsicsVector64BaseType", cmethod->name) ||
!strcmp ("ThrowForUnsupportedIntrinsicsVector128BaseType", cmethod->name) ||
!strcmp ("ThrowForUnsupportedIntrinsicsVector256BaseType", cmethod->name)) {
/* The mono JIT can't optimize the body of this method away */
MonoGenericContext *ctx = mono_method_get_context (cmethod);
g_assert (ctx);
g_assert (ctx->method_inst);

MonoType *t = ctx->method_inst->type_argv [0];
switch (t->type) {
case MONO_TYPE_I1:
case MONO_TYPE_U1:
case MONO_TYPE_I2:
case MONO_TYPE_U2:
case MONO_TYPE_I4:
case MONO_TYPE_U4:
case MONO_TYPE_I8:
case MONO_TYPE_U8:
case MONO_TYPE_R4:
case MONO_TYPE_R8:
case MONO_TYPE_I:
case MONO_TYPE_U:
MONO_INST_NEW (cfg, ins, OP_NOP);
MONO_ADD_INS (cfg->cbb, ins);
return ins;
default:
break;
}
}
else if (!strcmp ("ThrowForUnsupportedIntrinsicsVector64BaseType", cmethod->name) ||
!strcmp ("ThrowForUnsupportedIntrinsicsVector128BaseType", cmethod->name) ||
!strcmp ("ThrowForUnsupportedIntrinsicsVector256BaseType", cmethod->name)) {
/* The mono JIT can't optimize the body of this method away */
MonoGenericContext *ctx = mono_method_get_context (cmethod);
g_assert (ctx);
g_assert (ctx->method_inst);

MonoType *t = ctx->method_inst->type_argv [0];
switch (t->type) {
case MONO_TYPE_I1:
case MONO_TYPE_U1:
case MONO_TYPE_I2:
case MONO_TYPE_U2:
case MONO_TYPE_I4:
case MONO_TYPE_U4:
case MONO_TYPE_I8:
case MONO_TYPE_U8:
case MONO_TYPE_R4:
case MONO_TYPE_R8:
if (MONO_TYPE_IS_VECTOR_PRIMITIVE (t)) {
MONO_INST_NEW (cfg, ins, OP_NOP);
MONO_ADD_INS (cfg->cbb, ins);
return ins;
default:
break;
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions src/mono/mono/mini/simd-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2346,11 +2346,19 @@ emit_vector64_vector128_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign

MonoClass *klass = cmethod->klass;
MonoType *etype = mono_class_get_context (klass)->class_inst->type_argv [0];
gboolean supported = TRUE;
gboolean is_primitive_element_type = MONO_TYPE_IS_VECTOR_PRIMITIVE (etype);

if (!MONO_TYPE_IS_VECTOR_PRIMITIVE (etype))
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
// special case SN_get_IsSupported intrinsic which verifies whether a type parameter T is supported for a generic vector
if (id == SN_get_IsSupported) {
MonoInst *ins = NULL;
EMIT_NEW_ICONST (cfg, ins, is_primitive_element_type ? 1 : 0);
return ins;
}

if (!is_primitive_element_type)
return NULL;

gboolean supported = TRUE;
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
int size = mono_class_value_size (klass, NULL);
int esize = mono_class_value_size (mono_class_from_mono_type_internal (etype), NULL);
g_assert (size > 0);
Expand Down Expand Up @@ -2383,16 +2391,6 @@ emit_vector64_vector128_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
#endif
#endif

switch (id) {
case SN_get_IsSupported: {
MonoInst *ins = NULL;
EMIT_NEW_ICONST (cfg, ins, supported ? 1 : 0);
return ins;
}
default:
break;
}

if (!supported)
return NULL;

Expand Down