xref: /openbsd-src/lib/libc/arch/i386/string/strcpy.S (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7
8#if defined(LIBC_SCCS)
9	.text
10	.asciz "$OpenBSD: strcpy.S,v 1.2 1996/08/19 08:13:17 tholo Exp $"
11#endif
12
13/*
14 * NOTE: I've unrolled the loop eight times: large enough to make a
15 * significant difference, and small enough not to totally trash the
16 * cache.
17 */
18
19ENTRY(strcpy)
20	movl	4(%esp),%ecx		/* dst address */
21	movl	8(%esp),%edx		/* src address */
22	pushl	%ecx			/* push dst address */
23
24	.align 2,0x90
25L1:	movb	(%edx),%al		/* unroll loop, but not too much */
26	movb	%al,(%ecx)
27	testb	%al,%al
28	jz	L2
29	movb	1(%edx),%al
30	movb	%al,1(%ecx)
31	testb	%al,%al
32	jz	L2
33	movb	2(%edx),%al
34	movb	%al,2(%ecx)
35	testb	%al,%al
36	jz	L2
37	movb	3(%edx),%al
38	movb	%al,3(%ecx)
39	testb	%al,%al
40	jz	L2
41	movb	4(%edx),%al
42	movb	%al,4(%ecx)
43	testb	%al,%al
44	jz	L2
45	movb	5(%edx),%al
46	movb	%al,5(%ecx)
47	testb	%al,%al
48	jz	L2
49	movb	6(%edx),%al
50	movb	%al,6(%ecx)
51	testb	%al,%al
52	jz	L2
53	movb	7(%edx),%al
54	movb	%al,7(%ecx)
55	addl	$8,%edx
56	addl	$8,%ecx
57	testb	%al,%al
58	jnz	L1
59L2:	popl	%eax			/* pop dst address */
60	ret
61