11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics . CodeAnalysis ;
34using System . Numerics ;
45using BenchmarkDotNet . Environments ;
5- using System . Diagnostics . CodeAnalysis ;
6+ using System . Text ;
7+
68#if NET6_0_OR_GREATER
79using System . Runtime . Intrinsics . X86 ;
810using 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
0 commit comments