Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
address code review feedback
  • Loading branch information
adamsitnik committed Nov 16, 2023
commit c221774d197d5fc337070c8e70d41e0228a417a5
39 changes: 30 additions & 9 deletions src/BenchmarkDotNet/Portability/Cpu/HardwareIntrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using BenchmarkDotNet.Environments;
using System.Text;

#if NET6_0_OR_GREATER
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics.Arm;
Expand All @@ -17,7 +19,7 @@ internal static class HardwareIntrinsics
internal static string GetShortInfo()
{
if (IsX86Avx512FSupported)
return "AVX-512";
return GetShortAvx512Representation();
if (IsX86Avx2Supported)
return "AVX2";
else if (IsX86AvxSupported)
Expand Down Expand Up @@ -54,13 +56,9 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
{
case Platform.X86:
case Platform.X64:
if (IsX86Avx512FSupported) yield return "AVX-512F";
if (IsX86Avx512BWSupported) yield return "AVX-512BW";
if (IsX86Avx512CDSupported) yield return "AVX-512CD";
if (IsX86Avx512DQSupported) yield return "AVX-512DQ";
if (IsX86Avx512VbmiSupported) yield return "AVX-512VBMI";

if (IsX86Avx2Supported) yield return "AVX2";
if (IsX86Avx512FSupported) yield return GetShortAvx512Representation();
else if (IsX86Avx2Supported) yield return "AVX2";
else if (IsX86AvxSupported) yield return "AVX";
else if (IsX86Sse42Supported) yield return "SSE4.2";
else if (IsX86Sse41Supported) yield return "SSE4.1";
Expand Down Expand Up @@ -98,6 +96,18 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
}
}

private static string GetShortAvx512Representation()
{
StringBuilder avx512 = new ("AVX-512F");
if (IsX86Avx512CDSupported) avx512.Append("+CD");
if (IsX86Avx512BWSupported) avx512.Append("+BW");
if (IsX86Avx512DQSupported) avx512.Append("+DQ");
if (IsX86Avx512FVLSupported) avx512.Append("+VL");
if (IsX86Avx512VbmiSupported) avx512.Append("+VBMI");

return avx512.ToString();
}

internal static bool IsX86BaseSupported =>
#if NET6_0_OR_GREATER
X86Base.IsSupported;
Expand Down Expand Up @@ -168,6 +178,13 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512F");
#endif

internal static bool IsX86Avx512FVLSupported =>
#if NET8_0_OR_GREATER
Avx512F.VL.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512F+VL");
#endif

internal static bool IsX86Avx512BWSupported =>
#if NET8_0_OR_GREATER
Avx512BW.IsSupported;
Expand Down Expand Up @@ -254,8 +271,12 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
GetIsSupported("System.Runtime.Intrinsics.X86.AvxVnni");
#endif

// X86Serialize was introduced in .NET 7.0, BDN does not target it so we need to use reflection
internal static bool IsX86SerializeSupported => GetIsSupported("System.Runtime.Intrinsics.X86.X86Serialize");
internal static bool IsX86SerializeSupported =>
#if NET7_0_OR_GREATER
X86Serialize.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.X86Serialize");
#endif

internal static bool IsArmBaseSupported =>
#if NET6_0_OR_GREATER
Expand Down