Skip to content

Commit 282cb6c

Browse files
committed
Check if YMM register saving is OS enabled
1 parent 6080027 commit 282cb6c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

cpp/src/arrow/util/cpu_info.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,19 @@ void OsRetrieveCpuInfo(int64_t* hardware_flags, CpuInfo::Vendor* vendor,
184184
}
185185

186186
bool zmm_enabled = false;
187+
bool ymm_enabled = false;
187188
if (features_ECX[27]) { // OSXSAVE
188-
// Query if the OS supports saving ZMM registers when switching contexts
189+
// Query if the OS supports saving YMM and ZMM registers when switching contexts
189190
int64_t xcr0 = _xgetbv(0);
190191
zmm_enabled = (xcr0 & 0xE0) == 0xE0;
192+
ymm_enabled = (xcr0 & 0b110) == 0b110;
191193
}
192194

193195
if (features_ECX[9]) *hardware_flags |= CpuInfo::SSSE3;
194196
if (features_ECX[19]) *hardware_flags |= CpuInfo::SSE4_1;
195197
if (features_ECX[20]) *hardware_flags |= CpuInfo::SSE4_2;
196198
if (features_ECX[23]) *hardware_flags |= CpuInfo::POPCNT;
197-
if (features_ECX[28]) *hardware_flags |= CpuInfo::AVX;
199+
if (ymm_enabled && features_ECX[28]) *hardware_flags |= CpuInfo::AVX;
198200

199201
// cpuid with EAX=7, ECX=0: Extended Features
200202
register_EAX_id = 7;
@@ -203,10 +205,11 @@ void OsRetrieveCpuInfo(int64_t* hardware_flags, CpuInfo::Vendor* vendor,
203205
std::bitset<32> features_EBX = cpu_info[1];
204206

205207
if (features_EBX[3]) *hardware_flags |= CpuInfo::BMI1;
206-
if (features_EBX[5]) *hardware_flags |= CpuInfo::AVX2;
207208
if (features_EBX[8]) *hardware_flags |= CpuInfo::BMI2;
209+
// Only use AVX/AVX2 if enabled by the OS
210+
if (ymm_enabled && *features_EBX[5]) *hardware_flags |= CpuInfo::AVX2;
208211
// ARROW-11427: only use AVX512 if enabled by the OS
209-
if (zmm_enabled) {
212+
if (ymm_enabled && zmm_enabled) {
210213
if (features_EBX[16]) *hardware_flags |= CpuInfo::AVX512F;
211214
if (features_EBX[17]) *hardware_flags |= CpuInfo::AVX512DQ;
212215
if (features_EBX[28]) *hardware_flags |= CpuInfo::AVX512CD;

0 commit comments

Comments
 (0)