190885
From 18a0eba6e84524e3a1cbb544ed1f53dce9531b46 Mon Sep 17 00:00:00 2001
190885
From: "H.J. Lu" <hjl.tools@gmail.com>
190885
Date: Wed, 2 Mar 2022 12:52:23 -0800
190885
Subject: [PATCH] x86: Set Prefer_No_VZEROUPPER and add Prefer_AVX2_STRCMP
190885
190885
1. Set Prefer_No_VZEROUPPER if RTM is usable to avoid RTM abort triggered
190885
by VZEROUPPER inside a transactionally executing RTM region.
190885
2. Since to compare 2 32-byte strings, 256-bit EVEX strcmp requires 2
190885
loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp requires 1 load, 2 VPCMPEQs,
190885
1 VPMINU and 1 VPMOVMSKB, AVX2 strcmp is faster than EVEX strcmp.  Add
190885
Prefer_AVX2_STRCMP to prefer AVX2 strcmp family functions.
190885
190885
(cherry picked from commit 1da50d4bda07f04135dca39f40e79fc9eabed1f8)
190885
---
190885
 sysdeps/x86/cpu-features.c                    | 20 +++++++++++++++++--
190885
 sysdeps/x86/cpu-tunables.c                    |  2 ++
190885
 ...cpu-features-preferred_feature_index_1.def |  1 +
190885
 3 files changed, 21 insertions(+), 2 deletions(-)
190885
190885
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
190885
index 91042505..3610ee5c 100644
190885
--- a/sysdeps/x86/cpu-features.c
190885
+++ b/sysdeps/x86/cpu-features.c
190885
@@ -524,8 +524,24 @@ init_cpu_features (struct cpu_features *cpu_features)
190885
 	cpu_features->preferred[index_arch_Prefer_No_VZEROUPPER]
190885
 	  |= bit_arch_Prefer_No_VZEROUPPER;
190885
       else
190885
-	cpu_features->preferred[index_arch_Prefer_No_AVX512]
190885
-	  |= bit_arch_Prefer_No_AVX512;
190885
+	{
190885
+	  cpu_features->preferred[index_arch_Prefer_No_AVX512]
190885
+	    |= bit_arch_Prefer_No_AVX512;
190885
+
190885
+	  /* Avoid RTM abort triggered by VZEROUPPER inside a
190885
+	     transactionally executing RTM region.  */
190885
+	  if (CPU_FEATURE_USABLE_P (cpu_features, RTM))
190885
+	    cpu_features->preferred[index_arch_Prefer_No_VZEROUPPER]
190885
+	      |= bit_arch_Prefer_No_VZEROUPPER;
190885
+
190885
+	  /* Since to compare 2 32-byte strings, 256-bit EVEX strcmp
190885
+	     requires 2 loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp
190885
+	     requires 1 load, 2 VPCMPEQs, 1 VPMINU and 1 VPMOVMSKB,
190885
+	     AVX2 strcmp is faster than EVEX strcmp.  */
190885
+	  if (CPU_FEATURE_USABLE_P (cpu_features, AVX2))
190885
+	    cpu_features->preferred[index_arch_Prefer_AVX2_STRCMP]
190885
+	      |= bit_arch_Prefer_AVX2_STRCMP;
190885
+	}
190885
     }
190885
   /* This spells out "AuthenticAMD".  */
190885
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
190885
diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
190885
index 3173b2b9..73adbaba 100644
190885
--- a/sysdeps/x86/cpu-tunables.c
190885
+++ b/sysdeps/x86/cpu-tunables.c
190885
@@ -239,6 +239,8 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
190885
 	      CHECK_GLIBC_IFUNC_PREFERRED_BOTH (n, cpu_features,
190885
 						Fast_Copy_Backward,
190885
 						disable, 18);
190885
+	      CHECK_GLIBC_IFUNC_PREFERRED_NEED_BOTH
190885
+		(n, cpu_features, Prefer_AVX2_STRCMP, AVX2, disable, 18);
190885
 	    }
190885
 	  break;
190885
 	case 19:
190885
diff --git a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
190885
index 17a5cc42..4ca70b40 100644
190885
--- a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
190885
+++ b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
190885
@@ -32,3 +32,4 @@ BIT (Prefer_ERMS)
190885
 BIT (Prefer_FSRM)
190885
 BIT (Prefer_No_AVX512)
190885
 BIT (MathVec_Prefer_No_AVX512)
190885
+BIT (Prefer_AVX2_STRCMP)
190885
-- 
190885
GitLab
190885