Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86: Add disableAVX2/512 options and check XCR0 for OS support #7510

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions compiler/x/env/OMRCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,37 @@ OMR::X86::CPU::detect(OMRPortLibrary * const omrPortLib)

if (TRUE == omrsysinfo_processor_has_feature(&processorDescription, OMR_FEATURE_X86_OSXSAVE))
{
static const bool disableAVX = feGetEnv("TR_DisableAVX") != NULL;
if (((6 & _xgetbv(0)) != 6) || disableAVX) // '6' = mask for XCR0[2:1]='11b' (XMM state and YMM state are enabled)
// Check XCRO register for OS support of xmm/ymm/zmm
// '6' = mask for XCR0[2:1]='11b' (XMM state and YMM state are enabled)
static const bool disableAVX = ((6 & _xgetbv(0)) != 6) || feGetEnv("TR_DisableAVX") != NULL;
static const bool disableAVX2 = disableAVX || feGetEnv("TR_DisableAVX2") != NULL;
// 'e0' = mask for XCR0[7:5]='111b' (Opmask, ZMM_Hi256, Hi16_ZMM)
static const bool disableAVX512 = ((0xe0 & _xgetbv(0)) != 0xe0) || disableAVX || disableAVX2 || feGetEnv("TR_DisableAVX512") != NULL;

if(disableAVX)
{
// Unset OSXSAVE if not enabled via CR0
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_OSXSAVE, FALSE);
// Unset AVX if not enabled via CR0 or otherwise disabled
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX, FALSE);
}

if (disableAVX2)
{
// Unset AVX if not enabled via CR0 or otherwise disabled
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX2, FALSE);
}

if (disableAVX512)
{
// Unset AVX-512 if not enabled via CR0 or otherwise disabled
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512F, FALSE);
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512VL, FALSE);
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512BW, FALSE);
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512DQ, FALSE);
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512CD, FALSE);

omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_VBMI2, FALSE);
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_BITALG, FALSE);
omrsysinfo_processor_set_feature(&processorDescription, OMR_FEATURE_X86_AVX512_VPOPCNTDQ, FALSE);
}
}

Expand Down
33 changes: 29 additions & 4 deletions compiler/x/runtime/X86Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,36 @@ inline bool jitGetCPUID(TR_X86CPUIDBuffer* pBuffer)
// Check for XSAVE
if(pBuffer->_featureFlags2 & TR_OSXSAVE)
{
static const bool disableAVX = feGetEnv("TR_DisableAVX") != NULL;
if(((6 & _xgetbv(0)) != 6) || disableAVX) // '6' = mask for XCR0[2:1]='11b' (XMM state and YMM state are enabled)
// Check XCRO register for OS support of xmm/ymm/zmm
// '6' = mask for XCR0[2:1]='11b' (XMM state and YMM state are enabled)
static const bool disableAVX = ((6 & _xgetbv(0)) != 6) || feGetEnv("TR_DisableAVX") != NULL;
static const bool disableAVX2 = disableAVX || feGetEnv("TR_DisableAVX2") != NULL;
// 'e0' = mask for XCR0[7:5]='111b' (Opmask, ZMM_Hi256, Hi16_ZMM)
static const bool disableAVX512 = ((0xe0 & _xgetbv(0)) != 0xe0) || disableAVX || disableAVX2 || feGetEnv("TR_DisableAVX512") != NULL;

if(disableAVX)
{
pBuffer->_featureFlags2 &= ~TR_AVX; // Unset TR_AVX if not enabled via CR0 or otherwise disabled
}

if (disableAVX2)
{
// Unset OSXSAVE if not enabled via CR0
pBuffer->_featureFlags2 &= ~TR_OSXSAVE;
// Unset AVX2 if not enabled via CR0 or otherwise disabled
pBuffer->_featureFlags8 &= ~TR_AVX2;
}

if (disableAVX512)
{
// Unset AVX-512 if not enabled via CR0 or otherwise disabled
pBuffer->_featureFlags8 &= ~TR_AVX512F;
pBuffer->_featureFlags8 &= ~TR_AVX512VL;
pBuffer->_featureFlags8 &= ~TR_AVX512BW;
pBuffer->_featureFlags8 &= ~TR_AVX512DQ;
pBuffer->_featureFlags8 &= ~TR_AVX512CD;

pBuffer->_featureFlags10 &= ~TR_AVX512_VBMI2;
pBuffer->_featureFlags10 &= ~TR_AVX512_BITALG;
pBuffer->_featureFlags10 &= ~TR_AVX512_VPOPCNTDQ;
}
}

Expand Down