From 7b1376c3814ffa118b64ca9d12338f65dcc5115e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 23 Jan 2024 19:48:53 +0100 Subject: [PATCH 1/2] 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 --- src/OpenColorIO/CPUInfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenColorIO/CPUInfo.cpp b/src/OpenColorIO/CPUInfo.cpp index 28fcd9477e..84ed27b11b 100644 --- a/src/OpenColorIO/CPUInfo.cpp +++ b/src/OpenColorIO/CPUInfo.cpp @@ -107,7 +107,7 @@ 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) { @@ -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; } } From 680249807a5df86155cc8df2c21ea2481f1fb0bb Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 24 Jan 2024 19:07:43 +0100 Subject: [PATCH 2/2] Fix another case pointed out in review Signed-off-by: Brecht Van Lommel --- src/OpenColorIO/CPUInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenColorIO/CPUInfo.cpp b/src/OpenColorIO/CPUInfo.cpp index 84ed27b11b..c0d7c02899 100644 --- a/src/OpenColorIO/CPUInfo.cpp +++ b/src/OpenColorIO/CPUInfo.cpp @@ -110,7 +110,7 @@ CPUInfo::CPUInfo() 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) {