xref: /openbsd-src/lib/libc/arch/i386/string/strcat.S (revision db3296cf5c1dd9058ceecc3a29fe4aaa0bd26000)
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7
8#if defined(APIWARN)
9#APP
10	.stabs "warning: strcat() is almost always misused, consider using strlcat()",30,0,0,0
11	.stabs "_strcat",1,0,0,0
12#NO_APP
13#endif
14
15#if defined(LIBC_SCCS)
16	.text
17	.asciz "$OpenBSD: strcat.S,v 1.5 2003/07/24 01:15:42 deraadt Exp $"
18#endif
19
20/*
21 * NOTE: I've unrolled the loop eight times: large enough to make a
22 * significant difference, and small enough not to totally trash the
23 * cache.
24 */
25
26ENTRY(strcat)
27	pushl	%edi			/* save edi */
28	movl	8(%esp),%edi		/* dst address */
29	movl	12(%esp),%edx		/* src address */
30	pushl	%edi			/* push destination address */
31
32	cld				/* set search forward */
33	xorl	%eax,%eax		/* set search for null terminator */
34	movl	$-1,%ecx		/* set search for lots of characters */
35	repne				/* search! */
36	scasb
37
38	leal	-1(%edi),%ecx		/* correct dst address */
39
40	.align 2,0x90
41L1:	movb	(%edx),%al		/* unroll loop, but not too much */
42	movb	%al,(%ecx)
43	testb	%al,%al
44	jz	L2
45	movb	1(%edx),%al
46	movb	%al,1(%ecx)
47	testb	%al,%al
48	jz	L2
49	movb	2(%edx),%al
50	movb	%al,2(%ecx)
51	testb	%al,%al
52	jz	L2
53	movb	3(%edx),%al
54	movb	%al,3(%ecx)
55	testb	%al,%al
56	jz	L2
57	movb	4(%edx),%al
58	movb	%al,4(%ecx)
59	testb	%al,%al
60	jz	L2
61	movb	5(%edx),%al
62	movb	%al,5(%ecx)
63	testb	%al,%al
64	jz	L2
65	movb	6(%edx),%al
66	movb	%al,6(%ecx)
67	testb	%al,%al
68	jz	L2
69	movb	7(%edx),%al
70	movb	%al,7(%ecx)
71	addl	$8,%edx
72	addl	$8,%ecx
73	testb	%al,%al
74	jnz	L1
75L2:	popl	%eax			/* pop destination address */
76	popl	%edi			/* restore edi */
77	ret
78