Bug 1520760 - Fix AVX2 detection to ensure we support the required CPUID version. r=jrmuizel
authorAndrew Osmond <aosmond@mozilla.com>
Fri, 22 Feb 2019 10:11:54 -0500
changeset 519512 afbcec667ac42d4a17303ad65bd499a29e43c403
parent 519511 bb879a6a95f89fc3319899d3267c77a071d88076
child 519513 7ba97389b18333d03d4c07e101d1b156ec9b692f
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1520760
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1520760 - Fix AVX2 detection to ensure we support the required CPUID version. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D20833
media/libjpeg/1520760-avx2-detection.diff
media/libjpeg/simd/i386/jsimdcpu.asm
media/libjpeg/simd/x86_64/jsimdcpu.asm
--- a/media/libjpeg/1520760-avx2-detection.diff
+++ b/media/libjpeg/1520760-avx2-detection.diff
@@ -1,32 +1,57 @@
 Bug 1520760 - Fix AVX2 detection to ensure we have all required CPU parameters.
 
 diff --git simd/i386/jsimdcpu.asm simd/i386/jsimdcpu.asm
 --- simd/i386/jsimdcpu.asm
 +++ simd/i386/jsimdcpu.asm
-@@ -87,8 +87,10 @@ EXTN(jpeg_simd_cpu_support):
+@@ -75,6 +75,12 @@ EXTN(jpeg_simd_cpu_support):
+     or          edi, byte JSIMD_SSE2
+ .no_sse2:
+ 
++    ; Check for level 7 support
++    xor         eax, eax
++    cpuid
++    cmp         eax, 7
++    jl          short .no_avx2
++
+     ; Check for AVX2 instruction support
+     mov         eax, 7
+     xor         ecx, ecx
+@@ -87,8 +93,10 @@ EXTN(jpeg_simd_cpu_support):
      mov         eax, 1
      xor         ecx, ecx
      cpuid
 -    test        ecx, 1<<27
 +    test        ecx, 1<<26
      jz          short .no_avx2          ; O/S does not support XSAVE
 +    test        ecx, 1<<27
 +    jz          short .no_avx2          ; O/S does not support OSXSAVE
      test        ecx, 1<<28
      jz          short .no_avx2          ; CPU does not support AVX2
  
 diff --git simd/x86_64/jsimdcpu.asm simd/x86_64/jsimdcpu.asm
 --- simd/x86_64/jsimdcpu.asm
 +++ simd/x86_64/jsimdcpu.asm
-@@ -53,8 +53,10 @@ EXTN(jpeg_simd_cpu_support):
-     mov         rax, 1
+@@ -38,14 +38,20 @@ EXTN(jpeg_simd_cpu_support):
+ 
+     xor         rdi, rdi                ; simd support flag
+ 
++    ; Check for level 7 support
++    xor         rax, rax
++    cpuid
++
++    or          rdi, JSIMD_SSE2
++    or          rdi, JSIMD_SSE
++    cmp         rax, 7
++    jl          short .return
++
+     ; Check for AVX2 instruction support
+     mov         rax, 7
      xor         rcx, rcx
      cpuid
--    test        rcx, 1<<27
-+    test        rcx, 1<<26
-     jz          short .return           ; O/S does not support XSAVE
-+    test        rcx, 1<<27
-+    jz          short .return           ; O/S does not support OSXSAVE
-     test        rcx, 1<<28
-     jz          short .return           ; CPU does not support AVX2
+     mov         rax, rbx                ; rax = Extended feature flags
+-
+-    or          rdi, JSIMD_SSE2
+-    or          rdi, JSIMD_SSE
+     test        rax, 1<<5               ; bit5:AVX2
+     jz          short .return
  
--- a/media/libjpeg/simd/i386/jsimdcpu.asm
+++ b/media/libjpeg/simd/i386/jsimdcpu.asm
@@ -70,16 +70,22 @@ EXTN(jpeg_simd_cpu_support):
     jz          short .no_sse
     or          edi, byte JSIMD_SSE
 .no_sse:
     test        eax, 1<<26              ; bit26:SSE2
     jz          short .no_sse2
     or          edi, byte JSIMD_SSE2
 .no_sse2:
 
+    ; Check for level 7 support
+    xor         eax, eax
+    cpuid
+    cmp         eax, 7
+    jl          short .no_avx2
+
     ; Check for AVX2 instruction support
     mov         eax, 7
     xor         ecx, ecx
     cpuid
     mov         eax, ebx
     test        eax, 1<<5               ; bit5:AVX2
     jz          short .no_avx2
 
--- a/media/libjpeg/simd/x86_64/jsimdcpu.asm
+++ b/media/libjpeg/simd/x86_64/jsimdcpu.asm
@@ -33,24 +33,30 @@
     GLOBAL_FUNCTION(jpeg_simd_cpu_support)
 
 EXTN(jpeg_simd_cpu_support):
     push        rbx
     push        rdi
 
     xor         rdi, rdi                ; simd support flag
 
+    ; Check for level 7 support
+    xor         rax, rax
+    cpuid
+
+    or          rdi, JSIMD_SSE2
+    or          rdi, JSIMD_SSE
+    cmp         rax, 7
+    jl          short .return
+
     ; Check for AVX2 instruction support
     mov         rax, 7
     xor         rcx, rcx
     cpuid
     mov         rax, rbx                ; rax = Extended feature flags
-
-    or          rdi, JSIMD_SSE2
-    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<<26