Skip to content
9 changes: 4 additions & 5 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10638,17 +10638,16 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)

if (isVectorT || (strcmp(className, "Vector") == 0))
{
if (strncmp(methodName,
"System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector",
70) == 0)
if (strncmp(methodName, "System.Runtime.Intrinsics.ISimdVector<System.Numerics.Vector",
60) == 0)
{
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where
// possible but, they all prefix the qualified name of the interface first, so we'll
// check for that and skip the prefix before trying to resolve the method.

if (strncmp(methodName + 70, "<T>,T>.", 7) == 0)
if (strncmp(methodName + 60, "<T>,T>.", 7) == 0)
{
methodName += 77;
methodName += 67;
}
}

Expand Down
41 changes: 25 additions & 16 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4421,29 +4421,38 @@ private bool notifyInstructionSetUsage(InstructionSet instructionSet, bool suppo
}
else
{
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.
ReadOnlySpan<char> methodName = MethodBeingCompiled.Name.AsSpan();

if (methodName.StartsWith("System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector"))
if (methodName.StartsWith("System.Runtime.Intrinsics.ISimdVector<System."))
{
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.
ReadOnlySpan<char> partialMethodName = methodName.Slice(45);

ReadOnlySpan<char> partialMethodName = methodName.Slice(70);

if (partialMethodName.StartsWith("<T>,T>."))
{
methodName = partialMethodName.Slice(7);
}
else if (partialMethodName.StartsWith("64<T>,T>."))
if (partialMethodName.StartsWith("Numerics.Vector"))
{
methodName = partialMethodName.Slice(9);
partialMethodName = partialMethodName.Slice(15);

if (partialMethodName.StartsWith("<T>,T>."))
{
methodName = partialMethodName.Slice(7);
}
}
else if (partialMethodName.StartsWith("128<T>,T>.") ||
partialMethodName.StartsWith("256<T>,T>.") ||
partialMethodName.StartsWith("512<T>,T>."))
if (partialMethodName.StartsWith("Runtime.Intrinsics.Vector"))
{
methodName = partialMethodName.Slice(10);
partialMethodName = partialMethodName.Slice(25);

if (partialMethodName.StartsWith("64<T>,T>."))
{
methodName = partialMethodName.Slice(9);
}
else if (partialMethodName.StartsWith("128<T>,T>.") ||
partialMethodName.StartsWith("256<T>,T>.") ||
partialMethodName.StartsWith("512<T>,T>."))
{
methodName = partialMethodName.Slice(10);
}
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/mono/mono/mini/interp/transform-simd.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,20 +679,25 @@ static gboolean
emit_sn_vector_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignature *csignature, gboolean newobj)
{
const char *cmethod_name = cmethod->name;
bool explicitly_implemented = false;

if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector", 70) == 0) {
if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.Numerics.Vector<T>,T>.", 67) == 0) {
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.

if (strncmp(cmethod_name + 70, "<T>,T>.", 7) == 0) {
cmethod_name += 77;
}
cmethod_name += 67;
explicitly_implemented = true;
}

int id = lookup_intrins (sn_vector_t_methods, sizeof (sn_vector_t_methods), cmethod_name);
if (id == -1)
return FALSE;
if (id == -1) {
if (explicitly_implemented) {
return emit_sri_vector128 (td, cmethod, csignature);
} else {
return FALSE;
}
}

gint16 simd_opcode = -1;
gint16 simd_intrins = -1;
Expand Down
28 changes: 15 additions & 13 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2396,19 +2396,21 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
!strncmp ("System.Runtime.Intrinsics", cmethod_klass_name_space, 25))) {
const char* cmethod_name = cmethod->name;

if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector", 70) == 0) {
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.

if (strncmp(cmethod_name + 70, "<T>,T>.", 7) == 0) {
cmethod_name += 77;
} else if (strncmp(cmethod_name + 70, "64<T>,T>.", 9) == 0) {
cmethod_name += 79;
} else if ((strncmp(cmethod_name + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "512<T>,T>.", 10) == 0)) {
cmethod_name += 80;
if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.", 45) == 0) {
if (strncmp(cmethod_name + 45, "Runtime.Intrinsics.Vector", 25) == 0) {
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.

if (strncmp(cmethod_name + 70, "64<T>,T>.", 9) == 0) {
cmethod_name += 79;
} else if ((strncmp(cmethod_name + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "512<T>,T>.", 10) == 0)) {
cmethod_name += 80;
}
} else if (strncmp(cmethod_name + 45, "Numerics.Vector<T>,T>.", 22) == 0) {
cmethod_name += 67;
}
}

Expand Down
54 changes: 29 additions & 25 deletions src/mono/mono/mini/simd-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,19 +1906,21 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
{
const char *cmethod_name = cmethod->name;

if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector", 70) == 0) {
if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.", 45) == 0) {
if (strncmp (cmethod_name + 45, "Runtime.Intrinsics.Vector", 25) == 0) {
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.

if (strncmp(cmethod_name + 70, "<T>,T>.", 7) == 0) {
cmethod_name += 77;
} else if (strncmp(cmethod_name + 70, "64<T>,T>.", 9) == 0) {
cmethod_name += 79;
} else if ((strncmp(cmethod_name + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "512<T>,T>.", 10) == 0)) {
cmethod_name += 80;
if (strncmp(cmethod_name + 70, "64<T>,T>.", 9) == 0) {
cmethod_name += 79;
} else if ((strncmp(cmethod_name + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "512<T>,T>.", 10) == 0)) {
cmethod_name += 80;
}
} else if (strncmp(cmethod_name + 45, "Numerics.Vector<T>,T>.", 22) == 0) {
cmethod_name += 67;
}
}

Expand Down Expand Up @@ -2437,7 +2439,7 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi

const char *klass_name = m_class_get_name (klass);

if (!strcmp (klass_name, "Vector4")) {
if (strcmp (m_class_get_name_space (klass), "System.Runtime.Intrinsics") != 0) {
klass_name = "Vector128`1";
}
arg_class = create_class_instance ("System.Runtime.Intrinsics", klass_name, m_class_get_byval_arg (cast_class));
Expand Down Expand Up @@ -3371,21 +3373,23 @@ emit_sri_vector_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
const char *cmethod_name = cmethod->name;
bool explicitly_implemented = false;

if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector", 70) == 0) {
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.

if (strncmp(cmethod_name + 70, "<T>,T>.", 7) == 0) {
cmethod_name += 77;
explicitly_implemented = true;
} else if (strncmp(cmethod_name + 70, "64<T>,T>.", 9) == 0) {
cmethod_name += 79;
explicitly_implemented = true;
} else if ((strncmp(cmethod_name + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "512<T>,T>.", 10) == 0)) {
cmethod_name += 80;
if (strncmp(cmethod_name, "System.Runtime.Intrinsics.ISimdVector<System.", 45) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we duplicate this code block 3 times, maybe put it into some shared function?

if (strncmp(cmethod_name + 45, "Runtime.Intrinsics.Vector", 25) == 0) {
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
// but, they all prefix the qualified name of the interface first, so we'll check for that and
// skip the prefix before trying to resolve the method.

if (strncmp(cmethod_name + 70, "64<T>,T>.", 9) == 0) {
cmethod_name += 79;
explicitly_implemented = true;
} else if ((strncmp(cmethod_name + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(cmethod_name + 70, "512<T>,T>.", 10) == 0)) {
cmethod_name += 80;
explicitly_implemented = true;
}
} else if (strncmp(cmethod_name + 45, "Numerics.Vector<T>,T>.", 22) == 0) {
cmethod_name += 67;
explicitly_implemented = true;
}
}
Expand Down
Loading