From e93b2b1b332fc90da4934025e2edba7d67a15b54 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 14 Nov 2023 10:39:28 +0100 Subject: [PATCH] Use "native" for .NET 8, don't use "serialize" for .NET 7 (#2464) --- .../ConsoleArguments/ConfigParser.cs | 2 +- .../Toolchains/NativeAot/Generator.cs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 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..cc226de337 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,20 @@ 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 (!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) + && runtimeMoniker >= RuntimeMoniker.NativeAot80) + { + yield return "native"; // added in .NET 8 https://github.com/dotnet/runtime/pull/87865 + yield break; + } + switch (platform) { case Platform.X86: @@ -242,7 +256,7 @@ private static IEnumerable GetCurrentProcessInstructionSets(Platform pla 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";