xref: /openbsd-src/lib/libc/arch/i386/string/strcat.S (revision df930be708d50e9715f173caa26ffe1b7599b157)
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	RCSID("$NetBSD: strcat.S,v 1.8 1995/04/28 22:58:09 jtc Exp $")
10#endif
11
12/*
13 * NOTE: I've unrolled the loop eight times: large enough to make a
14 * significant difference, and small enough not to totally trash the
15 * cache.
16 */
17
18ENTRY(strcat)
19	pushl	%edi			/* save edi */
20	movl	8(%esp),%edi		/* dst address */
21	movl	12(%esp),%edx		/* src address */
22	pushl	%edi			/* push destination address */
23
24	cld				/* set search forward */
25	xorl	%eax,%eax		/* set search for null terminator */
26	movl	$-1,%ecx		/* set search for lots of characters */
27	repne				/* search! */
28	scasb
29
30	leal	-1(%edi),%ecx		/* correct dst address */
31
32	.align 2,0x90
33L1:	movb	(%edx),%al		/* unroll loop, but not too much */
34	movb	%al,(%ecx)
35	testb	%al,%al
36	jz	L2
37	movb	1(%edx),%al
38	movb	%al,1(%ecx)
39	testb	%al,%al
40	jz	L2
41	movb	2(%edx),%al
42	movb	%al,2(%ecx)
43	testb	%al,%al
44	jz	L2
45	movb	3(%edx),%al
46	movb	%al,3(%ecx)
47	testb	%al,%al
48	jz	L2
49	movb	4(%edx),%al
50	movb	%al,4(%ecx)
51	testb	%al,%al
52	jz	L2
53	movb	5(%edx),%al
54	movb	%al,5(%ecx)
55	testb	%al,%al
56	jz	L2
57	movb	6(%edx),%al
58	movb	%al,6(%ecx)
59	testb	%al,%al
60	jz	L2
61	movb	7(%edx),%al
62	movb	%al,7(%ecx)
63	addl	$8,%edx
64	addl	$8,%ecx
65	testb	%al,%al
66	jnz	L1
67L2:	popl	%eax			/* pop destination address */
68	popl	%edi			/* restore edi */
69	ret
70