1/* Copy memory block and return pointer to beginning of destination block
2   For Intel 80x86, x>=6.
3   This file is part of the GNU C Library.
4   Copyright (C) 1999-2022 Free Software Foundation, Inc.
5
6   The GNU C Library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10
11   The GNU C Library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Lesser General Public License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with the GNU C Library; if not, see
18   <https://www.gnu.org/licenses/>.  */
19
20#include <sysdep.h>
21#include "asm-syntax.h"
22
23#define PARMS	4		/* no space for saved regs */
24#define RTN	PARMS
25#define DEST	RTN
26#define SRC	DEST+4
27#define LEN	SRC+4
28
29	.text
30#if defined PIC && IS_IN (libc)
31ENTRY_CHK (__memcpy_chk)
32	movl	12(%esp), %eax
33	cmpl	%eax, 16(%esp)
34	jb	HIDDEN_JUMPTARGET (__chk_fail)
35END_CHK (__memcpy_chk)
36#endif
37ENTRY (memcpy)
38
39	movl	%edi, %eax
40	movl	DEST(%esp), %edi
41	movl	%esi, %edx
42	movl	SRC(%esp), %esi
43
44	movl	%edi, %ecx
45	xorl	%esi, %ecx
46	andl	$3, %ecx
47	movl	LEN(%esp), %ecx
48	cld
49	jne	.Lunaligned
50
51	cmpl	$3, %ecx
52	jbe	.Lunaligned
53
54	testl	$3, %esi
55	je	1f
56	movsb
57	decl	%ecx
58	testl	$3, %esi
59	je	1f
60	movsb
61	decl	%ecx
62	testl	$3, %esi
63	je	1f
64	movsb
65	decl	%ecx
661:	pushl	%eax
67	movl	%ecx, %eax
68	shrl	$2, %ecx
69	andl	$3, %eax
70	rep
71	movsl
72	movl	%eax, %ecx
73	rep
74	movsb
75	popl	%eax
76
77.Lend:	movl	%eax, %edi
78	movl	%edx, %esi
79	movl	DEST(%esp), %eax
80
81	ret
82
83	/* When we come here the pointers do not have the same
84	   alignment or the length is too short.  No need to optimize for
85	   aligned memory accesses. */
86.Lunaligned:
87	shrl	$1, %ecx
88	jnc	1f
89	movsb
901:	shrl	$1, %ecx
91	jnc	2f
92	movsw
932:	rep
94	movsl
95	jmp	.Lend
96END (memcpy)
97libc_hidden_builtin_def (memcpy)
98