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

Allow explicitly implemented ISimdVector APIs to be handled as intrinsic #104983

Merged
merged 2 commits into from
Aug 1, 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
32 changes: 32 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10191,6 +10191,19 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
else
{
#ifdef FEATURE_HW_INTRINSICS
if (strncmp(methodName,
"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(methodName + 70, "<T>,T>.", 7) == 0)
{
methodName += 77;
}
}

CORINFO_SIG_INFO sig;
info.compCompHnd->getMethodSig(method, &sig);

Expand Down Expand Up @@ -10409,6 +10422,25 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
#error Unsupported platform
#endif

if (strncmp(methodName,
"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(methodName + 70, "64<T>,T>.", 9) == 0)
{
methodName += 79;
}
else if ((strncmp(methodName + 70, "128<T>,T>.", 10) == 0) ||
(strncmp(methodName + 70, "256<T>,T>.", 10) == 0) ||
(strncmp(methodName + 70, "512<T>,T>.", 10) == 0))
{
methodName += 80;
}
}

if ((namespaceName[0] == '\0') || (strcmp(namespaceName, platformNamespaceName) == 0))
{
CORINFO_SIG_INFO sig;
Expand Down
38 changes: 35 additions & 3 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4349,12 +4349,44 @@ private bool notifyInstructionSetUsage(InstructionSet instructionSet, bool suppo
// By policy we code review all changes into corelib, such that failing to use an instruction
// set is not a reason to not support usage of it. Except for functions which check if a given
// feature is supported or hardware accelerated.
if (!isMethodDefinedInCoreLib() ||
MethodBeingCompiled.Name == "get_IsSupported" ||
MethodBeingCompiled.Name == "get_IsHardwareAccelerated")
if (!isMethodDefinedInCoreLib())
{
_actualInstructionSetUnsupported.AddInstructionSet(instructionSet);
}
else
{
ReadOnlySpan<char> methodName = MethodBeingCompiled.Name.AsSpan();

if (methodName.StartsWith("System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector"))
{
// 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(70);

if (partialMethodName.StartsWith("<T>,T>."))
{
methodName = partialMethodName.Slice(7);
}
else 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);
}
}

if (methodName.Equals("get_IsSupported", StringComparison.Ordinal) ||
methodName.Equals("get_IsHardwareAccelerated", StringComparison.Ordinal))
{
_actualInstructionSetUnsupported.AddInstructionSet(instructionSet);
}
}
}
return supportEnabled;
}
Expand Down
Loading
Loading