Skip to content

Commit

Permalink
Fix x86 hardware intrinsics (#99894)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Mar 19, 2024
1 parent 8b04e76 commit 6d412f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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;
if (potentialType.Name == "VL")
potentialType = (MetadataType)potentialType.ContainingType;
if (potentialType.Namespace != "System.Runtime.Intrinsics.X86")
Expand Down

0 comments on commit 6d412f4

Please sign in to comment.