08c3a6
commit 35f9c72c8bd7bc30deb412e966e2f548241b15d2
08c3a6
Author: Noah Goldstein <goldstein.w.n@gmail.com>
08c3a6
Date:   Wed Jun 29 16:07:15 2022 -0700
08c3a6
08c3a6
    x86: Move mem{p}{mov|cpy}_{chk_}erms to its own file
08c3a6
    
08c3a6
    The primary memmove_{impl}_unaligned_erms implementations don't
08c3a6
    interact with this function. Putting them in same file both
08c3a6
    wastes space and unnecessarily bloats a hot code section.
08c3a6
    
08c3a6
    (cherry picked from commit 21925f64730d52eb7d8b2fb62b412f8ab92b0caf)
08c3a6
08c3a6
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
08c3a6
index da9f16286a763556..b9ea5b60c2be1b0a 100644
08c3a6
--- a/sysdeps/x86_64/multiarch/Makefile
08c3a6
+++ b/sysdeps/x86_64/multiarch/Makefile
08c3a6
@@ -17,6 +17,7 @@ sysdep_routines += \
08c3a6
   memmove-avx-unaligned-erms-rtm \
08c3a6
   memmove-avx512-no-vzeroupper \
08c3a6
   memmove-avx512-unaligned-erms \
08c3a6
+  memmove-erms \
08c3a6
   memmove-evex-unaligned-erms \
08c3a6
   memmove-sse2-unaligned-erms \
08c3a6
   memmove-ssse3 \
08c3a6
diff --git a/sysdeps/x86_64/multiarch/memmove-erms.S b/sysdeps/x86_64/multiarch/memmove-erms.S
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..2d3a6ccb76d77052
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/memmove-erms.S
08c3a6
@@ -0,0 +1,72 @@
08c3a6
+/* memcpy/mempcpy/memmove implement with rep movsb
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 (__mempcpy_chk_erms)
08c3a6
+	cmp	%RDX_LP, %RCX_LP
08c3a6
+	jb	HIDDEN_JUMPTARGET (__chk_fail)
08c3a6
+END (__mempcpy_chk_erms)
08c3a6
+
08c3a6
+/* Only used to measure performance of REP MOVSB.  */
08c3a6
+ENTRY (__mempcpy_erms)
08c3a6
+	mov	%RDI_LP, %RAX_LP
08c3a6
+	/* Skip zero length.  */
08c3a6
+	test	%RDX_LP, %RDX_LP
08c3a6
+	jz	2f
08c3a6
+	add	%RDX_LP, %RAX_LP
08c3a6
+	jmp	L(start_movsb)
08c3a6
+END (__mempcpy_erms)
08c3a6
+
08c3a6
+ENTRY (__memmove_chk_erms)
08c3a6
+	cmp	%RDX_LP, %RCX_LP
08c3a6
+	jb	HIDDEN_JUMPTARGET (__chk_fail)
08c3a6
+END (__memmove_chk_erms)
08c3a6
+
08c3a6
+ENTRY (__memmove_erms)
08c3a6
+	movq	%rdi, %rax
08c3a6
+	/* Skip zero length.  */
08c3a6
+	test	%RDX_LP, %RDX_LP
08c3a6
+	jz	2f
08c3a6
+L(start_movsb):
08c3a6
+	mov	%RDX_LP, %RCX_LP
08c3a6
+	cmp	%RSI_LP, %RDI_LP
08c3a6
+	jb	1f
08c3a6
+	/* Source == destination is less common.  */
08c3a6
+	je	2f
08c3a6
+	lea	(%rsi,%rcx), %RDX_LP
08c3a6
+	cmp	%RDX_LP, %RDI_LP
08c3a6
+	jb	L(movsb_backward)
08c3a6
+1:
08c3a6
+	rep movsb
08c3a6
+2:
08c3a6
+	ret
08c3a6
+L(movsb_backward):
08c3a6
+	leaq	-1(%rdi,%rcx), %rdi
08c3a6
+	leaq	-1(%rsi,%rcx), %rsi
08c3a6
+	std
08c3a6
+	rep movsb
08c3a6
+	cld
08c3a6
+	ret
08c3a6
+END (__memmove_erms)
08c3a6
+strong_alias (__memmove_erms, __memcpy_erms)
08c3a6
+strong_alias (__memmove_chk_erms, __memcpy_chk_erms)
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
08c3a6
index 618d46d8ce28828c..93c7e6883a254434 100644
08c3a6
--- a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
08c3a6
+++ b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
08c3a6
@@ -239,56 +239,6 @@ L(start):
08c3a6
 #endif
08c3a6
 #if defined USE_MULTIARCH && IS_IN (libc)
08c3a6
 END (MEMMOVE_SYMBOL (__memmove, unaligned))
08c3a6
-# if VEC_SIZE == 16
08c3a6
-ENTRY (__mempcpy_chk_erms)
08c3a6
-	cmp	%RDX_LP, %RCX_LP
08c3a6
-	jb	HIDDEN_JUMPTARGET (__chk_fail)
08c3a6
-END (__mempcpy_chk_erms)
08c3a6
-
08c3a6
-/* Only used to measure performance of REP MOVSB.  */
08c3a6
-ENTRY (__mempcpy_erms)
08c3a6
-	mov	%RDI_LP, %RAX_LP
08c3a6
-	/* Skip zero length.  */
08c3a6
-	test	%RDX_LP, %RDX_LP
08c3a6
-	jz	2f
08c3a6
-	add	%RDX_LP, %RAX_LP
08c3a6
-	jmp	L(start_movsb)
08c3a6
-END (__mempcpy_erms)
08c3a6
-
08c3a6
-ENTRY (__memmove_chk_erms)
08c3a6
-	cmp	%RDX_LP, %RCX_LP
08c3a6
-	jb	HIDDEN_JUMPTARGET (__chk_fail)
08c3a6
-END (__memmove_chk_erms)
08c3a6
-
08c3a6
-ENTRY (__memmove_erms)
08c3a6
-	movq	%rdi, %rax
08c3a6
-	/* Skip zero length.  */
08c3a6
-	test	%RDX_LP, %RDX_LP
08c3a6
-	jz	2f
08c3a6
-L(start_movsb):
08c3a6
-	mov	%RDX_LP, %RCX_LP
08c3a6
-	cmp	%RSI_LP, %RDI_LP
08c3a6
-	jb	1f
08c3a6
-	/* Source == destination is less common.  */
08c3a6
-	je	2f
08c3a6
-	lea	(%rsi,%rcx), %RDX_LP
08c3a6
-	cmp	%RDX_LP, %RDI_LP
08c3a6
-	jb	L(movsb_backward)
08c3a6
-1:
08c3a6
-	rep movsb
08c3a6
-2:
08c3a6
-	ret
08c3a6
-L(movsb_backward):
08c3a6
-	leaq	-1(%rdi,%rcx), %rdi
08c3a6
-	leaq	-1(%rsi,%rcx), %rsi
08c3a6
-	std
08c3a6
-	rep movsb
08c3a6
-	cld
08c3a6
-	ret
08c3a6
-END (__memmove_erms)
08c3a6
-strong_alias (__memmove_erms, __memcpy_erms)
08c3a6
-strong_alias (__memmove_chk_erms, __memcpy_chk_erms)
08c3a6
-# endif
08c3a6
 
08c3a6
 # ifdef SHARED
08c3a6
 ENTRY (MEMMOVE_CHK_SYMBOL (__mempcpy_chk, unaligned_erms))