From 0c912cf699622d462de79f1658516943a36734e8 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 14 Nov 2023 09:42:16 +0100 Subject: [PATCH 1/2] NativeAOT: add support for "native" instruction set --- src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs | 2 +- .../Toolchains/NativeAot/Generator.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs index 0a125900f4..33cb9cc8b2 100644 --- a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs +++ b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs @@ -763,7 +763,7 @@ private static string GetCoreRunToolchainDisplayName(IReadOnlyList pat return coreRunPath.FullName.Substring(lastCommonDirectorySeparatorIndex); } - private static bool TryParse(string runtime, out RuntimeMoniker runtimeMoniker) + internal static bool TryParse(string runtime, out RuntimeMoniker runtimeMoniker) { int index = runtime.IndexOf('-'); diff --git a/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs b/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs index 6fb5e5421f..17b24929e3 100644 --- a/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs +++ b/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs @@ -3,8 +3,10 @@ using System.IO; using System.Linq; using System.Text; +using BenchmarkDotNet.ConsoleArguments; using BenchmarkDotNet.Environments; using BenchmarkDotNet.Extensions; +using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Loggers; using BenchmarkDotNet.Portability; using BenchmarkDotNet.Portability.Cpu; @@ -219,8 +221,16 @@ private string GetCurrentInstructionSet(Platform platform) => string.Join(",", GetCurrentProcessInstructionSets(platform)); // based on https://github.com/dotnet/runtime/blob/ce61c09a5f6fc71d8f717d3fc4562f42171869a0/src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs#L727 - private static IEnumerable GetCurrentProcessInstructionSets(Platform platform) + private IEnumerable GetCurrentProcessInstructionSets(Platform platform) { + if (platform == RuntimeInformation.GetCurrentPlatform() // "native" does not support cross-compilation (so does BDN for now) + && ConfigParser.TryParse(TargetFrameworkMoniker, out RuntimeMoniker runtimeMoniker) + && runtimeMoniker >= RuntimeMoniker.NativeAot80) + { + yield return "native"; // added in .NET 8 https://github.com/dotnet/runtime/pull/87865 + yield break; + } + switch (platform) { case Platform.X86: From a1108505cf68ff15417d8bb24b547105fe38214f Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 14 Nov 2023 09:45:37 +0100 Subject: [PATCH 2/2] don't use unsupported "serialize" for Native AOT before .NET 8 --- src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs b/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs index 17b24929e3..cc226de337 100644 --- a/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs +++ b/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs @@ -223,8 +223,12 @@ private string GetCurrentInstructionSet(Platform platform) // based on https://github.com/dotnet/runtime/blob/ce61c09a5f6fc71d8f717d3fc4562f42171869a0/src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs#L727 private IEnumerable GetCurrentProcessInstructionSets(Platform platform) { + if (!ConfigParser.TryParse(TargetFrameworkMoniker, out RuntimeMoniker runtimeMoniker)) + { + throw new NotSupportedException($"Invalid TFM: '{TargetFrameworkMoniker}'"); + } + if (platform == RuntimeInformation.GetCurrentPlatform() // "native" does not support cross-compilation (so does BDN for now) - && ConfigParser.TryParse(TargetFrameworkMoniker, out RuntimeMoniker runtimeMoniker) && runtimeMoniker >= RuntimeMoniker.NativeAot80) { yield return "native"; // added in .NET 8 https://github.com/dotnet/runtime/pull/87865 @@ -252,7 +256,7 @@ private IEnumerable GetCurrentProcessInstructionSets(Platform platform) if (HardwareIntrinsics.IsX86PclmulqdqSupported) yield return "pclmul"; if (HardwareIntrinsics.IsX86PopcntSupported) yield return "popcnt"; if (HardwareIntrinsics.IsX86AvxVnniSupported) yield return "avxvnni"; - if (HardwareIntrinsics.IsX86SerializeSupported) yield return "serialize"; + if (HardwareIntrinsics.IsX86SerializeSupported && runtimeMoniker > RuntimeMoniker.NativeAot70) yield return "serialize"; // https://github.com/dotnet/BenchmarkDotNet/issues/2463#issuecomment-1809625008 break; case Platform.Arm64: if (HardwareIntrinsics.IsArmBaseSupported) yield return "base";