Skip to content

Commit

Permalink
Allow explicitly implemented ISimdVector APIs to be handled as intrin…
Browse files Browse the repository at this point in the history
…sic (#104983)

* Allow explicitly implemented ISimdVector APIs to be handled as intrinsic

* Apply formatting patch
  • Loading branch information
tannergooding authored Aug 1, 2024
1 parent ffacda5 commit ae30cba
Show file tree
Hide file tree
Showing 9 changed files with 509 additions and 28 deletions.
32 changes: 32 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10312,6 +10312,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 @@ -10530,6 +10543,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 @@ -4384,12 +4384,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

0 comments on commit ae30cba

Please sign in to comment.