]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Bug 20689: Fix FMA and AVX2 detection on Intel
authorCarlos O'Donell <carlos@systemhalted.org>
Mon, 17 Oct 2016 23:35:34 +0000 (19:35 -0400)
committerCarlos O'Donell <carlos@systemhalted.org>
Mon, 17 Oct 2016 23:39:54 +0000 (19:39 -0400)
In the Intel Architecture Instruction Set Extensions Programming
reference the recommended way to test for FMA in section
'2.2.1 Detection of FMA' is:

"Application Software must identify that hardware supports AVX as
explained in ... after that it must also detect support for FMA..."

We don't do that in glibc. We use osxsave to detect the use of xgetbv,
and after that we check for AVX and FMA orthogonally. It is conceivable
that you could have the AVX bit clear and the FMA bit in an undefined
state.

This commit fixes FMA and AVX2 detection to depend on usable AVX
as required by the recommended Intel sequences.

v1: https://www.sourceware.org/ml/libc-alpha/2016-10/msg00241.html
v2: https://www.sourceware.org/ml/libc-alpha/2016-10/msg00265.html

ChangeLog
sysdeps/x86/cpu-features.c

index 5448fad7b6518d522a313acdfa3c86069013b2e3..11ee620309255d42b44cfd8f0398d0515589c2c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-17  Carlos O'Donell  <carlos@redhat.com>
+
+       [BZ #20689]
+       * sysdeps/x86/cpu-features.c: Only enable FMA and AVX2 if AVX is
+       usable.
+
 2016-10-17  Joseph Myers  <joseph@codesourcery.com>
 
        * sysdeps/generic/nan-high-order-bit.h: New file.
index 11b9af2231958f0d6b599f0582624ec2fbc1f382..e228a76c403697eb47fa46d1f3dafb363776af95 100644 (file)
@@ -60,12 +60,20 @@ get_common_indeces (struct cpu_features *cpu_features,
        {
          /* Determine if AVX is usable.  */
          if (CPU_FEATURES_CPU_P (cpu_features, AVX))
-           cpu_features->feature[index_arch_AVX_Usable]
-             |= bit_arch_AVX_Usable;
-         /* Determine if AVX2 is usable.  */
-         if (CPU_FEATURES_CPU_P (cpu_features, AVX2))
-           cpu_features->feature[index_arch_AVX2_Usable]
-             |= bit_arch_AVX2_Usable;
+           {
+             cpu_features->feature[index_arch_AVX_Usable]
+               |= bit_arch_AVX_Usable;
+             /* The following features depend on AVX being usable.  */
+             /* Determine if AVX2 is usable.  */
+             if (CPU_FEATURES_CPU_P (cpu_features, AVX2))
+               cpu_features->feature[index_arch_AVX2_Usable]
+                 |= bit_arch_AVX2_Usable;
+             /* Determine if FMA is usable.  */
+             if (CPU_FEATURES_CPU_P (cpu_features, FMA))
+               cpu_features->feature[index_arch_FMA_Usable]
+                 |= bit_arch_FMA_Usable;
+           }
+
          /* Check if OPMASK state, upper 256-bit of ZMM0-ZMM15 and
             ZMM16-ZMM31 state are enabled.  */
          if ((xcrlow & (bit_Opmask_state | bit_ZMM0_15_state
@@ -83,10 +91,6 @@ get_common_indeces (struct cpu_features *cpu_features,
                      |= bit_arch_AVX512DQ_Usable;
                }
            }
-         /* Determine if FMA is usable.  */
-         if (CPU_FEATURES_CPU_P (cpu_features, FMA))
-           cpu_features->feature[index_arch_FMA_Usable]
-             |= bit_arch_FMA_Usable;
        }
     }
 }