From: DRC Date: Tue, 12 Jul 2016 01:21:46 +0000 (-0500) Subject: AVX2: Verify O/S support for AVX2 before enabling X-Git-Tag: 1.5.90~114 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3dcb85ee9a9ced33842c032b01a47d567e5ab5ec;p=libjpeg-turbo 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. --- diff --git a/simd/jsimdcpu-64.asm b/simd/jsimdcpu-64.asm index 80e19c9..d0c2e5b 100644 --- a/simd/jsimdcpu-64.asm +++ b/simd/jsimdcpu-64.asm @@ -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: diff --git a/simd/jsimdcpu.asm b/simd/jsimdcpu.asm index 71abf93..92782e2 100644 --- a/simd/jsimdcpu.asm +++ b/simd/jsimdcpu.asm @@ -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: