]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: Set Prefer_No_VZEROUPPER and add Prefer_AVX2_STRCMP
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 26 Feb 2021 13:36:59 +0000 (05:36 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 27 Jan 2022 20:47:19 +0000 (12:47 -0800)
1. Set Prefer_No_VZEROUPPER if RTM is usable to avoid RTM abort triggered
by VZEROUPPER inside a transactionally executing RTM region.
2. Since to compare 2 32-byte strings, 256-bit EVEX strcmp requires 2
loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp requires 1 load, 2 VPCMPEQs,
1 VPMINU and 1 VPMOVMSKB, AVX2 strcmp is faster than EVEX strcmp.  Add
Prefer_AVX2_STRCMP to prefer AVX2 strcmp family functions.

(cherry picked from commit 1da50d4bda07f04135dca39f40e79fc9eabed1f8)

sysdeps/x86/cpu-features.c
sysdeps/x86/cpu-features.h
sysdeps/x86/cpu-tunables.c

index 4695ac80d414832783dccf12451c414b83b2e3d1..5ddc8eebf441b8ffa250f51977fb14d5564ee0df 100644 (file)
@@ -347,8 +347,24 @@ init_cpu_features (struct cpu_features *cpu_features)
        cpu_features->feature[index_arch_Prefer_No_VZEROUPPER]
          |= bit_arch_Prefer_No_VZEROUPPER;
       else
-       cpu_features->feature[index_arch_Prefer_No_AVX512]
-         |= bit_arch_Prefer_No_AVX512;
+       {
+         cpu_features->feature[index_arch_Prefer_No_AVX512]
+           |= bit_arch_Prefer_No_AVX512;
+
+         /* Avoid RTM abort triggered by VZEROUPPER inside a
+            transactionally executing RTM region.  */
+         if (CPU_FEATURES_CPU_P (cpu_features, RTM))
+           cpu_features->feature[index_arch_Prefer_No_VZEROUPPER]
+             |= bit_arch_Prefer_No_VZEROUPPER;
+
+         /* Since to compare 2 32-byte strings, 256-bit EVEX strcmp
+            requires 2 loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp
+            requires 1 load, 2 VPCMPEQs, 1 VPMINU and 1 VPMOVMSKB,
+            AVX2 strcmp is faster than EVEX strcmp.  */
+         if (CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable))
+           cpu_features->feature[index_arch_Prefer_AVX2_STRCMP]
+             |= bit_arch_Prefer_AVX2_STRCMP;
+       }
     }
   /* This spells out "AuthenticAMD".  */
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
index 347a4b118d007fd8f6ae09253b984c3cc747eda1..1f60296e7b65f3bb2091ffc111ae1a619a38ab8b 100644 (file)
@@ -41,6 +41,7 @@
 #define bit_arch_MathVec_Prefer_No_AVX512      (1 << 21)
 #define bit_arch_XSAVEC_Usable                 (1 << 22)
 #define bit_arch_Prefer_FSRM                   (1 << 23)
+#define bit_arch_Prefer_AVX2_STRCMP            (1 << 24)
 
 /* CPUID Feature flags.  */
 
@@ -266,6 +267,7 @@ extern const struct cpu_features *__get_cpu_features (void)
 # define index_arch_MathVec_Prefer_No_AVX512 FEATURE_INDEX_1
 # define index_arch_XSAVEC_Usable      FEATURE_INDEX_1
 # define index_arch_Prefer_FSRM                FEATURE_INDEX_1
+# define index_arch_Prefer_AVX2_STRCMP FEATURE_INDEX_1
 
 #endif /* !__ASSEMBLER__ */
 
index 69155a8f44812c4e104d1d630cecc8857fe85323..824ee76b1aab7d03cb01eaf0ddc08fd085abc3f1 100644 (file)
@@ -282,6 +282,9 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
              CHECK_GLIBC_IFUNC_ARCH_BOTH (n, cpu_features,
                                           Fast_Copy_Backward, disable,
                                           18);
+             CHECK_GLIBC_IFUNC_ARCH_NEED_ARCH_BOTH
+               (n, cpu_features, Prefer_AVX2_STRCMP, AVX2_Usable,
+                disable, 18);
            }
          break;
        case 19: