strcat.S revision 184548
1161202Simp/*
2161202Simp * Copyright (c) 1993 Winning Strategies, Inc.
3161202Simp * All rights reserved.
4161202Simp *
5161202Simp * Redistribution and use in source and binary forms, with or without
6161202Simp * modification, are permitted provided that the following conditions
7161202Simp * are met:
8161202Simp * 1. Redistributions of source code must retain the above copyright
9161202Simp *    notice, this list of conditions and the following disclaimer.
10161202Simp * 2. Redistributions in binary form must reproduce the above copyright
11161202Simp *    notice, this list of conditions and the following disclaimer in the
12161202Simp *    documentation and/or other materials provided with the distribution.
13161202Simp * 3. All advertising materials mentioning features or use of this software
14161202Simp *    must display the following acknowledgement:
15161202Simp *      This product includes software developed by Winning Strategies, Inc.
16161202Simp * 4. The name of the author may not be used to endorse or promote products
17161202Simp *    derived from this software without specific prior written permission
18161202Simp *
19161202Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20161202Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21161202Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22161202Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23161202Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24161202Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25161202Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26161202Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27161202Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28161202Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29161202Simp */
30161202Simp
31161202Simp#include <machine/asm.h>
32161202Simp__FBSDID("$FreeBSD: head/lib/libc/i386/string/strcat.S 184548 2008-11-02 01:28:47Z peter $");
33161202Simp
34161202Simp/*
35161202Simp * strcat(s, append)
36161202Simp *	append a copy of the null-terminated string "append" to the end
37161202Simp *	of the null-terminated string s, then add a terminating `\0'.
38161202Simp *
39161202Simp * Written by:
40161202Simp *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
41161202Simp */
42161202Simp
43161202Simp/*
44161202Simp * I've unrolled the loop eight times: large enough to make a
45161202Simp * significant difference, and small enough not to totally trash the
46161202Simp * cache.
47161202Simp */
48161202Simp
49161202SimpENTRY(strcat)
50161202Simp	pushl	%edi			/* save edi */
51161202Simp	movl	8(%esp),%edi		/* dst address */
52161202Simp	movl	12(%esp),%edx		/* src address */
53161202Simp	pushl	%edi			/* push destination address */
54161202Simp
55161202Simp	cld				/* set search forward */
56161202Simp	xorl	%eax,%eax		/* set search for null terminator */
57161202Simp	movl	$-1,%ecx		/* set search for lots of characters */
58161202Simp	repne				/* search! */
59161202Simp	scasb
60161202Simp
61161202Simp	leal	-1(%edi),%ecx		/* correct dst address */
62161202Simp
63161202Simp	.align 2,0x90
64161202SimpL1:	movb	(%edx),%al		/* unroll loop, but not too much */
65161202Simp	movb	%al,(%ecx)
66161202Simp	testb	%al,%al
67161202Simp	je	L2
68161202Simp	movb	1(%edx),%al
69161202Simp	movb	%al,1(%ecx)
70161202Simp	testb	%al,%al
71161202Simp	je	L2
72161202Simp	movb	2(%edx),%al
73161202Simp	movb	%al,2(%ecx)
74161202Simp	testb	%al,%al
75161202Simp	je	L2
76161202Simp	movb	3(%edx),%al
77161202Simp	movb	%al,3(%ecx)
78161202Simp	testb	%al,%al
79161202Simp	je	L2
80161202Simp	movb	4(%edx),%al
81161202Simp	movb	%al,4(%ecx)
82161202Simp	testb	%al,%al
83161202Simp	je	L2
84161202Simp	movb	5(%edx),%al
85161202Simp	movb	%al,5(%ecx)
86161202Simp	testb	%al,%al
87161202Simp	je	L2
88161202Simp	movb	6(%edx),%al
89161202Simp	movb	%al,6(%ecx)
90161202Simp	testb	%al,%al
91161202Simp	je	L2
92161202Simp	movb	7(%edx),%al
93161202Simp	movb	%al,7(%ecx)
94161202Simp	addl	$8,%edx
95161202Simp	addl	$8,%ecx
96163596Simp	testb	%al,%al
97161202Simp	jne	L1
98161202SimpL2:	popl	%eax			/* pop destination address */
99161202Simp	popl	%edi			/* restore edi */
100161202Simp	ret
101161202SimpEND(strcat)
102161202Simp