AVX2: Verify O/S support for AVX2 before enabling
This fixes crashes that would occur when attempting to use libjpeg-turbo's AVX2 extensions on older O/S's (such as Windows XP or RHEL 5.) Even if the CPU supports AVX2, the O/S has to also support saving/restoring YMM registers when switching contexts.
This commit is contained in:
@@ -48,6 +48,16 @@ EXTN(jpeg_simd_cpu_support):
|
||||
or rdi, JSIMD_SSE
|
||||
test rax, 1<<5 ; bit5:AVX2
|
||||
jz short .return
|
||||
|
||||
; Check for AVX2 O/S support
|
||||
mov rax, 1
|
||||
xor rcx, rcx
|
||||
cpuid
|
||||
test rcx, 1<<27
|
||||
jz short .return ; O/S does not support XSAVE
|
||||
test rcx, 1<<28
|
||||
jz short .return ; CPU does not support AVX2
|
||||
|
||||
or rdi, JSIMD_AVX2
|
||||
|
||||
.return:
|
||||
|
||||
@@ -82,6 +82,16 @@ EXTN(jpeg_simd_cpu_support):
|
||||
mov eax, ebx
|
||||
test eax, 1<<5 ; bit5:AVX2
|
||||
jz short .no_avx2
|
||||
|
||||
; Check for AVX2 O/S support
|
||||
mov eax, 1
|
||||
xor ecx, ecx
|
||||
cpuid
|
||||
test ecx, 1<<27
|
||||
jz short .no_avx2 ; O/S does not support XSAVE
|
||||
test ecx, 1<<28
|
||||
jz short .no_avx2 ; CPU does not support AVX2
|
||||
|
||||
or edi, JSIMD_AVX2
|
||||
.no_avx2:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user