]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Workaround possible CPUID bug in Sandy Bridge.
authorliuhongt <hongtao.liu@intel.com>
Fri, 4 Aug 2023 01:27:39 +0000 (09:27 +0800)
committerliuhongt <hongtao.liu@intel.com>
Wed, 9 Aug 2023 07:49:53 +0000 (15:49 +0800)
Don't access leaf 7 subleaf 1 unless subleaf 0 says it is
supported via EAX.

Intel documentation says invalid subleaves return 0. We had been
relying on that behavior instead of checking the max sublef number.

It appears that some Sandy Bridge CPUs return at least the subleaf 0
EDX value for subleaf 1. Best guess is that this is a bug in a
microcode patch since all of the bits we're seeing set in EDX were
introduced after Sandy Bridge was originally released.

This is causing avxvnniint16 to be incorrectly enabled with
-march=native on these CPUs.

gcc/ChangeLog:

* common/config/i386/cpuinfo.h (get_available_features): Check
max_subleaf_level for valid subleaf before use CPUID.

gcc/common/config/i386/cpuinfo.h

index 00b5eee21d4f3580e417dbfe8ebd4b241567a2ad..d42cdecdd26ce83cecaff24acb7b850c487b20af 100644 (file)
@@ -623,7 +623,9 @@ get_available_features (struct __processor_model *cpu_model,
   /* Get Advanced Features at level 7 (eax = 7, ecx = 0/1). */
   if (max_cpuid_level >= 7)
     {
-      __cpuid_count (7, 0, eax, ebx, ecx, edx);
+      unsigned int max_subleaf_level;
+
+      __cpuid_count (7, 0, max_subleaf_level, ebx, ecx, edx);
       if (ebx & bit_BMI)
        set_feature (FEATURE_BMI);
       if (ebx & bit_SGX)
@@ -733,18 +735,21 @@ get_available_features (struct __processor_model *cpu_model,
            set_feature (FEATURE_AVX512VP2INTERSECT);
        }
 
-      __cpuid_count (7, 1, eax, ebx, ecx, edx);
-      if (eax & bit_HRESET)
-       set_feature (FEATURE_HRESET);
-      if (avx_usable)
-       {
-         if (eax & bit_AVXVNNI)
-           set_feature (FEATURE_AVXVNNI);
-       }
-      if (avx512_usable)
+      if (max_subleaf_level >= 1)
        {
-         if (eax & bit_AVX512BF16)
-           set_feature (FEATURE_AVX512BF16);
+         __cpuid_count (7, 1, eax, ebx, ecx, edx);
+         if (eax & bit_HRESET)
+           set_feature (FEATURE_HRESET);
+         if (avx_usable)
+           {
+             if (eax & bit_AVXVNNI)
+               set_feature (FEATURE_AVXVNNI);
+           }
+         if (avx512_usable)
+           {
+             if (eax & bit_AVX512BF16)
+               set_feature (FEATURE_AVX512BF16);
+           }
        }
     }