shithub: libvpx

Download patch

ref: 4902606bb6803cfbb526d41519b851c47f3e2df7
parent: 2be50a1c9cf62c046c668669f5a224d2fc8c3f45
parent: abff8b24b935f134fd6c09a659dcb2c3fd6a1051
author: James Zern <[email protected]>
date: Tue Apr 28 17:31:02 EDT 2015

Merge "x86_simd_caps: check max cpuid before testing AVX2"

--- a/vpx_ports/x86.h
+++ b/vpx_ports/x86.h
@@ -152,7 +152,7 @@
 x86_simd_caps(void) {
   unsigned int flags = 0;
   unsigned int mask = ~0;
-  unsigned int reg_eax, reg_ebx, reg_ecx, reg_edx;
+  unsigned int max_cpuid_val, reg_eax, reg_ebx, reg_ecx, reg_edx;
   char *env;
   (void)reg_ebx;
 
@@ -168,9 +168,9 @@
     mask = strtol(env, NULL, 0);
 
   /* Ensure that the CPUID instruction supports extended features */
-  cpuid(0, 0, reg_eax, reg_ebx, reg_ecx, reg_edx);
+  cpuid(0, 0, max_cpuid_val, reg_ebx, reg_ecx, reg_edx);
 
-  if (reg_eax < 1)
+  if (max_cpuid_val < 1)
     return 0;
 
   /* Get the standard feature flags */
@@ -193,10 +193,12 @@
     if ((xgetbv() & 0x6) == 0x6) {
       flags |= HAS_AVX;
 
-      /* Get the leaf 7 feature flags. Needed to check for AVX2 support */
-      cpuid(7, 0, reg_eax, reg_ebx, reg_ecx, reg_edx);
+      if (max_cpuid_val >= 7) {
+        /* Get the leaf 7 feature flags. Needed to check for AVX2 support */
+        cpuid(7, 0, reg_eax, reg_ebx, reg_ecx, reg_edx);
 
-      if (reg_ebx & BIT(5)) flags |= HAS_AVX2;
+        if (reg_ebx & BIT(5)) flags |= HAS_AVX2;
+      }
     }
   }