1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics . CodeAnalysis ;
3
4
using System . Numerics ;
4
5
using BenchmarkDotNet . Environments ;
5
- using System . Diagnostics . CodeAnalysis ;
6
+ using System . Text ;
7
+
6
8
#if NET6_0_OR_GREATER
7
9
using System . Runtime . Intrinsics . X86 ;
8
10
using System . Runtime . Intrinsics . Arm ;
@@ -16,6 +18,8 @@ internal static class HardwareIntrinsics
16
18
17
19
internal static string GetShortInfo ( )
18
20
{
21
+ if ( IsX86Avx512FSupported )
22
+ return GetShortAvx512Representation ( ) ;
19
23
if ( IsX86Avx2Supported )
20
24
return "AVX2" ;
21
25
else if ( IsX86AvxSupported )
@@ -52,7 +56,9 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
52
56
{
53
57
case Platform . X86 :
54
58
case Platform . X64 :
55
- if ( IsX86Avx2Supported ) yield return "AVX2" ;
59
+
60
+ if ( IsX86Avx512FSupported ) yield return GetShortAvx512Representation ( ) ;
61
+ else if ( IsX86Avx2Supported ) yield return "AVX2" ;
56
62
else if ( IsX86AvxSupported ) yield return "AVX" ;
57
63
else if ( IsX86Sse42Supported ) yield return "SSE4.2" ;
58
64
else if ( IsX86Sse41Supported ) yield return "SSE4.1" ;
@@ -90,6 +96,18 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
90
96
}
91
97
}
92
98
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
+
93
111
internal static bool IsX86BaseSupported =>
94
112
#if NET6_0_OR_GREATER
95
113
X86Base . IsSupported ;
@@ -153,6 +171,48 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
153
171
GetIsSupported ( "System.Runtime.Intrinsics.X86.Avx2" ) ;
154
172
#endif
155
173
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
+
156
216
internal static bool IsX86AesSupported =>
157
217
#if NET6_0_OR_GREATER
158
218
System . Runtime . Intrinsics . X86 . Aes . IsSupported ;
@@ -211,8 +271,12 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
211
271
GetIsSupported( "System.Runtime.Intrinsics.X86.AvxVnni" ) ;
212
272
#endif
213
273
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
216
280
217
281
internal static bool IsArmBaseSupported =>
218
282
#if NET6_0_OR_GREATER
0 commit comments