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

Fix x86 hardware intrinsics #99894

Merged
merged 1 commit into from
Mar 19, 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
17 changes: 16 additions & 1 deletion src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@ public static partial class HardwareIntrinsicHelpers
/// </summary>
public static bool IsHardwareIntrinsic(MethodDesc method)
{
return !string.IsNullOrEmpty(InstructionSetSupport.GetHardwareIntrinsicId(method.Context.Target.Architecture, method.OwningType));
// Matches logic in
// https://github.com/dotnet/runtime/blob/5c40bb5636b939fb548492fdeb9d501b599ac5f5/src/coreclr/vm/methodtablebuilder.cpp#L1491-L1512
TypeDesc owningType = method.OwningType;
if (owningType.IsIntrinsic && !owningType.HasInstantiation)
{
var owningMdType = (MetadataType)owningType;
string ns = owningMdType.ContainingType?.Namespace ?? owningMdType.Namespace;
return method.Context.Target.Architecture switch
{
TargetArchitecture.ARM64 => ns == "System.Runtime.Intrinsics.Arm",
TargetArchitecture.X64 or TargetArchitecture.X86 => ns == "System.Runtime.Intrinsics.X86",
_ => false,
};
}

return false;
}

public static void AddRuntimeRequiredIsaFlagsToBuilder(InstructionSetSupportBuilder builder, int flags)
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public static string GetHardwareIntrinsicId(TargetArchitecture architecture, Typ
}
else if (architecture == TargetArchitecture.X86)
{
if (potentialType.Name == "X64")
potentialType = (MetadataType)potentialType.ContainingType;
Comment on lines -83 to -84
Copy link
Member

Choose a reason for hiding this comment

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

Is this "correct"? Should we not just return "" instead to simplify things and ensure that potentialType.Name isn't returned (in this case "X64")?

Copy link
Member Author

Choose a reason for hiding this comment

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

If this is the X64 nested type, we'll take the exit on line 86 and return an empty string. Nested types don't set a namespace so (potentialType.Namespace != "System.Runtime.Intrinsics.X86") is true.

if (potentialType.Name == "VL")
potentialType = (MetadataType)potentialType.ContainingType;
if (potentialType.Namespace != "System.Runtime.Intrinsics.X86")
Expand Down