Skip to content

Commit ae30cba

Browse files
Allow explicitly implemented ISimdVector APIs to be handled as intrinsic (#104983)
* Allow explicitly implemented ISimdVector APIs to be handled as intrinsic * Apply formatting patch
1 parent ffacda5 commit ae30cba

File tree

9 files changed

+509
-28
lines changed

9 files changed

+509
-28
lines changed

src/coreclr/jit/importercalls.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10312,6 +10312,19 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
1031210312
else
1031310313
{
1031410314
#ifdef FEATURE_HW_INTRINSICS
10315+
if (strncmp(methodName,
10316+
"System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector", 70) == 0)
10317+
{
10318+
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where
10319+
// possible but, they all prefix the qualified name of the interface first, so we'll check
10320+
// for that and skip the prefix before trying to resolve the method.
10321+
10322+
if (strncmp(methodName + 70, "<T>,T>.", 7) == 0)
10323+
{
10324+
methodName += 77;
10325+
}
10326+
}
10327+
1031510328
CORINFO_SIG_INFO sig;
1031610329
info.compCompHnd->getMethodSig(method, &sig);
1031710330

@@ -10530,6 +10543,25 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
1053010543
#error Unsupported platform
1053110544
#endif
1053210545

10546+
if (strncmp(methodName,
10547+
"System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector", 70) == 0)
10548+
{
10549+
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where
10550+
// possible but, they all prefix the qualified name of the interface first, so we'll check
10551+
// for that and skip the prefix before trying to resolve the method.
10552+
10553+
if (strncmp(methodName + 70, "64<T>,T>.", 9) == 0)
10554+
{
10555+
methodName += 79;
10556+
}
10557+
else if ((strncmp(methodName + 70, "128<T>,T>.", 10) == 0) ||
10558+
(strncmp(methodName + 70, "256<T>,T>.", 10) == 0) ||
10559+
(strncmp(methodName + 70, "512<T>,T>.", 10) == 0))
10560+
{
10561+
methodName += 80;
10562+
}
10563+
}
10564+
1053310565
if ((namespaceName[0] == '\0') || (strcmp(namespaceName, platformNamespaceName) == 0))
1053410566
{
1053510567
CORINFO_SIG_INFO sig;

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,12 +4384,44 @@ private bool notifyInstructionSetUsage(InstructionSet instructionSet, bool suppo
43844384
// By policy we code review all changes into corelib, such that failing to use an instruction
43854385
// set is not a reason to not support usage of it. Except for functions which check if a given
43864386
// feature is supported or hardware accelerated.
4387-
if (!isMethodDefinedInCoreLib() ||
4388-
MethodBeingCompiled.Name == "get_IsSupported" ||
4389-
MethodBeingCompiled.Name == "get_IsHardwareAccelerated")
4387+
if (!isMethodDefinedInCoreLib())
43904388
{
43914389
_actualInstructionSetUnsupported.AddInstructionSet(instructionSet);
43924390
}
4391+
else
4392+
{
4393+
ReadOnlySpan<char> methodName = MethodBeingCompiled.Name.AsSpan();
4394+
4395+
if (methodName.StartsWith("System.Runtime.Intrinsics.ISimdVector<System.Runtime.Intrinsics.Vector"))
4396+
{
4397+
// We want explicitly implemented ISimdVector<TSelf, T> APIs to still be expanded where possible
4398+
// but, they all prefix the qualified name of the interface first, so we'll check for that and
4399+
// skip the prefix before trying to resolve the method.
4400+
4401+
ReadOnlySpan<char> partialMethodName = methodName.Slice(70);
4402+
4403+
if (partialMethodName.StartsWith("<T>,T>."))
4404+
{
4405+
methodName = partialMethodName.Slice(7);
4406+
}
4407+
else if (partialMethodName.StartsWith("64<T>,T>."))
4408+
{
4409+
methodName = partialMethodName.Slice(9);
4410+
}
4411+
else if (partialMethodName.StartsWith("128<T>,T>.") ||
4412+
partialMethodName.StartsWith("256<T>,T>.") ||
4413+
partialMethodName.StartsWith("512<T>,T>."))
4414+
{
4415+
methodName = partialMethodName.Slice(10);
4416+
}
4417+
}
4418+
4419+
if (methodName.Equals("get_IsSupported", StringComparison.Ordinal) ||
4420+
methodName.Equals("get_IsHardwareAccelerated", StringComparison.Ordinal))
4421+
{
4422+
_actualInstructionSetUnsupported.AddInstructionSet(instructionSet);
4423+
}
4424+
}
43934425
}
43944426
return supportEnabled;
43954427
}

0 commit comments

Comments
 (0)