xref: /freebsd/lib/libc/i386/string/strcat.S (revision 2ceb2ce9eed6efe8076988a9e81722d6a920245d)
12ceb2ce9SGarrett Wollman/*
22ceb2ce9SGarrett Wollman * Copyright (c) 1993 Winning Strategies, Inc.
32ceb2ce9SGarrett Wollman * All rights reserved.
42ceb2ce9SGarrett Wollman *
52ceb2ce9SGarrett Wollman * Redistribution and use in source and binary forms, with or without
62ceb2ce9SGarrett Wollman * modification, are permitted provided that the following conditions
72ceb2ce9SGarrett Wollman * are met:
82ceb2ce9SGarrett Wollman * 1. Redistributions of source code must retain the above copyright
92ceb2ce9SGarrett Wollman *    notice, this list of conditions and the following disclaimer.
102ceb2ce9SGarrett Wollman * 2. Redistributions in binary form must reproduce the above copyright
112ceb2ce9SGarrett Wollman *    notice, this list of conditions and the following disclaimer in the
122ceb2ce9SGarrett Wollman *    documentation and/or other materials provided with the distribution.
132ceb2ce9SGarrett Wollman * 3. All advertising materials mentioning features or use of this software
142ceb2ce9SGarrett Wollman *    must display the following acknowledgement:
152ceb2ce9SGarrett Wollman *      This product includes software developed by Winning Strategies, Inc.
162ceb2ce9SGarrett Wollman * 4. The name of the author may not be used to endorse or promote products
172ceb2ce9SGarrett Wollman *    derived from this software withough specific prior written permission
182ceb2ce9SGarrett Wollman *
192ceb2ce9SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
202ceb2ce9SGarrett Wollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
212ceb2ce9SGarrett Wollman * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
222ceb2ce9SGarrett Wollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
232ceb2ce9SGarrett Wollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
242ceb2ce9SGarrett Wollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
252ceb2ce9SGarrett Wollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
262ceb2ce9SGarrett Wollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
272ceb2ce9SGarrett Wollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
282ceb2ce9SGarrett Wollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292ceb2ce9SGarrett Wollman *
302ceb2ce9SGarrett Wollman *	$Id: strcat.S,v 1.1 1993/12/05 13:01:56 ats Exp $
312ceb2ce9SGarrett Wollman */
322ceb2ce9SGarrett Wollman
332ceb2ce9SGarrett Wollman#if defined(LIBC_RCS) && !defined(lint)
342ceb2ce9SGarrett Wollman        .asciz "$Id: strcat.S,v 1.1 1993/12/05 13:01:56 ats Exp $"
352ceb2ce9SGarrett Wollman#endif /* LIBC_RCS and not lint */
362ceb2ce9SGarrett Wollman
372ceb2ce9SGarrett Wollman#include "DEFS.h"
382ceb2ce9SGarrett Wollman
392ceb2ce9SGarrett Wollman/*
402ceb2ce9SGarrett Wollman * strcat(s, append)
412ceb2ce9SGarrett Wollman *	append a copy of the null-terminated string "append" to the end
422ceb2ce9SGarrett Wollman *	of the null-terminated string s, then add a terminating `\0'.
432ceb2ce9SGarrett Wollman *
442ceb2ce9SGarrett Wollman * Written by:
452ceb2ce9SGarrett Wollman *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
462ceb2ce9SGarrett Wollman */
472ceb2ce9SGarrett Wollman
482ceb2ce9SGarrett Wollman/*
492ceb2ce9SGarrett Wollman * I've unrolled the loop eight times: large enough to make a
502ceb2ce9SGarrett Wollman * significant difference, and small enough not to totally trash the
512ceb2ce9SGarrett Wollman * cashe.
522ceb2ce9SGarrett Wollman */
532ceb2ce9SGarrett Wollman
542ceb2ce9SGarrett WollmanENTRY(strcat)
552ceb2ce9SGarrett Wollman	pushl	%edi			/* save edi */
562ceb2ce9SGarrett Wollman	movl	8(%esp),%edi		/* dst address */
572ceb2ce9SGarrett Wollman	movl	12(%esp),%edx		/* src address */
582ceb2ce9SGarrett Wollman	pushl	%edi			/* push destination address */
592ceb2ce9SGarrett Wollman
602ceb2ce9SGarrett Wollman	cld				/* set search forward */
612ceb2ce9SGarrett Wollman	xorl	%eax,%eax		/* set search for null terminator */
622ceb2ce9SGarrett Wollman	movl	$-1,%ecx		/* set search for lots of characters */
632ceb2ce9SGarrett Wollman	repne				/* search! */
642ceb2ce9SGarrett Wollman	scasb
652ceb2ce9SGarrett Wollman
662ceb2ce9SGarrett Wollman	leal	-1(%edi),%ecx		/* correct dst address */
672ceb2ce9SGarrett Wollman
682ceb2ce9SGarrett Wollman	.align 2,0x90
692ceb2ce9SGarrett WollmanL1:	movb	(%edx),%al		/* unroll loop, but not too much */
702ceb2ce9SGarrett Wollman	movb	%al,(%ecx)
712ceb2ce9SGarrett Wollman	testb	%al,%al
722ceb2ce9SGarrett Wollman	je	L2
732ceb2ce9SGarrett Wollman	movb	1(%edx),%al
742ceb2ce9SGarrett Wollman	movb	%al,1(%ecx)
752ceb2ce9SGarrett Wollman	testb	%al,%al
762ceb2ce9SGarrett Wollman	je	L2
772ceb2ce9SGarrett Wollman	movb	2(%edx),%al
782ceb2ce9SGarrett Wollman	movb	%al,2(%ecx)
792ceb2ce9SGarrett Wollman	testb	%al,%al
802ceb2ce9SGarrett Wollman	je	L2
812ceb2ce9SGarrett Wollman	movb	3(%edx),%al
822ceb2ce9SGarrett Wollman	movb	%al,3(%ecx)
832ceb2ce9SGarrett Wollman	testb	%al,%al
842ceb2ce9SGarrett Wollman	je	L2
852ceb2ce9SGarrett Wollman	movb	4(%edx),%al
862ceb2ce9SGarrett Wollman	movb	%al,4(%ecx)
872ceb2ce9SGarrett Wollman	testb	%al,%al
882ceb2ce9SGarrett Wollman	je	L2
892ceb2ce9SGarrett Wollman	movb	5(%edx),%al
902ceb2ce9SGarrett Wollman	movb	%al,5(%ecx)
912ceb2ce9SGarrett Wollman	testb	%al,%al
922ceb2ce9SGarrett Wollman	je	L2
932ceb2ce9SGarrett Wollman	movb	6(%edx),%al
942ceb2ce9SGarrett Wollman	movb	%al,6(%ecx)
952ceb2ce9SGarrett Wollman	testb	%al,%al
962ceb2ce9SGarrett Wollman	je	L2
972ceb2ce9SGarrett Wollman	movb	7(%edx),%al
982ceb2ce9SGarrett Wollman	movb	%al,7(%ecx)
992ceb2ce9SGarrett Wollman	addl	$8,%edx
1002ceb2ce9SGarrett Wollman	addl	$8,%ecx
1012ceb2ce9SGarrett Wollman	testb	%al,%al
1022ceb2ce9SGarrett Wollman	jne	L1
1032ceb2ce9SGarrett WollmanL2:	popl	%eax			/* pop destination address */
1042ceb2ce9SGarrett Wollman	popl	%edi			/* restore edi */
1052ceb2ce9SGarrett Wollman	ret
106