25
25
#include " stressLog.h"
26
26
#include " RestrictedCallouts.h"
27
27
#include " yieldprocessornormalized.h"
28
+ #include < minipal/cpufeatures.h>
28
29
29
30
#ifdef FEATURE_PERFTRACING
30
31
#include " EventPipeInterface.h"
@@ -48,9 +49,6 @@ static bool DetectCPUFeatures();
48
49
49
50
extern RhConfig * g_pRhConfig;
50
51
51
- EXTERN_C bool g_fHasFastFxsave;
52
- bool g_fHasFastFxsave = false ;
53
-
54
52
CrstStatic g_ThunkPoolLock;
55
53
56
54
#if defined(HOST_X86) || defined(HOST_AMD64) || defined(HOST_ARM64)
@@ -183,203 +181,7 @@ static bool InitDLL(HANDLE hPalInstance)
183
181
bool DetectCPUFeatures ()
184
182
{
185
183
#if defined(HOST_X86) || defined(HOST_AMD64) || defined(HOST_ARM64)
186
-
187
- #if defined(HOST_X86) || defined(HOST_AMD64)
188
-
189
- int cpuidInfo[4 ];
190
-
191
- const int CPUID_EAX = 0 ;
192
- const int CPUID_EBX = 1 ;
193
- const int CPUID_ECX = 2 ;
194
- const int CPUID_EDX = 3 ;
195
-
196
- __cpuid (cpuidInfo, 0x00000000 );
197
- uint32_t maxCpuId = static_cast <uint32_t >(cpuidInfo[CPUID_EAX]);
198
-
199
- if (maxCpuId >= 1 )
200
- {
201
- __cpuid (cpuidInfo, 0x00000001 );
202
-
203
- const int requiredBaselineEdxFlags = (1 << 25 ) // SSE
204
- | (1 << 26 ); // SSE2
205
-
206
- if ((cpuidInfo[CPUID_EDX] & requiredBaselineEdxFlags) == requiredBaselineEdxFlags)
207
- {
208
- g_cpuFeatures |= XArchIntrinsicConstants_VectorT128;
209
-
210
- if ((cpuidInfo[CPUID_ECX] & (1 << 25 )) != 0 ) // AESNI
211
- {
212
- g_cpuFeatures |= XArchIntrinsicConstants_Aes;
213
- }
214
-
215
- if ((cpuidInfo[CPUID_ECX] & (1 << 1 )) != 0 ) // PCLMULQDQ
216
- {
217
- g_cpuFeatures |= XArchIntrinsicConstants_Pclmulqdq;
218
- }
219
-
220
- if ((cpuidInfo[CPUID_ECX] & (1 << 0 )) != 0 ) // SSE3
221
- {
222
- g_cpuFeatures |= XArchIntrinsicConstants_Sse3;
223
-
224
- if ((cpuidInfo[CPUID_ECX] & (1 << 9 )) != 0 ) // SSSE3
225
- {
226
- g_cpuFeatures |= XArchIntrinsicConstants_Ssse3;
227
-
228
- if ((cpuidInfo[CPUID_ECX] & (1 << 19 )) != 0 ) // SSE4.1
229
- {
230
- g_cpuFeatures |= XArchIntrinsicConstants_Sse41;
231
-
232
- if ((cpuidInfo[CPUID_ECX] & (1 << 20 )) != 0 ) // SSE4.2
233
- {
234
- g_cpuFeatures |= XArchIntrinsicConstants_Sse42;
235
-
236
- if ((cpuidInfo[CPUID_ECX] & (1 << 22 )) != 0 ) // MOVBE
237
- {
238
- g_cpuFeatures |= XArchIntrinsicConstants_Movbe;
239
- }
240
-
241
- if ((cpuidInfo[CPUID_ECX] & (1 << 23 )) != 0 ) // POPCNT
242
- {
243
- g_cpuFeatures |= XArchIntrinsicConstants_Popcnt;
244
- }
245
-
246
- const int requiredAvxEcxFlags = (1 << 27 ) // OSXSAVE
247
- | (1 << 28 ); // AVX
248
-
249
- if ((cpuidInfo[CPUID_ECX] & requiredAvxEcxFlags) == requiredAvxEcxFlags)
250
- {
251
- if (PalIsAvxEnabled () && (xmmYmmStateSupport () == 1 )) // XGETBV == 11
252
- {
253
- g_cpuFeatures |= XArchIntrinsicConstants_Avx;
254
-
255
- if ((cpuidInfo[CPUID_ECX] & (1 << 12 )) != 0 ) // FMA
256
- {
257
- g_cpuFeatures |= XArchIntrinsicConstants_Fma;
258
- }
259
-
260
- if (maxCpuId >= 0x07 )
261
- {
262
- __cpuidex (cpuidInfo, 0x00000007 , 0x00000000 );
263
-
264
- if ((cpuidInfo[CPUID_EBX] & (1 << 5 )) != 0 ) // AVX2
265
- {
266
- g_cpuFeatures |= XArchIntrinsicConstants_Avx2;
267
- g_cpuFeatures |= XArchIntrinsicConstants_VectorT256;
268
-
269
- if (PalIsAvx512Enabled () && (avx512StateSupport () == 1 )) // XGETBV XRC0[7:5] == 111
270
- {
271
- if ((cpuidInfo[CPUID_EBX] & (1 << 16 )) != 0 ) // AVX512F
272
- {
273
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512f;
274
- g_cpuFeatures |= XArchIntrinsicConstants_VectorT512;
275
-
276
- bool isAVX512_VLSupported = false ;
277
- if ((cpuidInfo[CPUID_EBX] & (1 << 31 )) != 0 ) // AVX512VL
278
- {
279
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512f_vl;
280
- isAVX512_VLSupported = true ;
281
- }
282
-
283
- if ((cpuidInfo[CPUID_EBX] & (1 << 30 )) != 0 ) // AVX512BW
284
- {
285
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512bw;
286
- if (isAVX512_VLSupported) // AVX512BW_VL
287
- {
288
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512bw_vl;
289
- }
290
- }
291
-
292
- if ((cpuidInfo[CPUID_EBX] & (1 << 28 )) != 0 ) // AVX512CD
293
- {
294
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512cd;
295
- if (isAVX512_VLSupported) // AVX512CD_VL
296
- {
297
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512cd_vl;
298
- }
299
- }
300
-
301
- if ((cpuidInfo[CPUID_EBX] & (1 << 17 )) != 0 ) // AVX512DQ
302
- {
303
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512dq;
304
- if (isAVX512_VLSupported) // AVX512DQ_VL
305
- {
306
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512dq_vl;
307
- }
308
- }
309
-
310
- if ((cpuidInfo[CPUID_ECX] & (1 << 1 )) != 0 ) // AVX512VBMI
311
- {
312
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512Vbmi;
313
- if (isAVX512_VLSupported) // AVX512VBMI_VL
314
- {
315
- g_cpuFeatures |= XArchIntrinsicConstants_Avx512Vbmi_vl;
316
- }
317
- }
318
- }
319
- }
320
-
321
- __cpuidex (cpuidInfo, 0x00000007 , 0x00000001 );
322
-
323
- if ((cpuidInfo[CPUID_EAX] & (1 << 4 )) != 0 ) // AVX-VNNI
324
- {
325
- g_cpuFeatures |= XArchIntrinsicConstants_AvxVnni;
326
- }
327
- }
328
- }
329
- }
330
- }
331
- }
332
- }
333
- }
334
- }
335
- }
336
-
337
- if (maxCpuId >= 0x07 )
338
- {
339
- __cpuidex (cpuidInfo, 0x00000007 , 0x00000000 );
340
-
341
- if ((cpuidInfo[CPUID_EBX] & (1 << 3 )) != 0 ) // BMI1
342
- {
343
- g_cpuFeatures |= XArchIntrinsicConstants_Bmi1;
344
- }
345
-
346
- if ((cpuidInfo[CPUID_EBX] & (1 << 8 )) != 0 ) // BMI2
347
- {
348
- g_cpuFeatures |= XArchIntrinsicConstants_Bmi2;
349
- }
350
-
351
- if ((cpuidInfo[CPUID_EDX] & (1 << 14 )) != 0 )
352
- {
353
- g_cpuFeatures |= XArchIntrinsicConstants_Serialize; // SERIALIZE
354
- }
355
- }
356
- }
357
-
358
- __cpuid (cpuidInfo, 0x80000000 );
359
- uint32_t maxCpuIdEx = static_cast <uint32_t >(cpuidInfo[CPUID_EAX]);
360
-
361
- if (maxCpuIdEx >= 0x80000001 )
362
- {
363
- __cpuid (cpuidInfo, 0x80000001 );
364
-
365
- if ((cpuidInfo[CPUID_ECX] & (1 << 5 )) != 0 ) // LZCNT
366
- {
367
- g_cpuFeatures |= XArchIntrinsicConstants_Lzcnt;
368
- }
369
-
370
- #ifdef HOST_AMD64
371
- // AMD has a "fast" mode for fxsave/fxrstor, which omits the saving of xmm registers. The OS will enable this mode
372
- // if it is supported. So if we continue to use fxsave/fxrstor, we must manually save/restore the xmm registers.
373
- // fxsr_opt is bit 25 of CPUID_EDX
374
- if ((cpuidInfo[CPUID_EDX] & (1 << 25 )) != 0 )
375
- g_fHasFastFxsave = true ;
376
- #endif
377
- }
378
- #endif // HOST_X86 || HOST_AMD64
379
-
380
- #if defined(HOST_ARM64)
381
- PAL_GetCpuCapabilityFlags (&g_cpuFeatures);
382
- #endif
184
+ g_cpuFeatures = minipal_getcpufeatures ();
383
185
384
186
if ((g_cpuFeatures & g_requiredCpuFeatures) != g_requiredCpuFeatures)
385
187
{
0 commit comments