Blame SOURCES/0008-only-avoid-short-distance-rep-mobsb-on-icx.patch

3c8a07
From 0058b10814afd8f1ea031b11f3c4ac226fa60d79 Mon Sep 17 00:00:00 2001
3c8a07
From: Wangyang Guo <wangyang.guo@intel.com>
3c8a07
Date: Mon, 24 Jan 2022 02:59:56 +0000
3c8a07
Subject: [PATCH] Only avoid short distance REP MOVSB on ICX
3c8a07
3c8a07
---
3c8a07
 sysdeps/x86/cacheinfo.h                                  | 9 +++++++++
3c8a07
 sysdeps/x86/cpu-features.c                               | 5 +++++
3c8a07
 .../include/cpu-features-preferred_feature_index_1.def   | 1 +
3c8a07
 sysdeps/x86/sysdep.h                                     | 3 +++
3c8a07
 sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S    | 5 +++++
3c8a07
 5 files changed, 23 insertions(+)
3c8a07
3c8a07
diff --git a/sysdeps/x86/cacheinfo.h b/sysdeps/x86/cacheinfo.h
3c8a07
index 02556961..7af8575d 100644
3c8a07
--- a/sysdeps/x86/cacheinfo.h
3c8a07
+++ b/sysdeps/x86/cacheinfo.h
3c8a07
@@ -45,6 +45,11 @@ long int __x86_rep_movsb_threshold attribute_hidden = 2048;
3c8a07
 /* Threshold to use Enhanced REP STOSB.  */
3c8a07
 long int __x86_rep_stosb_threshold attribute_hidden = 2048;
3c8a07
 
3c8a07
+/* Non-zero to avoid short distance REP MOVSB.  */
3c8a07
+//int __x86_avoid_short_distance_rep_movsb attribute_hidden;
3c8a07
+/* String/memory function control.  */
3c8a07
+int __x86_string_control attribute_hidden;
3c8a07
+
3c8a07
 static void
3c8a07
 get_common_cache_info (long int *shared_ptr, unsigned int *threads_ptr,
3c8a07
 		       long int core)
3c8a07
@@ -421,6 +426,10 @@ init_cacheinfo (void)
3c8a07
   else
3c8a07
     __x86_rep_movsb_threshold = rep_movsb_threshold;
3c8a07
 
3c8a07
+  if (CPU_FEATURES_ARCH_P (cpu_features, Avoid_Short_Distance_REP_MOVSB))
3c8a07
+    __x86_string_control
3c8a07
+      |= X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB;
3c8a07
+
3c8a07
 # if HAVE_TUNABLES
3c8a07
   __x86_rep_stosb_threshold = cpu_features->rep_stosb_threshold;
3c8a07
 # endif
3c8a07
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
3c8a07
index 91042505..22b45c72 100644
3c8a07
--- a/sysdeps/x86/cpu-features.c
3c8a07
+++ b/sysdeps/x86/cpu-features.c
3c8a07
@@ -526,6 +526,11 @@ init_cpu_features (struct cpu_features *cpu_features)
3c8a07
       else
3c8a07
 	cpu_features->preferred[index_arch_Prefer_No_AVX512]
3c8a07
 	  |= bit_arch_Prefer_No_AVX512;
3c8a07
+
3c8a07
+      /* Avoid avoid short distance REP MOVSB on processor with FSRM.  */
3c8a07
+      if (CPU_FEATURES_CPU_P (cpu_features, FSRM))
3c8a07
+	cpu_features->preferred[index_arch_Avoid_Short_Distance_REP_MOVSB]
3c8a07
+	  |= bit_arch_Avoid_Short_Distance_REP_MOVSB;
3c8a07
     }
3c8a07
   /* This spells out "AuthenticAMD".  */
3c8a07
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
3c8a07
diff --git a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
3c8a07
index 17a5cc42..e7277b33 100644
3c8a07
--- a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
3c8a07
+++ b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
3c8a07
@@ -32,3 +32,4 @@ BIT (Prefer_ERMS)
3c8a07
 BIT (Prefer_FSRM)
3c8a07
 BIT (Prefer_No_AVX512)
3c8a07
 BIT (MathVec_Prefer_No_AVX512)
3c8a07
+BIT (Avoid_Short_Distance_REP_MOVSB)
3c8a07
diff --git a/sysdeps/x86/sysdep.h b/sysdeps/x86/sysdep.h
3c8a07
index f41f4ebd..4ac93a95 100644
3c8a07
--- a/sysdeps/x86/sysdep.h
3c8a07
+++ b/sysdeps/x86/sysdep.h
3c8a07
@@ -57,6 +57,9 @@ enum cf_protection_level
3c8a07
 #define STATE_SAVE_MASK \
3c8a07
   ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7))
3c8a07
 
3c8a07
+/* Avoid short distance REP MOVSB.  */
3c8a07
+#define X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB      (1 << 0)
3c8a07
+
3c8a07
 #ifdef	__ASSEMBLER__
3c8a07
 
3c8a07
 /* Syntactic details of assembler.  */
3c8a07
diff --git a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
3c8a07
index 07299dc0..4aa65555 100644
3c8a07
--- a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
3c8a07
+++ b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
3c8a07
@@ -244,12 +244,16 @@ L(movsb):
3c8a07
 	/* Avoid slow backward REP MOVSB.  */
3c8a07
 	jb	L(more_8x_vec_backward)
3c8a07
 # if AVOID_SHORT_DISTANCE_REP_MOVSB
3c8a07
+	andl    $X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB, __x86_string_control(%rip)
3c8a07
+	jz	3f
3c8a07
 	movq	%rdi, %rcx
3c8a07
 	subq	%rsi, %rcx
3c8a07
 	jmp	2f
3c8a07
 # endif
3c8a07
 1:
3c8a07
 # if AVOID_SHORT_DISTANCE_REP_MOVSB
3c8a07
+	andl    $X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB, __x86_string_control(%rip)
3c8a07
+	jz	3f
3c8a07
 	movq	%rsi, %rcx
3c8a07
 	subq	%rdi, %rcx
3c8a07
 2:
3c8a07
@@ -257,6 +261,7 @@ L(movsb):
3c8a07
    is N*4GB + [1..63] with N >= 0.  */
3c8a07
 	cmpl	$63, %ecx
3c8a07
 	jbe	L(more_2x_vec)	/* Avoid "rep movsb" if ECX <= 63.  */
3c8a07
+3:
3c8a07
 # endif
3c8a07
 	movq	%rdx, %rcx
3c8a07
 	rep movsb
3c8a07
-- 
3c8a07
2.27.0
3c8a07