1/*	$OpenBSD: strcpy.S,v 1.10 2017/11/28 06:55:49 tb Exp $ */
2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain.
5 */
6
7#include <machine/asm.h>
8
9#if defined(APIWARN)
10#APP
11	.section .gnu.warning.strcpy
12	.ascii "strcpy() is almost always misused, please use strlcpy()"
13#NO_APP
14#endif
15
16/*
17 * NOTE: I've unrolled the loop eight times: large enough to make a
18 * significant difference, and small enough not to totally trash the
19 * cache.
20 */
21
22ENTRY(strcpy)
23	movl	4(%esp),%ecx		/* dst address */
24	movl	8(%esp),%edx		/* src address */
25	pushl	%ecx			/* push dst address */
26
27	.align 2,0x90
28L1:	movb	(%edx),%al		/* unroll loop, but not too much */
29	movb	%al,(%ecx)
30	testb	%al,%al
31	jz	L2
32	movb	1(%edx),%al
33	movb	%al,1(%ecx)
34	testb	%al,%al
35	jz	L2
36	movb	2(%edx),%al
37	movb	%al,2(%ecx)
38	testb	%al,%al
39	jz	L2
40	movb	3(%edx),%al
41	movb	%al,3(%ecx)
42	testb	%al,%al
43	jz	L2
44	movb	4(%edx),%al
45	movb	%al,4(%ecx)
46	testb	%al,%al
47	jz	L2
48	movb	5(%edx),%al
49	movb	%al,5(%ecx)
50	testb	%al,%al
51	jz	L2
52	movb	6(%edx),%al
53	movb	%al,6(%ecx)
54	testb	%al,%al
55	jz	L2
56	movb	7(%edx),%al
57	movb	%al,7(%ecx)
58	addl	$8,%edx
59	addl	$8,%ecx
60	testb	%al,%al
61	jnz	L1
62L2:	popl	%eax			/* pop dst address */
63	ret
64END(strcpy)
65