08c3a6
commit 7079931c51547854323fe2ed6fdccf2a1b8b04d7
08c3a6
Author: Noah Goldstein <goldstein.w.n@gmail.com>
08c3a6
Date:   Wed Jun 29 16:07:05 2022 -0700
08c3a6
08c3a6
    x86: Move and slightly improve memset_erms
08c3a6
    
08c3a6
    Implementation wise:
08c3a6
        1. Remove the VZEROUPPER as memset_{impl}_unaligned_erms does not
08c3a6
           use the L(stosb) label that was previously defined.
08c3a6
    
08c3a6
        2. Don't give the hotpath (fallthrough) to zero size.
08c3a6
    
08c3a6
    Code positioning wise:
08c3a6
    
08c3a6
    Move memset_{chk}_erms to its own file.  Leaving it in between the
08c3a6
    memset_{impl}_unaligned both adds unnecessary complexity to the
08c3a6
    file and wastes space in a relatively hot cache section.
08c3a6
    
08c3a6
    (cherry picked from commit 4a3f29e7e475dd4e7cce2a24c187e6fb7b5b0a05)
08c3a6
08c3a6
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
08c3a6
index 0e39e63ef6be6a86..da9f16286a763556 100644
08c3a6
--- a/sysdeps/x86_64/multiarch/Makefile
08c3a6
+++ b/sysdeps/x86_64/multiarch/Makefile
08c3a6
@@ -29,6 +29,7 @@ sysdep_routines += \
08c3a6
   memset-avx2-unaligned-erms-rtm \
08c3a6
   memset-avx512-no-vzeroupper \
08c3a6
   memset-avx512-unaligned-erms \
08c3a6
+  memset-erms \
08c3a6
   memset-evex-unaligned-erms \
08c3a6
   memset-sse2-unaligned-erms \
08c3a6
   rawmemchr-avx2 \
08c3a6
diff --git a/sysdeps/x86_64/multiarch/memset-erms.S b/sysdeps/x86_64/multiarch/memset-erms.S
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..e83cccc731f0a7ea
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/memset-erms.S
08c3a6
@@ -0,0 +1,44 @@
08c3a6
+/* memset implement with rep stosb
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+
08c3a6
+#include <sysdep.h>
08c3a6
+
08c3a6
+#if defined USE_MULTIARCH && IS_IN (libc)
08c3a6
+	.text
08c3a6
+ENTRY (__memset_chk_erms)
08c3a6
+	cmp	%RDX_LP, %RCX_LP
08c3a6
+	jb	HIDDEN_JUMPTARGET (__chk_fail)
08c3a6
+END (__memset_chk_erms)
08c3a6
+
08c3a6
+/* Only used to measure performance of REP STOSB.  */
08c3a6
+ENTRY (__memset_erms)
08c3a6
+	/* Skip zero length.  */
08c3a6
+	test	%RDX_LP, %RDX_LP
08c3a6
+	jz	 L(stosb_return_zero)
08c3a6
+	mov	%RDX_LP, %RCX_LP
08c3a6
+	movzbl	%sil, %eax
08c3a6
+	mov	%RDI_LP, %RDX_LP
08c3a6
+	rep stosb
08c3a6
+	mov	%RDX_LP, %RAX_LP
08c3a6
+	ret
08c3a6
+L(stosb_return_zero):
08c3a6
+	movq	%rdi, %rax
08c3a6
+	ret
08c3a6
+END (__memset_erms)
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
08c3a6
index abc12d9cda1b3843..905d0fa4643d5768 100644
08c3a6
--- a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
08c3a6
+++ b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
08c3a6
@@ -156,37 +156,6 @@ L(entry_from_wmemset):
08c3a6
 #if defined USE_MULTIARCH && IS_IN (libc)
08c3a6
 END (MEMSET_SYMBOL (__memset, unaligned))
08c3a6
 
08c3a6
-# if VEC_SIZE == 16
08c3a6
-ENTRY (__memset_chk_erms)
08c3a6
-	cmp	%RDX_LP, %RCX_LP
08c3a6
-	jb	HIDDEN_JUMPTARGET (__chk_fail)
08c3a6
-END (__memset_chk_erms)
08c3a6
-
08c3a6
-/* Only used to measure performance of REP STOSB.  */
08c3a6
-ENTRY (__memset_erms)
08c3a6
-	/* Skip zero length.  */
08c3a6
-	test	%RDX_LP, %RDX_LP
08c3a6
-	jnz	 L(stosb)
08c3a6
-	movq	%rdi, %rax
08c3a6
-	ret
08c3a6
-# else
08c3a6
-/* Provide a hidden symbol to debugger.  */
08c3a6
-	.hidden	MEMSET_SYMBOL (__memset, erms)
08c3a6
-ENTRY (MEMSET_SYMBOL (__memset, erms))
08c3a6
-# endif
08c3a6
-L(stosb):
08c3a6
-	mov	%RDX_LP, %RCX_LP
08c3a6
-	movzbl	%sil, %eax
08c3a6
-	mov	%RDI_LP, %RDX_LP
08c3a6
-	rep stosb
08c3a6
-	mov	%RDX_LP, %RAX_LP
08c3a6
-	VZEROUPPER_RETURN
08c3a6
-# if VEC_SIZE == 16
08c3a6
-END (__memset_erms)
08c3a6
-# else
08c3a6
-END (MEMSET_SYMBOL (__memset, erms))
08c3a6
-# endif
08c3a6
-
08c3a6
 # if defined SHARED && IS_IN (libc)
08c3a6
 ENTRY_CHK (MEMSET_CHK_SYMBOL (__memset_chk, unaligned_erms))
08c3a6
 	cmp	%RDX_LP, %RCX_LP