]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: Add MathVec_Prefer_No_AVX512 to cpu-features [BZ #21967]
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 12 Sep 2017 14:46:11 +0000 (07:46 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 12 Sep 2017 14:54:47 +0000 (07:54 -0700)
AVX512 functions in mathvec are used on machines with AVX512.  An AVX2
wrapper is also provided and it can be used when the AVX512 version
isn't profitable.  MathVec_Prefer_No_AVX512 is addded to cpu-features.
If glibc.tune.hwcaps=MathVec_Prefer_No_AVX512 is set in GLIBC_TUNABLES
environment variable, the AVX2 wrapper will be used.

Tested on x86-64 machines with and without AVX512.  Also verified
glibc.tune.hwcaps=MathVec_Prefer_No_AVX512 on AVX512 machine.

[BZ #21967]
* sysdeps/x86/cpu-features.h (bit_arch_MathVec_Prefer_No_AVX512):
New.
(index_arch_MathVec_Prefer_No_AVX512): Likewise.
* sysdeps/x86/cpu-tunables.c (TUNABLE_CALLBACK (set_hwcaps)):
Handle MathVec_Prefer_No_AVX512.
* sysdeps/x86_64/fpu/multiarch/ifunc-mathvec-avx512.h
(IFUNC_SELECTOR): Return AVX2 version if MathVec_Prefer_No_AVX512
is set.

ChangeLog
sysdeps/x86/cpu-features.h
sysdeps/x86/cpu-tunables.c
sysdeps/x86_64/fpu/multiarch/ifunc-mathvec-avx512.h

index 7f8432cb370324a54393b4e24c1b413d3e276e3c..e6567be03ee2efe67ae7a2c11b86b49b2d628fed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-09-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       [BZ #21967]
+       * sysdeps/x86/cpu-features.h (bit_arch_MathVec_Prefer_No_AVX512):
+       New.
+       (index_arch_MathVec_Prefer_No_AVX512): Likewise.
+       * sysdeps/x86/cpu-tunables.c (TUNABLE_CALLBACK (set_hwcaps)):
+       Handle MathVec_Prefer_No_AVX512.
+       * sysdeps/x86_64/fpu/multiarch/ifunc-mathvec-avx512.h
+       (IFUNC_SELECTOR): Return AVX2 version if MathVec_Prefer_No_AVX512
+       is set.
+
 2017-09-12  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
        * posix/sched_primax.c (__sched_get_priority_max): Add
index 9e01781424acf55520cfa281b84621fadef7e5dc..a032a2e168ee7936942f4857bb9ca4685db2883d 100644 (file)
@@ -40,6 +40,7 @@
 #define bit_arch_Use_dl_runtime_resolve_opt    (1 << 20)
 #define bit_arch_Use_dl_runtime_resolve_slow   (1 << 21)
 #define bit_arch_Prefer_No_AVX512              (1 << 22)
+#define bit_arch_MathVec_Prefer_No_AVX512      (1 << 23)
 
 /* CPUID Feature flags.  */
 
@@ -239,6 +240,7 @@ extern const struct cpu_features *__get_cpu_features (void)
 # define index_arch_Use_dl_runtime_resolve_opt FEATURE_INDEX_1
 # define index_arch_Use_dl_runtime_resolve_slow FEATURE_INDEX_1
 # define index_arch_Prefer_No_AVX512   FEATURE_INDEX_1
+# define index_arch_MathVec_Prefer_No_AVX512 FEATURE_INDEX_1
 
 #endif /* !__ASSEMBLER__ */
 
index 0ab708cca80b0417ca3fdc88ae5a4c070524f61a..ec72d86f082ae5e2963c9e6c204c8a4f05da9928 100644 (file)
@@ -303,6 +303,13 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
                 disable, 23);
            }
          break;
+       case 24:
+           {
+             CHECK_GLIBC_IFUNC_ARCH_NEED_ARCH_BOTH
+               (n, cpu_features, MathVec_Prefer_No_AVX512,
+                AVX512F_Usable, disable, 24);
+           }
+         break;
        case 26:
            {
              CHECK_GLIBC_IFUNC_ARCH_NEED_CPU_BOTH
index 1857e1f7604075f74c58e2b695e099dc18512daf..fffc9da114fac02ca5d81d9615615defeca32013 100644 (file)
@@ -32,11 +32,14 @@ IFUNC_SELECTOR (void)
 {
   const struct cpu_features* cpu_features = __get_cpu_features ();
 
-  if (CPU_FEATURES_ARCH_P (cpu_features, AVX512DQ_Usable))
-    return OPTIMIZE (skx);
-
-  if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable))
-    return OPTIMIZE (knl);
+  if (!CPU_FEATURES_ARCH_P (cpu_features, MathVec_Prefer_No_AVX512))
+    {
+      if (CPU_FEATURES_ARCH_P (cpu_features, AVX512DQ_Usable))
+       return OPTIMIZE (skx);
+
+      if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable))
+       return OPTIMIZE (knl);
+    }
 
   return OPTIMIZE (avx2_wrapper);
 }