Skip to content

Commit

Permalink
Fix AVX instructions used on CPUs that don't support them (AcademySof…
Browse files Browse the repository at this point in the history
…twareFoundation#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 <brecht@blender.org>

* Fix another case pointed out in review

Signed-off-by: Brecht Van Lommel <brecht@blender.org>

---------

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
(cherry picked from commit 0c90ded)
Signed-off-by: Doug Walker <doug.walker@autodesk.com>
  • Loading branch information
brechtvl authored and doug-walker committed Jan 29, 2024
1 parent c136224 commit eccae2e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/OpenColorIO/CPUInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down

0 comments on commit eccae2e

Please sign in to comment.