2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
#include " common.h"
5
-
6
- #ifdef TARGET_WINDOWS
7
- #include < intrin.h>
8
- #include < windows.h>
9
- #endif
10
-
11
5
#include " do_vxsort.h"
12
6
7
+ #include < minipal/cpufeatures.h>
8
+
13
9
enum class SupportedISA
14
10
{
15
11
None = 0 ,
16
12
AVX2 = 1 << (int )InstructionSet::AVX2,
17
13
AVX512F = 1 << (int )InstructionSet::AVX512F
18
14
};
19
15
20
- #if defined(TARGET_AMD64) && defined(TARGET_WINDOWS)
21
-
22
- SupportedISA DetermineSupportedISA ()
23
- {
24
- // register definitions to make the following code more readable
25
- enum reg
26
- {
27
- EAX = 0 ,
28
- EBX = 1 ,
29
- ECX = 2 ,
30
- EDX = 3 ,
31
- COUNT = 4
32
- };
33
-
34
- // bit definitions to make code more readable
35
- enum bits
36
- {
37
- OCXSAVE = 1 <<27 ,
38
- AVX = 1 <<28 ,
39
- AVX2 = 1 << 5 ,
40
- AVX512F = 1 <<16 ,
41
- AVX512DQ = 1 <<17 ,
42
- };
43
- int reg[COUNT];
44
-
45
- __cpuid (reg, 0 );
46
- if (reg[EAX] < 7 )
47
- return SupportedISA::None;
48
-
49
- __cpuid (reg, 1 );
50
-
51
- // both AVX and OCXSAVE feature flags must be enabled
52
- if ((reg[ECX] & (OCXSAVE|AVX)) != (OCXSAVE | AVX))
53
- return SupportedISA::None;
54
-
55
- // get xcr0 register
56
- DWORD64 xcr0 = _xgetbv (0 );
57
-
58
- // get OS XState info
59
- DWORD64 FeatureMask = GetEnabledXStateFeatures ();
60
-
61
- // get processor extended feature flag info
62
- __cpuidex (reg, 7 , 0 );
63
-
64
- // check if all of AVX2, AVX512F and AVX512DQ are supported by both processor and OS
65
- if ((reg[EBX] & (AVX2 | AVX512F | AVX512DQ)) == (AVX2 | AVX512F | AVX512DQ) &&
66
- (xcr0 & 0xe6 ) == 0xe6 &&
67
- (FeatureMask & (XSTATE_MASK_AVX | XSTATE_MASK_AVX512)) == (XSTATE_MASK_AVX | XSTATE_MASK_AVX512))
68
- {
69
- return (SupportedISA)((int )SupportedISA::AVX2 | (int )SupportedISA::AVX512F);
70
- }
71
-
72
- // check if AVX2 is supported by both processor and OS
73
- if ((reg[EBX] & AVX2) &&
74
- (xcr0 & 0x06 ) == 0x06 &&
75
- (FeatureMask & XSTATE_MASK_AVX) == XSTATE_MASK_AVX)
76
- {
77
- return SupportedISA::AVX2;
78
- }
79
-
80
- return SupportedISA::None;
81
- }
82
-
83
- #elif defined(TARGET_UNIX)
84
-
85
16
SupportedISA DetermineSupportedISA ()
86
17
{
87
- __builtin_cpu_init ();
88
- if (__builtin_cpu_supports ( " avx2 " ) )
18
+ int cpuFeatures = minipal_getcpufeatures ();
19
+ if ((cpuFeatures & XArchIntrinsicConstants_Avx2) != 0 )
89
20
{
90
- if (__builtin_cpu_supports ( " avx512f " ) )
21
+ if ((cpuFeatures & XArchIntrinsicConstants_Avx512) != 0 )
91
22
return (SupportedISA)((int )SupportedISA::AVX2 | (int )SupportedISA::AVX512F);
92
23
else
93
24
return SupportedISA::AVX2;
@@ -98,8 +29,6 @@ SupportedISA DetermineSupportedISA()
98
29
}
99
30
}
100
31
101
- #endif // defined(TARGET_UNIX)
102
-
103
32
static bool s_initialized;
104
33
static SupportedISA s_supportedISA;
105
34
0 commit comments