strcat.S revision 1849
1147191Sjkoshy/*
2147191Sjkoshy * Copyright (c) 1993 Winning Strategies, Inc.
3147191Sjkoshy * All rights reserved.
4147191Sjkoshy *
5147191Sjkoshy * Redistribution and use in source and binary forms, with or without
6147191Sjkoshy * modification, are permitted provided that the following conditions
7147191Sjkoshy * are met:
8147191Sjkoshy * 1. Redistributions of source code must retain the above copyright
9147191Sjkoshy *    notice, this list of conditions and the following disclaimer.
10147191Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11147191Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12147191Sjkoshy *    documentation and/or other materials provided with the distribution.
13147191Sjkoshy * 3. All advertising materials mentioning features or use of this software
14147191Sjkoshy *    must display the following acknowledgement:
15147191Sjkoshy *      This product includes software developed by Winning Strategies, Inc.
16147191Sjkoshy * 4. The name of the author may not be used to endorse or promote products
17147191Sjkoshy *    derived from this software withough specific prior written permission
18147191Sjkoshy *
19147191Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20147191Sjkoshy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21147191Sjkoshy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22147191Sjkoshy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23147191Sjkoshy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24147191Sjkoshy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25147191Sjkoshy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26147191Sjkoshy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27147191Sjkoshy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28147191Sjkoshy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29147191Sjkoshy *
30147191Sjkoshy *	$Id: strcat.S,v 1.1 1993/12/05 13:01:56 ats Exp $
31147191Sjkoshy */
32147191Sjkoshy
33147191Sjkoshy#if defined(LIBC_RCS) && !defined(lint)
34147191Sjkoshy        .asciz "$Id: strcat.S,v 1.1 1993/12/05 13:01:56 ats Exp $"
35147191Sjkoshy#endif /* LIBC_RCS and not lint */
36147191Sjkoshy
37147191Sjkoshy#include "DEFS.h"
38147191Sjkoshy
39147191Sjkoshy/*
40147191Sjkoshy * strcat(s, append)
41174410Sjkoshy *	append a copy of the null-terminated string "append" to the end
42185168Sjkoshy *	of the null-terminated string s, then add a terminating `\0'.
43185168Sjkoshy *
44185168Sjkoshy * Written by:
45185168Sjkoshy *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
46185168Sjkoshy */
47185168Sjkoshy
48174410Sjkoshy/*
49174410Sjkoshy * I've unrolled the loop eight times: large enough to make a
50174410Sjkoshy * significant difference, and small enough not to totally trash the
51174410Sjkoshy * cashe.
52174410Sjkoshy */
53174410Sjkoshy
54174410SjkoshyENTRY(strcat)
55174410Sjkoshy	pushl	%edi			/* save edi */
56174410Sjkoshy	movl	8(%esp),%edi		/* dst address */
57174410Sjkoshy	movl	12(%esp),%edx		/* src address */
58174410Sjkoshy	pushl	%edi			/* push destination address */
59174410Sjkoshy
60174410Sjkoshy	cld				/* set search forward */
61174410Sjkoshy	xorl	%eax,%eax		/* set search for null terminator */
62174410Sjkoshy	movl	$-1,%ecx		/* set search for lots of characters */
63174410Sjkoshy	repne				/* search! */
64174410Sjkoshy	scasb
65174410Sjkoshy
66174410Sjkoshy	leal	-1(%edi),%ecx		/* correct dst address */
67
68	.align 2,0x90
69L1:	movb	(%edx),%al		/* unroll loop, but not too much */
70	movb	%al,(%ecx)
71	testb	%al,%al
72	je	L2
73	movb	1(%edx),%al
74	movb	%al,1(%ecx)
75	testb	%al,%al
76	je	L2
77	movb	2(%edx),%al
78	movb	%al,2(%ecx)
79	testb	%al,%al
80	je	L2
81	movb	3(%edx),%al
82	movb	%al,3(%ecx)
83	testb	%al,%al
84	je	L2
85	movb	4(%edx),%al
86	movb	%al,4(%ecx)
87	testb	%al,%al
88	je	L2
89	movb	5(%edx),%al
90	movb	%al,5(%ecx)
91	testb	%al,%al
92	je	L2
93	movb	6(%edx),%al
94	movb	%al,6(%ecx)
95	testb	%al,%al
96	je	L2
97	movb	7(%edx),%al
98	movb	%al,7(%ecx)
99	addl	$8,%edx
100	addl	$8,%ecx
101	testb	%al,%al
102	jne	L1
103L2:	popl	%eax			/* pop destination address */
104	popl	%edi			/* restore edi */
105	ret
106