From 55f59b5af02fbf9bcb7965c15a142c2cf8d5aca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 15 Mar 2024 08:44:00 +0100 Subject: [PATCH] Fix x86 hardware intrinsics --- .../Common/Compiler/HardwareIntrinsicHelpers.cs | 17 ++++++++++++++++- .../Common/Compiler/InstructionSetSupport.cs | 2 -- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs b/src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs index c30736fcb6019..5cdd1a9fd2a93 100644 --- a/src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs +++ b/src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs @@ -16,7 +16,22 @@ public static partial class HardwareIntrinsicHelpers /// 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) diff --git a/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs b/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs index f476b972b8046..a1725f3db9d92 100644 --- a/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs +++ b/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs @@ -80,8 +80,6 @@ public static string GetHardwareIntrinsicId(TargetArchitecture architecture, Typ } else if (architecture == TargetArchitecture.X86) { - if (potentialType.Name == "X64") - potentialType = (MetadataType)potentialType.ContainingType; if (potentialType.Name == "VL") potentialType = (MetadataType)potentialType.ContainingType; if (potentialType.Namespace != "System.Runtime.Intrinsics.X86")