|
116 | 116 | #include <strings.h>
|
117 | 117 | #endif
|
118 | 118 |
|
| 119 | +#if defined(OMR_OS_WINDOWS) && defined(TR_TARGET_X86) |
| 120 | +#include <intrin.h> |
| 121 | +#elif defined(TR_TARGET_X86) |
| 122 | +inline unsigned long long _xgetbv(unsigned int ecx) |
| 123 | + { |
| 124 | + unsigned int eax, edx; |
| 125 | + __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(ecx)); |
| 126 | + return ((unsigned long long)edx << 32) | eax; |
| 127 | + } |
| 128 | +#endif |
| 129 | + |
119 | 130 | #if defined(J9ZOS390)
|
120 | 131 | extern "C" bool _isPSWInProblemState(); /* 390 asm stub */
|
121 | 132 | #endif
|
|
296 | 307 | TR_J9VM::initializeProcessorType()
|
297 | 308 | {
|
298 | 309 | TR_ASSERT(_compInfo,"compInfo not defined");
|
299 |
| - |
| 310 | + |
300 | 311 | if (TR::Compiler->target.cpu.isZ())
|
301 | 312 | {
|
302 | 313 | OMRProcessorDesc processorDescription = TR::Compiler->target.cpu.getProcessorDescription();
|
@@ -333,12 +344,42 @@ TR_J9VM::initializeProcessorType()
|
333 | 344 | {
|
334 | 345 | OMRProcessorDesc processorDescription = TR::Compiler->target.cpu.getProcessorDescription();
|
335 | 346 | OMRPORT_ACCESS_FROM_OMRPORT(TR::Compiler->omrPortLib);
|
336 |
| - static const bool disableAVX = feGetEnv("TR_DisableAVX") != NULL; |
337 |
| - if (disableAVX) |
| 347 | + |
| 348 | + bool disableAVX = true; |
| 349 | + bool disableAVX512 = true; |
| 350 | + |
| 351 | + // Check XCRO register for OS support of xmm/ymm/zmm |
| 352 | + if (TRUE == omrsysinfo_processor_has_feature(&processorDescription, OMR_FEATURE_X86_OSXSAVE)) |
338 | 353 | {
|
339 |
| - omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_OSXSAVE, FALSE); |
| 354 | + // '6' = mask for XCR0[2:1]='11b' (XMM state and YMM state are enabled) |
| 355 | + disableAVX = ((6 & _xgetbv(0)) != 6); |
| 356 | + // 'e6' = (mask for XCR0[7:5]='111b' (Opmask, ZMM_Hi256, Hi16_ZMM) + XCR0[2:1]='11b' (XMM/YMM)) |
| 357 | + disableAVX512 = ((0xe6 & _xgetbv(0)) != 0xe6); |
340 | 358 | }
|
341 |
| - |
| 359 | + |
| 360 | + if(disableAVX) |
| 361 | + { |
| 362 | + // Unset AVX/AVX2 if not enabled via CR0 or otherwise disabled |
| 363 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX, FALSE); |
| 364 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX2, FALSE); |
| 365 | + } |
| 366 | + |
| 367 | + if (disableAVX512) |
| 368 | + { |
| 369 | + // Unset AVX-512 if not enabled via CR0 or otherwise disabled |
| 370 | + // If other AVX-512 extensions are supported in the port library, they need to be disabled here |
| 371 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512F, FALSE); |
| 372 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512VL, FALSE); |
| 373 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512BW, FALSE); |
| 374 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512CD, FALSE); |
| 375 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512DQ, FALSE); |
| 376 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_BITALG, FALSE); |
| 377 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_VBMI, FALSE); |
| 378 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_VBMI2, FALSE); |
| 379 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_VNNI, FALSE); |
| 380 | + omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_VPOPCNTDQ, FALSE); |
| 381 | + } |
| 382 | + |
342 | 383 | TR::Compiler->target.cpu = TR::CPU::customize(processorDescription);
|
343 | 384 |
|
344 | 385 | const char *vendor = TR::Compiler->target.cpu.getProcessorVendorId();
|
|
0 commit comments