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

Add support for other same size vector bitcasts to Mono #104309

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mono/mono/mini/interp/simd-methods.def
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ SIMD_METHOD(AsInt32)
SIMD_METHOD(AsInt64)
SIMD_METHOD(AsNInt)
SIMD_METHOD(AsNUInt)
SIMD_METHOD(AsPlane)
SIMD_METHOD(AsQuaternion)
SIMD_METHOD(AsSByte)
SIMD_METHOD(AsSingle)
SIMD_METHOD(AsUInt16)
SIMD_METHOD(AsUInt32)
SIMD_METHOD(AsUInt64)
SIMD_METHOD(AsVector)
SIMD_METHOD(AsVector4)
SIMD_METHOD(AsVector128)
SIMD_METHOD(ConditionalSelect)
SIMD_METHOD(Create)
SIMD_METHOD(CreateScalar)
Expand Down
34 changes: 33 additions & 1 deletion src/mono/mono/mini/interp/transform-simd.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ static guint16 sri_vector128_methods [] = {
SN_AsInt64,
SN_AsNInt,
SN_AsNUInt,
SN_AsPlane,
SN_AsQuaternion,
SN_AsSByte,
SN_AsSingle,
SN_AsUInt16,
SN_AsUInt32,
SN_AsUInt64,
SN_AsVector,
SN_AsVector4,
SN_AsVector128,
SN_ConditionalSelect,
SN_Create,
SN_CreateScalar,
Expand Down Expand Up @@ -424,7 +429,13 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
gint16 simd_opcode = -1;
gint16 simd_intrins = -1;

vector_klass = mono_class_from_mono_type_internal (csignature->ret);
if (csignature->ret->type == MONO_TYPE_GENERICINST) {
kg marked this conversation as resolved.
Show resolved Hide resolved
vector_klass = mono_class_from_mono_type_internal (csignature->ret);
} else if (csignature->params [0]->type == MONO_TYPE_GENERICINST) {
vector_klass = mono_class_from_mono_type_internal (csignature->params [0]);
} else {
return FALSE;
}

MonoTypeEnum atype;
int arg_size, scalar_arg;
Expand All @@ -444,6 +455,8 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
case SN_AsInt64:
case SN_AsNInt:
case SN_AsNUInt:
case SN_AsPlane:
case SN_AsQuaternion:
case SN_AsSByte:
case SN_AsSingle:
case SN_AsUInt16:
Expand All @@ -455,6 +468,25 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature
simd_intrins = INTERP_SIMD_INTRINSIC_V128_BITCAST;
break;
}
case SN_AsVector:
case SN_AsVector128:
case SN_AsVector4: {
if (!is_element_type_primitive (csignature->ret) || !is_element_type_primitive (csignature->params [0]))
kg marked this conversation as resolved.
Show resolved Hide resolved
return FALSE;

MonoClass *ret_class = mono_class_from_mono_type_internal (csignature->ret);
int ret_size = mono_class_value_size (ret_class, NULL);

MonoClass *arg_class = mono_class_from_mono_type_internal (csignature->params [0]);
int arg_size = mono_class_value_size (arg_class, NULL);

if (arg_size == ret_size) {
kg marked this conversation as resolved.
Show resolved Hide resolved
simd_opcode = MINT_SIMD_INTRINS_P_P;
simd_intrins = INTERP_SIMD_INTRINSIC_V128_BITCAST;
break;
}
return FALSE;
}
case SN_ConditionalSelect:
simd_opcode = MINT_SIMD_INTRINS_P_PPP;
simd_intrins = INTERP_SIMD_INTRINSIC_V128_CONDITIONAL_SELECT;
Expand Down
24 changes: 24 additions & 0 deletions src/mono/mono/mini/simd-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,11 +1187,16 @@ static guint16 sri_vector_methods [] = {
SN_AsInt64,
SN_AsNInt,
SN_AsNUInt,
SN_AsPlane,
SN_AsQuaternion,
SN_AsSByte,
SN_AsSingle,
SN_AsUInt16,
SN_AsUInt32,
SN_AsUInt64,
SN_AsVector,
SN_AsVector128,
SN_AsVector4,
SN_BitwiseAnd,
SN_BitwiseOr,
SN_Ceiling,
Expand Down Expand Up @@ -1622,6 +1627,8 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
case SN_AsInt64:
case SN_AsNInt:
case SN_AsNUInt:
case SN_AsPlane:
case SN_AsQuaternion:
case SN_AsSByte:
case SN_AsSingle:
case SN_AsUInt16:
Expand All @@ -1631,6 +1638,23 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
return NULL;
return emit_simd_ins (cfg, klass, OP_XCAST, args [0]->dreg, -1);
}
case SN_AsVector:
case SN_AsVector128:
case SN_AsVector4: {
if (!is_element_type_primitive (fsig->ret) || !is_element_type_primitive (fsig->params [0]))
return NULL;

MonoClass *ret_class = mono_class_from_mono_type_internal (fsig->ret);
int ret_size = mono_class_value_size (ret_class, NULL);

MonoClass *arg_class = mono_class_from_mono_type_internal (fsig->params [0]);
int arg_size = mono_class_value_size (arg_class, NULL);

if (arg_size == ret_size)
return emit_simd_ins (cfg, klass, OP_XCAST, args [0]->dreg, -1);

return NULL;
}
case SN_Ceiling:
case SN_Floor: {
if (!type_enum_is_float (arg0_type))
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/mini/simd-methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ METHOD(AsInt32)
METHOD(AsInt64)
METHOD(AsNInt)
METHOD(AsNUInt)
METHOD(AsPlane)
METHOD(AsQuaternion)
METHOD(AsSByte)
METHOD(AsSingle)
METHOD(AsUInt16)
METHOD(AsUInt32)
METHOD(AsUInt64)
METHOD(AsVector)
METHOD(AsVector128)
METHOD(AsVector2)
METHOD(AsVector256)
Expand Down
Loading