1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Numerics ;
2
4
using BenchmarkDotNet . Environments ;
5
+ using System . Diagnostics . CodeAnalysis ;
3
6
#if NET6_0_OR_GREATER
4
7
using System . Runtime . Intrinsics . X86 ;
5
8
using System . Runtime . Intrinsics . Arm ;
6
- using System . Numerics ;
7
- #elif NETSTANDARD2_0_OR_GREATER
8
- using System ;
9
9
#endif
10
10
11
11
namespace BenchmarkDotNet . Portability . Cpu
12
12
{
13
13
internal static class HardwareIntrinsics
14
14
{
15
- internal static string GetVectorSize ( )
16
- {
17
- #if NET6_0_OR_GREATER
18
- if ( Vector . IsHardwareAccelerated )
19
- return $ "VectorSize={ Vector < byte > . Count * 8 } ";
20
- #endif
21
- return string . Empty ;
22
- }
15
+ internal static string GetVectorSize ( ) => Vector . IsHardwareAccelerated ? $ "VectorSize={ Vector < byte > . Count * 8 } " : string . Empty ;
23
16
24
17
internal static string GetShortInfo ( )
25
18
{
@@ -31,18 +24,22 @@ internal static string GetShortInfo()
31
24
return "SSE4.2" ;
32
25
else if ( IsX86Sse41Supported )
33
26
return "SSE4.1" ;
27
+ else if ( IsX86Ssse3Supported )
28
+ return "SSSE3" ;
34
29
else if ( IsX86Sse3Supported )
35
30
return "SSE3" ;
36
31
else if ( IsX86Sse2Supported )
37
32
return "SSE2" ;
38
33
else if ( IsX86SseSupported )
39
34
return "SSE" ;
35
+ else if ( IsX86BaseSupported )
36
+ return "X86Base" ;
40
37
else if ( IsArmAdvSimdSupported )
41
38
return "AdvSIMD" ;
42
39
else if ( IsArmBaseSupported )
43
- return "base " ;
40
+ return "ArmBase " ;
44
41
else
45
- return string . Empty ;
42
+ return string . Empty ; // Runtimes prior to .NET Core 3.0 (APIs did not exist)
46
43
}
47
44
48
45
internal static string GetFullInfo ( Platform platform )
@@ -59,9 +56,11 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
59
56
else if ( IsX86AvxSupported ) yield return "AVX" ;
60
57
else if ( IsX86Sse42Supported ) yield return "SSE4.2" ;
61
58
else if ( IsX86Sse41Supported ) yield return "SSE4.1" ;
59
+ else if ( IsX86Ssse3Supported ) yield return "SSSE3" ;
62
60
else if ( IsX86Sse3Supported ) yield return "SSE3" ;
63
61
else if ( IsX86Sse2Supported ) yield return "SSE2" ;
64
62
else if ( IsX86SseSupported ) yield return "SSE" ;
63
+ else if ( IsX86BaseSupported ) yield return "X86Base" ;
65
64
66
65
if ( IsX86AesSupported ) yield return "AES" ;
67
66
if ( IsX86Bmi1Supported ) yield return "BMI1" ;
@@ -71,10 +70,12 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
71
70
if ( IsX86PclmulqdqSupported ) yield return "PCLMUL" ;
72
71
if ( IsX86PopcntSupported ) yield return "POPCNT" ;
73
72
if ( IsX86AvxVnniSupported ) yield return "AvxVnni" ;
73
+ if ( IsX86SerializeSupported ) yield return "SERIALIZE" ;
74
74
// TODO: Add MOVBE when API is added.
75
75
break ;
76
76
case Platform . Arm64 :
77
77
if ( IsArmAdvSimdSupported ) yield return "AdvSIMD" ;
78
+ else if ( IsArmBaseSupported ) yield return "ArmBase" ;
78
79
79
80
if ( IsArmAesSupported ) yield return "AES" ;
80
81
if ( IsArmCrc32Supported ) yield return "CRC32" ;
@@ -117,6 +118,13 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
117
118
GetIsSupported ( "System.Runtime.Intrinsics.X86.Sse3" ) ;
118
119
#endif
119
120
121
+ internal static bool IsX86Ssse3Supported =>
122
+ #if NET6_0_OR_GREATER
123
+ Ssse3 . IsSupported ;
124
+ #elif NETSTANDARD
125
+ GetIsSupported ( "System.Runtime.Intrinsics.X86.Ssse3" ) ;
126
+ #endif
127
+
120
128
internal static bool IsX86Sse41Supported =>
121
129
#if NET6_0_OR_GREATER
122
130
Sse41 . IsSupported ;
@@ -203,6 +211,9 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
203
211
GetIsSupported( "System.Runtime.Intrinsics.X86.AvxVnni" ) ;
204
212
#endif
205
213
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" ) ;
216
+
206
217
internal static bool IsArmBaseSupported =>
207
218
#if NET6_0_OR_GREATER
208
219
ArmBase . IsSupported ;
@@ -259,14 +270,12 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
259
270
GetIsSupported ( "System.Runtime.Intrinsics.Arm.Sha256" ) ;
260
271
#endif
261
272
262
- #if NETSTANDARD
263
- private static bool GetIsSupported ( string typeName )
273
+ private static bool GetIsSupported ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties ) ] string typeName )
264
274
{
265
275
Type type = Type . GetType ( typeName ) ;
266
276
if ( type == null ) return false ;
267
277
268
278
return ( bool ) type . GetProperty ( "IsSupported" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Static ) . GetValue ( null , null ) ;
269
279
}
270
- #endif
271
280
}
272
281
}
0 commit comments