From: DRC Date: Fri, 28 Sep 2018 20:46:35 +0000 (-0500) Subject: SIMD: Fix c000001d exception on Win 7 w/o SP1 X-Git-Tag: 2.0.1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d5f281b734425fc1d930ff2c3f8441aad731343e;p=libjpeg-turbo SIMD: Fix c000001d exception on Win 7 w/o SP1 Apparently Windows 7 without SP1 has O/S support for XSAVE but not for YMM registers, and this exposed a bug in our usage of xgetbv. The test instruction will set ZF only if none of the bits match between the two operarands, so in effect, we were enabling AVX2 instructions if the O/S supported XSAVE and the CPU supported AVX2 but the O/S only supported XMM registers. This bug was not exposed on, for instance, Windows XP or RHEL 5 because those O/S's do not support XSAVE. Fixes #288 --- diff --git a/ChangeLog.md b/ChangeLog.md index 3d99801..47c730b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,9 @@ functions in the MIPS DSPr2 SIMD extensions are now disabled at compile time if the soft float ABI is enabled. Those functions use instructions that are incompatible with the soft float ABI. +3. Fixed an issue in the SIMD feature detection code that caused libjpeg-turbo +to crash on Windows 7 if Service Pack 1 was not installed. + 2.0.0 ===== diff --git a/simd/i386/jsimdcpu.asm b/simd/i386/jsimdcpu.asm index 50a0d51..faddd38 100644 --- a/simd/i386/jsimdcpu.asm +++ b/simd/i386/jsimdcpu.asm @@ -94,9 +94,10 @@ EXTN(jpeg_simd_cpu_support): xor ecx, ecx xgetbv - test eax, 6 ; O/S does not manage XMM/YMM state + and eax, 6 + cmp eax, 6 ; O/S does not manage XMM/YMM state ; using XSAVE - jz short .no_avx2 + jnz short .no_avx2 or edi, JSIMD_AVX2 .no_avx2: diff --git a/simd/x86_64/jsimdcpu.asm b/simd/x86_64/jsimdcpu.asm index 42979be..38e1a7b 100644 --- a/simd/x86_64/jsimdcpu.asm +++ b/simd/x86_64/jsimdcpu.asm @@ -60,9 +60,10 @@ EXTN(jpeg_simd_cpu_support): xor rcx, rcx xgetbv - test rax, 6 ; O/S does not manage XMM/YMM state + and rax, 6 + cmp rax, 6 ; O/S does not manage XMM/YMM state ; using XSAVE - jz short .return + jnz short .return or rdi, JSIMD_AVX2