513694
From 94783c6e57638122cefe4e02342c7fafc3cf09f0 Mon Sep 17 00:00:00 2001
513694
From: "H.J. Lu" <hjl.tools@gmail.com>
513694
Date: Mon, 7 Feb 2022 05:55:15 -0800
513694
Subject: [PATCH] x86-64: Optimize bzero
513694
513694
Add OPTIMIZE1 and OPTIMIZE2 in ifunc-init.h file.
513694
Remove memcmpeq implementation from Makefile.
513694
513694
memset with zero as the value to set is by far the majority value (99%+
513694
for Python3 and GCC).
513694
513694
bzero can be slightly more optimized for this case by using a zero-idiom
513694
xor for broadcasting the set value to a register (vector or GPR).
513694
513694
Co-developed-by: Noah Goldstein <goldstein.w.n@gmail.com>
513694
(cherry picked from commit 3d9f171bfb5325bd5f427e9fc386453358c6e840)
513694
---
513694
 sysdeps/generic/ifunc-init.h                  |   5 +-
513694
 sysdeps/x86_64/memset.S                       |   8 +
513694
 sysdeps/x86_64/multiarch/Makefile             | 205 +++++++++++-------
513694
 sysdeps/x86_64/multiarch/bzero.c              | 106 +++++++++
513694
 sysdeps/x86_64/multiarch/ifunc-impl-list.c    |  42 ++++
513694
 .../memset-avx2-unaligned-erms-rtm.S          |   1 +
513694
 .../multiarch/memset-avx2-unaligned-erms.S    |   6 +
513694
 .../multiarch/memset-avx512-unaligned-erms.S  |   3 +
513694
 .../multiarch/memset-evex-unaligned-erms.S    |   3 +
513694
 .../multiarch/memset-sse2-unaligned-erms.S    |   1 +
513694
 .../multiarch/memset-vec-unaligned-erms.S     | 110 +++++++---
513694
 11 files changed, 384 insertions(+), 106 deletions(-)
513694
 create mode 100644 sysdeps/x86_64/multiarch/bzero.c
513694
513694
diff --git a/sysdeps/generic/ifunc-init.h b/sysdeps/generic/ifunc-init.h
513694
index 241e4161..f7a72375 100644
513694
--- a/sysdeps/generic/ifunc-init.h
513694
+++ b/sysdeps/generic/ifunc-init.h
513694
@@ -50,5 +50,8 @@
513694
    '__<symbol>_<variant>' as the optimized implementation and
513694
    '<symbol>_ifunc_selector' as the IFUNC selector.  */
513694
 #define REDIRECT_NAME	EVALUATOR1 (__redirect, SYMBOL_NAME)
513694
-#define OPTIMIZE(name)	EVALUATOR2 (SYMBOL_NAME, name)
513694
+#define OPTIMIZE1(name)	EVALUATOR1 (SYMBOL_NAME, name)
513694
+#define OPTIMIZE2(name)	EVALUATOR2 (SYMBOL_NAME, name)
513694
+/* Default is to use OPTIMIZE2.  */
513694
+#define OPTIMIZE(name)	OPTIMIZE2(name)
513694
 #define IFUNC_SELECTOR	EVALUATOR1 (SYMBOL_NAME, ifunc_selector)
513694
diff --git a/sysdeps/x86_64/memset.S b/sysdeps/x86_64/memset.S
513694
index 4cb4aa71..a1353f89 100644
513694
--- a/sysdeps/x86_64/memset.S
513694
+++ b/sysdeps/x86_64/memset.S
513694
@@ -35,6 +35,9 @@
513694
   punpcklwd %xmm0, %xmm0; \
513694
   pshufd $0, %xmm0, %xmm0
513694
 
513694
+# define BZERO_ZERO_VEC0() \
513694
+  pxor %xmm0, %xmm0
513694
+
513694
 # define WMEMSET_SET_VEC0_AND_SET_RETURN(d, r) \
513694
   movd d, %xmm0; \
513694
   pshufd $0, %xmm0, %xmm0; \
513694
@@ -53,6 +56,10 @@
513694
 # define MEMSET_SYMBOL(p,s)	memset
513694
 #endif
513694
 
513694
+#ifndef BZERO_SYMBOL
513694
+# define BZERO_SYMBOL(p,s)	__bzero
513694
+#endif
513694
+
513694
 #ifndef WMEMSET_SYMBOL
513694
 # define WMEMSET_CHK_SYMBOL(p,s) p
513694
 # define WMEMSET_SYMBOL(p,s)	__wmemset
513694
@@ -63,6 +70,7 @@
513694
 libc_hidden_builtin_def (memset)
513694
 
513694
 #if IS_IN (libc)
513694
+weak_alias (__bzero, bzero)
513694
 libc_hidden_def (__wmemset)
513694
 weak_alias (__wmemset, wmemset)
513694
 libc_hidden_weak (wmemset)
513694
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
513694
index 26be4095..37d8d6f0 100644
513694
--- a/sysdeps/x86_64/multiarch/Makefile
513694
+++ b/sysdeps/x86_64/multiarch/Makefile
513694
@@ -1,85 +1,130 @@
513694
 ifeq ($(subdir),string)
513694
 
513694
-sysdep_routines += strncat-c stpncpy-c strncpy-c \
513694
-		   strcmp-sse2 strcmp-sse2-unaligned strcmp-ssse3  \
513694
-		   strcmp-sse4_2 strcmp-avx2 \
513694
-		   strncmp-sse2 strncmp-ssse3 strncmp-sse4_2 strncmp-avx2 \
513694
-		   memchr-sse2 rawmemchr-sse2 memchr-avx2 rawmemchr-avx2 \
513694
-		   memrchr-sse2 memrchr-avx2 \
513694
-		   memcmp-sse2 \
513694
-		   memcmp-avx2-movbe \
513694
-		   memcmp-sse4 memcpy-ssse3 \
513694
-		   memmove-ssse3 \
513694
-		   memcpy-ssse3-back \
513694
-		   memmove-ssse3-back \
513694
-		   memmove-avx512-no-vzeroupper \
513694
-		   strcasecmp_l-sse2 strcasecmp_l-ssse3 \
513694
-		   strcasecmp_l-sse4_2 strcasecmp_l-avx \
513694
-		   strncase_l-sse2 strncase_l-ssse3 \
513694
-		   strncase_l-sse4_2 strncase_l-avx \
513694
-		   strchr-sse2 strchrnul-sse2 strchr-avx2 strchrnul-avx2 \
513694
-		   strrchr-sse2 strrchr-avx2 \
513694
-		   strlen-sse2 strnlen-sse2 strlen-avx2 strnlen-avx2 \
513694
-		   strcat-avx2 strncat-avx2 \
513694
-		   strcat-ssse3 strncat-ssse3\
513694
-		   strcpy-avx2 strncpy-avx2 \
513694
-		   strcpy-sse2 stpcpy-sse2 \
513694
-		   strcpy-ssse3 strncpy-ssse3 stpcpy-ssse3 stpncpy-ssse3 \
513694
-		   strcpy-sse2-unaligned strncpy-sse2-unaligned \
513694
-		   stpcpy-sse2-unaligned stpncpy-sse2-unaligned \
513694
-		   stpcpy-avx2 stpncpy-avx2 \
513694
-		   strcat-sse2 \
513694
-		   strcat-sse2-unaligned strncat-sse2-unaligned \
513694
-		   strchr-sse2-no-bsf memcmp-ssse3 strstr-sse2-unaligned \
513694
-		   strcspn-sse2 strpbrk-sse2 strspn-sse2 \
513694
-		   strcspn-c strpbrk-c strspn-c varshift \
513694
-		   memset-avx512-no-vzeroupper \
513694
-		   memmove-sse2-unaligned-erms \
513694
-		   memmove-avx-unaligned-erms \
513694
-		   memmove-avx512-unaligned-erms \
513694
-		   memset-sse2-unaligned-erms \
513694
-		   memset-avx2-unaligned-erms \
513694
-		   memset-avx512-unaligned-erms \
513694
-		   memchr-avx2-rtm \
513694
-		   memcmp-avx2-movbe-rtm \
513694
-		   memmove-avx-unaligned-erms-rtm \
513694
-		   memrchr-avx2-rtm \
513694
-		   memset-avx2-unaligned-erms-rtm \
513694
-		   rawmemchr-avx2-rtm \
513694
-		   strchr-avx2-rtm \
513694
-		   strcmp-avx2-rtm \
513694
-		   strchrnul-avx2-rtm \
513694
-		   stpcpy-avx2-rtm \
513694
-		   stpncpy-avx2-rtm \
513694
-		   strcat-avx2-rtm \
513694
-		   strcpy-avx2-rtm \
513694
-		   strlen-avx2-rtm \
513694
-		   strncat-avx2-rtm \
513694
-		   strncmp-avx2-rtm \
513694
-		   strncpy-avx2-rtm \
513694
-		   strnlen-avx2-rtm \
513694
-		   strrchr-avx2-rtm \
513694
-		   memchr-evex \
513694
-		   memcmp-evex-movbe \
513694
-		   memmove-evex-unaligned-erms \
513694
-		   memrchr-evex \
513694
-		   memset-evex-unaligned-erms \
513694
-		   rawmemchr-evex \
513694
-		   stpcpy-evex \
513694
-		   stpncpy-evex \
513694
-		   strcat-evex \
513694
-		   strchr-evex \
513694
-		   strchrnul-evex \
513694
-		   strcmp-evex \
513694
-		   strcpy-evex \
513694
-		   strlen-evex \
513694
-		   strncat-evex \
513694
-		   strncmp-evex \
513694
-		   strncpy-evex \
513694
-		   strnlen-evex \
513694
-		   strrchr-evex \
513694
-		   memchr-evex-rtm \
513694
-		   rawmemchr-evex-rtm
513694
+sysdep_routines += \
513694
+  bzero \
513694
+  memchr-avx2 \
513694
+  memchr-avx2-rtm \
513694
+  memchr-evex \
513694
+  memchr-evex-rtm \
513694
+  memchr-sse2 \
513694
+  memcmp-avx2-movbe \
513694
+  memcmp-avx2-movbe-rtm \
513694
+  memcmp-evex-movbe \
513694
+  memcmp-sse2 \
513694
+  memcmp-sse4 \
513694
+  memcmp-ssse3 \
513694
+  memcpy-ssse3 \
513694
+  memcpy-ssse3-back \
513694
+  memmove-avx-unaligned-erms \
513694
+  memmove-avx-unaligned-erms-rtm \
513694
+  memmove-avx512-no-vzeroupper \
513694
+  memmove-avx512-unaligned-erms \
513694
+  memmove-evex-unaligned-erms \
513694
+  memmove-sse2-unaligned-erms \
513694
+  memmove-ssse3 \
513694
+  memmove-ssse3-back \
513694
+  memrchr-avx2 \
513694
+  memrchr-avx2-rtm \
513694
+  memrchr-evex \
513694
+  memrchr-sse2 \
513694
+  memset-avx2-unaligned-erms \
513694
+  memset-avx2-unaligned-erms-rtm \
513694
+  memset-avx512-no-vzeroupper \
513694
+  memset-avx512-unaligned-erms \
513694
+  memset-evex-unaligned-erms \
513694
+  memset-sse2-unaligned-erms \
513694
+  rawmemchr-avx2 \
513694
+  rawmemchr-avx2-rtm \
513694
+  rawmemchr-evex \
513694
+  rawmemchr-evex-rtm \
513694
+  rawmemchr-sse2 \
513694
+  stpcpy-avx2 \
513694
+  stpcpy-avx2-rtm \
513694
+  stpcpy-evex \
513694
+  stpcpy-sse2 \
513694
+  stpcpy-sse2-unaligned \
513694
+  stpcpy-ssse3 \
513694
+  stpncpy-avx2 \
513694
+  stpncpy-avx2-rtm \
513694
+  stpncpy-c \
513694
+  stpncpy-evex \
513694
+  stpncpy-sse2-unaligned \
513694
+  stpncpy-ssse3 \
513694
+  strcasecmp_l-avx \
513694
+  strcasecmp_l-sse2 \
513694
+  strcasecmp_l-sse4_2 \
513694
+  strcasecmp_l-ssse3 \
513694
+  strcat-avx2 \
513694
+  strcat-avx2-rtm \
513694
+  strcat-evex \
513694
+  strcat-sse2 \
513694
+  strcat-sse2-unaligned \
513694
+  strcat-ssse3 \
513694
+  strchr-avx2 \
513694
+  strchr-avx2-rtm \
513694
+  strchr-evex \
513694
+  strchr-sse2 \
513694
+  strchr-sse2-no-bsf \
513694
+  strchrnul-avx2 \
513694
+  strchrnul-avx2-rtm \
513694
+  strchrnul-evex \
513694
+  strchrnul-sse2 \
513694
+  strcmp-avx2 \
513694
+  strcmp-avx2-rtm \
513694
+  strcmp-evex \
513694
+  strcmp-sse2 \
513694
+  strcmp-sse2-unaligned \
513694
+  strcmp-sse4_2 \
513694
+  strcmp-ssse3 \
513694
+  strcpy-avx2 \
513694
+  strcpy-avx2-rtm \
513694
+  strcpy-evex \
513694
+  strcpy-sse2 \
513694
+  strcpy-sse2-unaligned \
513694
+  strcpy-ssse3 \
513694
+  strcspn-c \
513694
+  strcspn-sse2 \
513694
+  strlen-avx2 \
513694
+  strlen-avx2-rtm \
513694
+  strlen-evex \
513694
+  strlen-sse2 \
513694
+  strncase_l-avx \
513694
+  strncase_l-sse2 \
513694
+  strncase_l-sse4_2 \
513694
+  strncase_l-ssse3 \
513694
+  strncat-avx2 \
513694
+  strncat-avx2-rtm \
513694
+  strncat-c \
513694
+  strncat-evex \
513694
+  strncat-sse2-unaligned \
513694
+  strncat-ssse3 \
513694
+  strncmp-avx2 \
513694
+  strncmp-avx2-rtm \
513694
+  strncmp-evex \
513694
+  strncmp-sse2 \
513694
+  strncmp-sse4_2 \
513694
+  strncmp-ssse3 \
513694
+  strncpy-avx2 \
513694
+  strncpy-avx2-rtm \
513694
+  strncpy-c \
513694
+  strncpy-evex \
513694
+  strncpy-sse2-unaligned \
513694
+  strncpy-ssse3 \
513694
+  strnlen-avx2 \
513694
+  strnlen-avx2-rtm \
513694
+  strnlen-evex \
513694
+  strnlen-sse2 \
513694
+  strpbrk-c \
513694
+  strpbrk-sse2 \
513694
+  strrchr-avx2 \
513694
+  strrchr-avx2-rtm \
513694
+  strrchr-evex \
513694
+  strrchr-sse2 \
513694
+  strspn-c \
513694
+  strspn-sse2 \
513694
+  strstr-sse2-unaligned \
513694
+  varshift \
513694
+# sysdep_routines
513694
 CFLAGS-varshift.c += -msse4
513694
 CFLAGS-strcspn-c.c += -msse4
513694
 CFLAGS-strpbrk-c.c += -msse4
513694
diff --git a/sysdeps/x86_64/multiarch/bzero.c b/sysdeps/x86_64/multiarch/bzero.c
513694
new file mode 100644
513694
index 00000000..58a14b2c
513694
--- /dev/null
513694
+++ b/sysdeps/x86_64/multiarch/bzero.c
513694
@@ -0,0 +1,106 @@
513694
+/* Multiple versions of bzero.
513694
+   All versions must be listed in ifunc-impl-list.c.
513694
+   Copyright (C) 2022 Free Software Foundation, Inc.
513694
+   This file is part of the GNU C Library.
513694
+
513694
+   The GNU C Library is free software; you can redistribute it and/or
513694
+   modify it under the terms of the GNU Lesser General Public
513694
+   License as published by the Free Software Foundation; either
513694
+   version 2.1 of the License, or (at your option) any later version.
513694
+
513694
+   The GNU C Library is distributed in the hope that it will be useful,
513694
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
513694
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
513694
+   Lesser General Public License for more details.
513694
+
513694
+   You should have received a copy of the GNU Lesser General Public
513694
+   License along with the GNU C Library; if not, see
513694
+   <https://www.gnu.org/licenses/>.  */
513694
+
513694
+/* Define multiple versions only for the definition in libc.  */
513694
+#if IS_IN (libc)
513694
+# define __bzero __redirect___bzero
513694
+# include <string.h>
513694
+# undef __bzero
513694
+
513694
+# define SYMBOL_NAME __bzero
513694
+# include <init-arch.h>
513694
+
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (sse2_unaligned)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (sse2_unaligned_erms)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned) attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned_erms)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned_rtm)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned_erms_rtm)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (evex_unaligned)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (evex_unaligned_erms)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx512_unaligned)
513694
+  attribute_hidden;
513694
+extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx512_unaligned_erms)
513694
+  attribute_hidden;
513694
+
513694
+static inline void *
513694
+IFUNC_SELECTOR (void)
513694
+{
513694
+  const struct cpu_features* cpu_features = __get_cpu_features ();
513694
+
513694
+  if (CPU_FEATURE_USABLE_P (cpu_features, AVX512F)
513694
+      && !CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_AVX512))
513694
+    {
513694
+      if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
513694
+          && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW)
513694
+          && CPU_FEATURE_USABLE_P (cpu_features, BMI2))
513694
+	{
513694
+	  if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
513694
+	    return OPTIMIZE1 (avx512_unaligned_erms);
513694
+
513694
+	  return OPTIMIZE1 (avx512_unaligned);
513694
+	}
513694
+    }
513694
+
513694
+  if (CPU_FEATURE_USABLE_P (cpu_features, AVX2))
513694
+    {
513694
+      if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
513694
+          && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW)
513694
+          && CPU_FEATURE_USABLE_P (cpu_features, BMI2))
513694
+	{
513694
+	  if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
513694
+	    return OPTIMIZE1 (evex_unaligned_erms);
513694
+
513694
+	  return OPTIMIZE1 (evex_unaligned);
513694
+	}
513694
+
513694
+      if (CPU_FEATURE_USABLE_P (cpu_features, RTM))
513694
+	{
513694
+	  if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
513694
+	    return OPTIMIZE1 (avx2_unaligned_erms_rtm);
513694
+
513694
+	  return OPTIMIZE1 (avx2_unaligned_rtm);
513694
+	}
513694
+
513694
+      if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER))
513694
+	{
513694
+	  if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
513694
+	    return OPTIMIZE1 (avx2_unaligned_erms);
513694
+
513694
+	  return OPTIMIZE1 (avx2_unaligned);
513694
+	}
513694
+    }
513694
+
513694
+  if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
513694
+    return OPTIMIZE1 (sse2_unaligned_erms);
513694
+
513694
+  return OPTIMIZE1 (sse2_unaligned);
513694
+}
513694
+
513694
+libc_ifunc_redirected (__redirect___bzero, __bzero, IFUNC_SELECTOR ());
513694
+
513694
+weak_alias (__bzero, bzero)
513694
+#endif
513694
diff --git a/sysdeps/x86_64/multiarch/ifunc-impl-list.c b/sysdeps/x86_64/multiarch/ifunc-impl-list.c
513694
index 8be0d78a..c963d391 100644
513694
--- a/sysdeps/x86_64/multiarch/ifunc-impl-list.c
513694
+++ b/sysdeps/x86_64/multiarch/ifunc-impl-list.c
513694
@@ -282,6 +282,48 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
513694
 			      __memset_avx512_no_vzeroupper)
513694
 	     )
513694
 
513694
+  /* Support sysdeps/x86_64/multiarch/bzero.c.  */
513694
+  IFUNC_IMPL (i, name, bzero,
513694
+	      IFUNC_IMPL_ADD (array, i, bzero, 1,
513694
+			      __bzero_sse2_unaligned)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero, 1,
513694
+			      __bzero_sse2_unaligned_erms)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      CPU_FEATURE_USABLE (AVX2),
513694
+			      __bzero_avx2_unaligned)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      CPU_FEATURE_USABLE (AVX2),
513694
+			      __bzero_avx2_unaligned_erms)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      (CPU_FEATURE_USABLE (AVX2)
513694
+			       && CPU_FEATURE_USABLE (RTM)),
513694
+			      __bzero_avx2_unaligned_rtm)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      (CPU_FEATURE_USABLE (AVX2)
513694
+			       && CPU_FEATURE_USABLE (RTM)),
513694
+			      __bzero_avx2_unaligned_erms_rtm)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      (CPU_FEATURE_USABLE (AVX512VL)
513694
+			       && CPU_FEATURE_USABLE (AVX512BW)
513694
+			       && CPU_FEATURE_USABLE (BMI2)),
513694
+			      __bzero_evex_unaligned)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      (CPU_FEATURE_USABLE (AVX512VL)
513694
+			       && CPU_FEATURE_USABLE (AVX512BW)
513694
+			       && CPU_FEATURE_USABLE (BMI2)),
513694
+			      __bzero_evex_unaligned_erms)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      (CPU_FEATURE_USABLE (AVX512VL)
513694
+			       && CPU_FEATURE_USABLE (AVX512BW)
513694
+			       && CPU_FEATURE_USABLE (BMI2)),
513694
+			      __bzero_avx512_unaligned_erms)
513694
+	      IFUNC_IMPL_ADD (array, i, bzero,
513694
+			      (CPU_FEATURE_USABLE (AVX512VL)
513694
+			       && CPU_FEATURE_USABLE (AVX512BW)
513694
+			       && CPU_FEATURE_USABLE (BMI2)),
513694
+			      __bzero_avx512_unaligned)
513694
+	     )
513694
+
513694
   /* Support sysdeps/x86_64/multiarch/rawmemchr.c.  */
513694
   IFUNC_IMPL (i, name, rawmemchr,
513694
 	      IFUNC_IMPL_ADD (array, i, rawmemchr,
513694
diff --git a/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms-rtm.S b/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms-rtm.S
513694
index 8ac3e479..5a5ee6f6 100644
513694
--- a/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms-rtm.S
513694
+++ b/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms-rtm.S
513694
@@ -5,6 +5,7 @@
513694
 
513694
 #define SECTION(p) p##.avx.rtm
513694
 #define MEMSET_SYMBOL(p,s)	p##_avx2_##s##_rtm
513694
+#define BZERO_SYMBOL(p,s)	p##_avx2_##s##_rtm
513694
 #define WMEMSET_SYMBOL(p,s)	p##_avx2_##s##_rtm
513694
 
513694
 #include "memset-avx2-unaligned-erms.S"
513694
diff --git a/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms.S
513694
index c0bf2875..a093a283 100644
513694
--- a/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms.S
513694
+++ b/sysdeps/x86_64/multiarch/memset-avx2-unaligned-erms.S
513694
@@ -14,6 +14,9 @@
513694
   vmovd d, %xmm0; \
513694
   movq r, %rax;
513694
 
513694
+# define BZERO_ZERO_VEC0() \
513694
+  vpxor %xmm0, %xmm0, %xmm0
513694
+
513694
 # define WMEMSET_SET_VEC0_AND_SET_RETURN(d, r) \
513694
   MEMSET_SET_VEC0_AND_SET_RETURN(d, r)
513694
 
513694
@@ -29,6 +32,9 @@
513694
 # ifndef MEMSET_SYMBOL
513694
 #  define MEMSET_SYMBOL(p,s)	p##_avx2_##s
513694
 # endif
513694
+# ifndef BZERO_SYMBOL
513694
+#  define BZERO_SYMBOL(p,s)	p##_avx2_##s
513694
+# endif
513694
 # ifndef WMEMSET_SYMBOL
513694
 #  define WMEMSET_SYMBOL(p,s)	p##_avx2_##s
513694
 # endif
513694
diff --git a/sysdeps/x86_64/multiarch/memset-avx512-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-avx512-unaligned-erms.S
513694
index 5241216a..727c9213 100644
513694
--- a/sysdeps/x86_64/multiarch/memset-avx512-unaligned-erms.S
513694
+++ b/sysdeps/x86_64/multiarch/memset-avx512-unaligned-erms.S
513694
@@ -19,6 +19,9 @@
513694
   vpbroadcastb d, %VEC0; \
513694
   movq r, %rax
513694
 
513694
+# define BZERO_ZERO_VEC0() \
513694
+  vpxorq %XMM0, %XMM0, %XMM0
513694
+
513694
 # define WMEMSET_SET_VEC0_AND_SET_RETURN(d, r) \
513694
   vpbroadcastd d, %VEC0; \
513694
   movq r, %rax
513694
diff --git a/sysdeps/x86_64/multiarch/memset-evex-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-evex-unaligned-erms.S
513694
index 63700215..5d8fa78f 100644
513694
--- a/sysdeps/x86_64/multiarch/memset-evex-unaligned-erms.S
513694
+++ b/sysdeps/x86_64/multiarch/memset-evex-unaligned-erms.S
513694
@@ -19,6 +19,9 @@
513694
   vpbroadcastb d, %VEC0; \
513694
   movq r, %rax
513694
 
513694
+# define BZERO_ZERO_VEC0() \
513694
+  vpxorq %XMM0, %XMM0, %XMM0
513694
+
513694
 # define WMEMSET_SET_VEC0_AND_SET_RETURN(d, r) \
513694
   vpbroadcastd d, %VEC0; \
513694
   movq r, %rax
513694
diff --git a/sysdeps/x86_64/multiarch/memset-sse2-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-sse2-unaligned-erms.S
513694
index 56b81f5c..8f579ad6 100644
513694
--- a/sysdeps/x86_64/multiarch/memset-sse2-unaligned-erms.S
513694
+++ b/sysdeps/x86_64/multiarch/memset-sse2-unaligned-erms.S
513694
@@ -22,6 +22,7 @@
513694
 
513694
 #if IS_IN (libc)
513694
 # define MEMSET_SYMBOL(p,s)	p##_sse2_##s
513694
+# define BZERO_SYMBOL(p,s)	MEMSET_SYMBOL (p, s)
513694
 # define WMEMSET_SYMBOL(p,s)	p##_sse2_##s
513694
 
513694
 # ifdef SHARED
513694
diff --git a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
513694
index a67f9833..06f5f5d7 100644
513694
--- a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
513694
+++ b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
513694
@@ -26,6 +26,10 @@
513694
 
513694
 #include <sysdep.h>
513694
 
513694
+#ifndef BZERO_SYMBOL
513694
+# define BZERO_SYMBOL(p,s)		MEMSET_SYMBOL (p, s)
513694
+#endif
513694
+
513694
 #ifndef MEMSET_CHK_SYMBOL
513694
 # define MEMSET_CHK_SYMBOL(p,s)		MEMSET_SYMBOL(p, s)
513694
 #endif
513694
@@ -87,6 +91,18 @@
513694
 # define XMM_SMALL	0
513694
 #endif
513694
 
513694
+#ifdef USE_LESS_VEC_MASK_STORE
513694
+# define SET_REG64	rcx
513694
+# define SET_REG32	ecx
513694
+# define SET_REG16	cx
513694
+# define SET_REG8	cl
513694
+#else
513694
+# define SET_REG64	rsi
513694
+# define SET_REG32	esi
513694
+# define SET_REG16	si
513694
+# define SET_REG8	sil
513694
+#endif
513694
+
513694
 #define PAGE_SIZE 4096
513694
 
513694
 /* Macro to calculate size of small memset block for aligning
513694
@@ -96,18 +112,6 @@
513694
 
513694
 #ifndef SECTION
513694
 # error SECTION is not defined!
513694
-#endif
513694
-
513694
-	.section SECTION(.text),"ax",@progbits
513694
-#if VEC_SIZE == 16 && IS_IN (libc)
513694
-ENTRY (__bzero)
513694
-	mov	%RDI_LP, %RAX_LP /* Set return value.  */
513694
-	mov	%RSI_LP, %RDX_LP /* Set n.  */
513694
-	xorl	%esi, %esi
513694
-	pxor	%XMM0, %XMM0
513694
-	jmp	L(entry_from_bzero)
513694
-END (__bzero)
513694
-weak_alias (__bzero, bzero)
513694
 #endif
513694
 
513694
 #if IS_IN (libc)
513694
@@ -123,12 +127,37 @@ ENTRY (WMEMSET_SYMBOL (__wmemset, unaligned))
513694
 	WMEMSET_SET_VEC0_AND_SET_RETURN (%esi, %rdi)
513694
 	WMEMSET_VDUP_TO_VEC0_LOW()
513694
 	cmpq	$VEC_SIZE, %rdx
513694
-	jb	L(less_vec_no_vdup)
513694
+	jb	L(less_vec_from_wmemset)
513694
 	WMEMSET_VDUP_TO_VEC0_HIGH()
513694
 	jmp	L(entry_from_wmemset)
513694
 END (WMEMSET_SYMBOL (__wmemset, unaligned))
513694
 #endif
513694
 
513694
+ENTRY (BZERO_SYMBOL(__bzero, unaligned))
513694
+#if VEC_SIZE > 16
513694
+	BZERO_ZERO_VEC0 ()
513694
+#endif
513694
+	mov	%RDI_LP, %RAX_LP
513694
+	mov	%RSI_LP, %RDX_LP
513694
+#ifndef USE_LESS_VEC_MASK_STORE
513694
+	xorl	%esi, %esi
513694
+#endif
513694
+	cmp	$VEC_SIZE, %RDX_LP
513694
+	jb	L(less_vec_no_vdup)
513694
+#ifdef USE_LESS_VEC_MASK_STORE
513694
+	xorl	%esi, %esi
513694
+#endif
513694
+#if VEC_SIZE <= 16
513694
+	BZERO_ZERO_VEC0 ()
513694
+#endif
513694
+	cmp	$(VEC_SIZE * 2), %RDX_LP
513694
+	ja	L(more_2x_vec)
513694
+	/* From VEC and to 2 * VEC.  No branch when size == VEC_SIZE.  */
513694
+	VMOVU	%VEC(0), (%rdi)
513694
+	VMOVU	%VEC(0), (VEC_SIZE * -1)(%rdi, %rdx)
513694
+	VZEROUPPER_RETURN
513694
+END (BZERO_SYMBOL(__bzero, unaligned))
513694
+
513694
 #if defined SHARED && IS_IN (libc)
513694
 ENTRY_CHK (MEMSET_CHK_SYMBOL (__memset_chk, unaligned))
513694
 	cmp	%RDX_LP, %RCX_LP
513694
@@ -142,7 +171,6 @@ ENTRY (MEMSET_SYMBOL (__memset, unaligned))
513694
 	/* Clear the upper 32 bits.  */
513694
 	mov	%edx, %edx
513694
 # endif
513694
-L(entry_from_bzero):
513694
 	cmpq	$VEC_SIZE, %rdx
513694
 	jb	L(less_vec)
513694
 	MEMSET_VDUP_TO_VEC0_HIGH()
513694
@@ -187,6 +215,31 @@ END (__memset_erms)
513694
 END (MEMSET_SYMBOL (__memset, erms))
513694
 # endif
513694
 
513694
+ENTRY_P2ALIGN (BZERO_SYMBOL(__bzero, unaligned_erms), 6)
513694
+# if VEC_SIZE > 16
513694
+	BZERO_ZERO_VEC0 ()
513694
+# endif
513694
+	mov	%RDI_LP, %RAX_LP
513694
+	mov	%RSI_LP, %RDX_LP
513694
+# ifndef USE_LESS_VEC_MASK_STORE
513694
+	xorl	%esi, %esi
513694
+# endif
513694
+	cmp	$VEC_SIZE, %RDX_LP
513694
+	jb	L(less_vec_no_vdup)
513694
+# ifdef USE_LESS_VEC_MASK_STORE
513694
+	xorl	%esi, %esi
513694
+# endif
513694
+# if VEC_SIZE <= 16
513694
+	BZERO_ZERO_VEC0 ()
513694
+# endif
513694
+	cmp	$(VEC_SIZE * 2), %RDX_LP
513694
+	ja	L(stosb_more_2x_vec)
513694
+	/* From VEC and to 2 * VEC.  No branch when size == VEC_SIZE.  */
513694
+	VMOVU	%VEC(0), (%rdi)
513694
+	VMOVU	%VEC(0), (VEC_SIZE * -1)(%rdi, %rdx)
513694
+	VZEROUPPER_RETURN
513694
+END (BZERO_SYMBOL(__bzero, unaligned_erms))
513694
+
513694
 # if defined SHARED && IS_IN (libc)
513694
 ENTRY_CHK (MEMSET_CHK_SYMBOL (__memset_chk, unaligned_erms))
513694
 	cmp	%RDX_LP, %RCX_LP
513694
@@ -229,6 +282,7 @@ L(last_2x_vec):
513694
 	.p2align 4,, 10
513694
 L(less_vec):
513694
 L(less_vec_no_vdup):
513694
+L(less_vec_from_wmemset):
513694
 	/* Less than 1 VEC.  */
513694
 # if VEC_SIZE != 16 && VEC_SIZE != 32 && VEC_SIZE != 64
513694
 #  error Unsupported VEC_SIZE!
513694
@@ -374,8 +428,11 @@ L(less_vec):
513694
 	/* Broadcast esi to partial register (i.e VEC_SIZE == 32 broadcast to
513694
 	   xmm). This is only does anything for AVX2.  */
513694
 	MEMSET_VDUP_TO_VEC0_LOW ()
513694
+L(less_vec_from_wmemset):
513694
+#if VEC_SIZE > 16
513694
 L(less_vec_no_vdup):
513694
 #endif
513694
+#endif
513694
 L(cross_page):
513694
 #if VEC_SIZE > 32
513694
 	cmpl	$32, %edx
513694
@@ -386,7 +443,10 @@ L(cross_page):
513694
 	jge	L(between_16_31)
513694
 #endif
513694
 #ifndef USE_XMM_LESS_VEC
513694
-	MOVQ	%XMM0, %rcx
513694
+	MOVQ	%XMM0, %SET_REG64
513694
+#endif
513694
+#if VEC_SIZE <= 16
513694
+L(less_vec_no_vdup):
513694
 #endif
513694
 	cmpl	$8, %edx
513694
 	jge	L(between_8_15)
513694
@@ -395,7 +455,7 @@ L(cross_page):
513694
 	cmpl	$1, %edx
513694
 	jg	L(between_2_3)
513694
 	jl	L(between_0_0)
513694
-	movb	%sil, (%LESS_VEC_REG)
513694
+	movb	%SET_REG8, (%LESS_VEC_REG)
513694
 L(between_0_0):
513694
 	ret
513694
 
513694
@@ -428,8 +488,8 @@ L(between_8_15):
513694
 	MOVQ	%XMM0, (%rdi)
513694
 	MOVQ	%XMM0, -8(%rdi, %rdx)
513694
 #else
513694
-	movq	%rcx, (%LESS_VEC_REG)
513694
-	movq	%rcx, -8(%LESS_VEC_REG, %rdx)
513694
+	movq	%SET_REG64, (%LESS_VEC_REG)
513694
+	movq	%SET_REG64, -8(%LESS_VEC_REG, %rdx)
513694
 #endif
513694
 	ret
513694
 
513694
@@ -442,8 +502,8 @@ L(between_4_7):
513694
 	MOVD	%XMM0, (%rdi)
513694
 	MOVD	%XMM0, -4(%rdi, %rdx)
513694
 #else
513694
-	movl	%ecx, (%LESS_VEC_REG)
513694
-	movl	%ecx, -4(%LESS_VEC_REG, %rdx)
513694
+	movl	%SET_REG32, (%LESS_VEC_REG)
513694
+	movl	%SET_REG32, -4(%LESS_VEC_REG, %rdx)
513694
 #endif
513694
 	ret
513694
 
513694
@@ -452,12 +512,12 @@ L(between_4_7):
513694
 L(between_2_3):
513694
 	/* From 2 to 3.  No branch when size == 2.  */
513694
 #ifdef USE_XMM_LESS_VEC
513694
-	movb	%sil, (%rdi)
513694
-	movb	%sil, 1(%rdi)
513694
-	movb	%sil, -1(%rdi, %rdx)
513694
+	movb	%SET_REG8, (%rdi)
513694
+	movb	%SET_REG8, 1(%rdi)
513694
+	movb	%SET_REG8, -1(%rdi, %rdx)
513694
 #else
513694
-	movw	%cx, (%LESS_VEC_REG)
513694
-	movb	%sil, -1(%LESS_VEC_REG, %rdx)
513694
+	movw	%SET_REG16, (%LESS_VEC_REG)
513694
+	movb	%SET_REG8, -1(%LESS_VEC_REG, %rdx)
513694
 #endif
513694
 	ret
513694
 END (MEMSET_SYMBOL (__memset, unaligned_erms))
513694
-- 
513694
GitLab
513694