2016-09-28  Uros Bizjak  <ubiz...@gmail.com>

    PR target/77756
    * config/i386/cpuid.h (__get_cpuid): Handle CPUID level >= 7.

testsuite/ChangeLog:

2016-09-28  Uros Bizjak  <ubiz...@gmail.com>

    PR target/77756
    * gcc.target/i386/pr77756.c: New test.

Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline, will be backported to release branches.

Uros.
Index: config/i386/cpuid.h
===================================================================
--- config/i386/cpuid.h (revision 240579)
+++ config/i386/cpuid.h (working copy)
@@ -244,6 +244,16 @@ __get_cpuid (unsigned int __level,
   if (__get_cpuid_max (__ext, 0) < __level)
     return 0;
 
-  __cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
+  if (__ext)
+    __cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
+  else
+    {
+      if (__level >= 13)
+       __cpuid_count (__level, 1, *__eax, *__ebx, *__ecx, *__edx);
+      else if (__level >= 7)
+       __cpuid_count (__level, 0, *__eax, *__ebx, *__ecx, *__edx);
+      else
+       __cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
+    }
   return 1;
 }
Index: testsuite/gcc.target/i386/pr77756.c
===================================================================
--- testsuite/gcc.target/i386/pr77756.c (nonexistent)
+++ testsuite/gcc.target/i386/pr77756.c (working copy)
@@ -0,0 +1,22 @@
+/* { dg-do run }  */
+
+#include "cpuid.h"
+
+int
+main ()
+{
+  __builtin_cpu_init ();
+
+  if (__builtin_cpu_supports ("avx2"))
+    {
+      unsigned int eax, ebx, ecx, edx;
+
+      if (!__get_cpuid (7, &eax, &ebx, &ecx, &edx))
+       __builtin_abort ();
+
+      if (!(ebx & bit_AVX2))
+       __builtin_abort ();
+    }
+
+  return 0;
+}

Reply via email to