Skip to content

Commit 536a28e

Browse files
nietrasadamsitnik
andauthored
Add HardwareIntrinsics AVX-512 info (#2412)
Co-authored-by: Adam Sitnik <[email protected]>
1 parent 630622b commit 536a28e

File tree

4 files changed

+78
-6
lines changed

4 files changed

+78
-6
lines changed

src/BenchmarkDotNet/BenchmarkDotNet.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
44
<AssemblyTitle>BenchmarkDotNet</AssemblyTitle>
5-
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<NoWarn>$(NoWarn);1701;1702;1705;1591;3005;NU1702;CS3001;CS3003</NoWarn>
88
<AssemblyName>BenchmarkDotNet</AssemblyName>

src/BenchmarkDotNet/Portability/Cpu/HardwareIntrinsics.cs

+68-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Numerics;
45
using BenchmarkDotNet.Environments;
5-
using System.Diagnostics.CodeAnalysis;
6+
using System.Text;
7+
68
#if NET6_0_OR_GREATER
79
using System.Runtime.Intrinsics.X86;
810
using System.Runtime.Intrinsics.Arm;
@@ -16,6 +18,8 @@ internal static class HardwareIntrinsics
1618

1719
internal static string GetShortInfo()
1820
{
21+
if (IsX86Avx512FSupported)
22+
return GetShortAvx512Representation();
1923
if (IsX86Avx2Supported)
2024
return "AVX2";
2125
else if (IsX86AvxSupported)
@@ -52,7 +56,9 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
5256
{
5357
case Platform.X86:
5458
case Platform.X64:
55-
if (IsX86Avx2Supported) yield return "AVX2";
59+
60+
if (IsX86Avx512FSupported) yield return GetShortAvx512Representation();
61+
else if (IsX86Avx2Supported) yield return "AVX2";
5662
else if (IsX86AvxSupported) yield return "AVX";
5763
else if (IsX86Sse42Supported) yield return "SSE4.2";
5864
else if (IsX86Sse41Supported) yield return "SSE4.1";
@@ -90,6 +96,18 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
9096
}
9197
}
9298

99+
private static string GetShortAvx512Representation()
100+
{
101+
StringBuilder avx512 = new ("AVX-512F");
102+
if (IsX86Avx512CDSupported) avx512.Append("+CD");
103+
if (IsX86Avx512BWSupported) avx512.Append("+BW");
104+
if (IsX86Avx512DQSupported) avx512.Append("+DQ");
105+
if (IsX86Avx512FVLSupported) avx512.Append("+VL");
106+
if (IsX86Avx512VbmiSupported) avx512.Append("+VBMI");
107+
108+
return avx512.ToString();
109+
}
110+
93111
internal static bool IsX86BaseSupported =>
94112
#if NET6_0_OR_GREATER
95113
X86Base.IsSupported;
@@ -153,6 +171,48 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
153171
GetIsSupported("System.Runtime.Intrinsics.X86.Avx2");
154172
#endif
155173

174+
internal static bool IsX86Avx512FSupported =>
175+
#if NET8_0_OR_GREATER
176+
Avx512F.IsSupported;
177+
#else
178+
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512F");
179+
#endif
180+
181+
internal static bool IsX86Avx512FVLSupported =>
182+
#if NET8_0_OR_GREATER
183+
Avx512F.VL.IsSupported;
184+
#else
185+
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512F+VL");
186+
#endif
187+
188+
internal static bool IsX86Avx512BWSupported =>
189+
#if NET8_0_OR_GREATER
190+
Avx512BW.IsSupported;
191+
#else
192+
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512BW");
193+
#endif
194+
195+
internal static bool IsX86Avx512CDSupported =>
196+
#if NET8_0_OR_GREATER
197+
Avx512CD.IsSupported;
198+
#else
199+
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512CD");
200+
#endif
201+
202+
internal static bool IsX86Avx512DQSupported =>
203+
#if NET8_0_OR_GREATER
204+
Avx512DQ.IsSupported;
205+
#else
206+
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512DQ");
207+
#endif
208+
209+
internal static bool IsX86Avx512VbmiSupported =>
210+
#if NET8_0_OR_GREATER
211+
Avx512Vbmi.IsSupported;
212+
#else
213+
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512Vbmi");
214+
#endif
215+
156216
internal static bool IsX86AesSupported =>
157217
#if NET6_0_OR_GREATER
158218
System.Runtime.Intrinsics.X86.Aes.IsSupported;
@@ -211,8 +271,12 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
211271
GetIsSupported("System.Runtime.Intrinsics.X86.AvxVnni");
212272
#endif
213273

214-
// X86Serialize was introduced in .NET 7.0, BDN does not target it so we need to use reflection
215-
internal static bool IsX86SerializeSupported => GetIsSupported("System.Runtime.Intrinsics.X86.X86Serialize");
274+
internal static bool IsX86SerializeSupported =>
275+
#if NET7_0_OR_GREATER
276+
X86Serialize.IsSupported;
277+
#else
278+
GetIsSupported("System.Runtime.Intrinsics.X86.X86Serialize");
279+
#endif
216280

217281
internal static bool IsArmBaseSupported =>
218282
#if NET6_0_OR_GREATER

src/BenchmarkDotNet/Portability/Libc.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace BenchmarkDotNet.Portability
44
{
5+
#pragma warning disable CS8981 // The type name 'libc' only contains lower-cased ascii characters. Such names may become reserved for the language.
56
internal static class libc
7+
#pragma warning restore CS8981
68
{
79
[DllImport(nameof(libc))]
810
internal static extern int getppid();

src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ private string GetILCompilerPackageReference()
161161

162162
private string GetTrimmingSettings()
163163
=> rootAllApplicationAssemblies
164-
? "" // use the defaults
164+
// Use the defaults
165+
? ""
165166
// TrimMode is set in explicit way as for older versions it might have different default value
166167
: "<TrimMode>link</TrimMode><TrimmerDefaultAction>link</TrimmerDefaultAction>";
167168

@@ -248,6 +249,11 @@ private IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
248249
if (HardwareIntrinsics.IsX86Sse42Supported) yield return "sse4.2";
249250
if (HardwareIntrinsics.IsX86AvxSupported) yield return "avx";
250251
if (HardwareIntrinsics.IsX86Avx2Supported) yield return "avx2";
252+
if (HardwareIntrinsics.IsX86Avx512FSupported) yield return "avx-512f";
253+
if (HardwareIntrinsics.IsX86Avx512BWSupported) yield return "avx-512bw";
254+
if (HardwareIntrinsics.IsX86Avx512CDSupported) yield return "avx-512cd";
255+
if (HardwareIntrinsics.IsX86Avx512DQSupported) yield return "avx-512dq";
256+
if (HardwareIntrinsics.IsX86Avx512VbmiSupported) yield return "avx-512vbmi";
251257
if (HardwareIntrinsics.IsX86AesSupported) yield return "aes";
252258
if (HardwareIntrinsics.IsX86Bmi1Supported) yield return "bmi";
253259
if (HardwareIntrinsics.IsX86Bmi2Supported) yield return "bmi2";

0 commit comments

Comments
 (0)