From eccae2e2e89ea3ec68851ec0fdae4fcb88f6a9be Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 26 Jan 2024 20:53:29 +0100 Subject: [PATCH] Fix AVX instructions used on CPUs that don't support them (#1935) * Fix AVX instructions used on CPUs that don't support them It's supposed to check all bits are enabled, not just one of them. This causes a crash using OpenColorIO on older CPUs. Thanks to Ray Molenkamp for help tracking this down. Signed-off-by: Brecht Van Lommel * Fix another case pointed out in review Signed-off-by: Brecht Van Lommel --------- Signed-off-by: Brecht Van Lommel (cherry picked from commit 0c90ded16687b1b63f3e24ef417789c89b1dc509) Signed-off-by: Doug Walker --- src/OpenColorIO/CPUInfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenColorIO/CPUInfo.cpp b/src/OpenColorIO/CPUInfo.cpp index 28fcd9477..c0d7c0289 100644 --- a/src/OpenColorIO/CPUInfo.cpp +++ b/src/OpenColorIO/CPUInfo.cpp @@ -107,10 +107,10 @@ CPUInfo::CPUInfo() flags |= X86_CPU_FLAG_SSE42; /* Check OSXSAVE and AVX bits */ - if (info.reg.ecx & 0x18000000) + if ((info.reg.ecx & 0x18000000) == 0x18000000) { xcr = xgetbv(); - if(xcr & 0x6) { + if((xcr & 0x6) == 0x6) { flags |= X86_CPU_FLAG_AVX; if(info.reg.ecx & 0x20000000) { @@ -129,7 +129,7 @@ CPUInfo::CPUInfo() /* OPMASK/ZMM state */ if ((xcr & 0xe0) == 0xe0) { - if ((flags & X86_CPU_FLAG_AVX2) && (info.reg.ebx & 0xd0030000)) + if ((flags & X86_CPU_FLAG_AVX2) && ((info.reg.ebx & 0xd0030000) == 0xd0030000)) flags |= X86_CPU_FLAG_AVX512; } }