strcat.S revision 5790
11849Swollman/* 21849Swollman * Copyright (c) 1993 Winning Strategies, Inc. 31849Swollman * All rights reserved. 41849Swollman * 51849Swollman * Redistribution and use in source and binary forms, with or without 61849Swollman * modification, are permitted provided that the following conditions 71849Swollman * are met: 81849Swollman * 1. Redistributions of source code must retain the above copyright 91849Swollman * notice, this list of conditions and the following disclaimer. 101849Swollman * 2. Redistributions in binary form must reproduce the above copyright 111849Swollman * notice, this list of conditions and the following disclaimer in the 121849Swollman * documentation and/or other materials provided with the distribution. 131849Swollman * 3. All advertising materials mentioning features or use of this software 141849Swollman * must display the following acknowledgement: 151849Swollman * This product includes software developed by Winning Strategies, Inc. 161849Swollman * 4. The name of the author may not be used to endorse or promote products 171849Swollman * derived from this software withough specific prior written permission 181849Swollman * 191849Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 201849Swollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 211849Swollman * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 221849Swollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 231849Swollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 241849Swollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251849Swollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261849Swollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271849Swollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 281849Swollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291849Swollman * 305790Sdg * $Id: strcat.S,v 1.1 1994/08/05 01:18:32 wollman Exp $ 311849Swollman */ 321849Swollman 331849Swollman#if defined(LIBC_RCS) && !defined(lint) 345790Sdg .text 355790Sdg .asciz "$Id: strcat.S,v 1.1 1994/08/05 01:18:32 wollman Exp $" 361849Swollman#endif /* LIBC_RCS and not lint */ 371849Swollman 381849Swollman#include "DEFS.h" 391849Swollman 401849Swollman/* 411849Swollman * strcat(s, append) 421849Swollman * append a copy of the null-terminated string "append" to the end 431849Swollman * of the null-terminated string s, then add a terminating `\0'. 441849Swollman * 451849Swollman * Written by: 461849Swollman * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. 471849Swollman */ 481849Swollman 491849Swollman/* 501849Swollman * I've unrolled the loop eight times: large enough to make a 511849Swollman * significant difference, and small enough not to totally trash the 521849Swollman * cashe. 531849Swollman */ 541849Swollman 551849SwollmanENTRY(strcat) 561849Swollman pushl %edi /* save edi */ 571849Swollman movl 8(%esp),%edi /* dst address */ 581849Swollman movl 12(%esp),%edx /* src address */ 591849Swollman pushl %edi /* push destination address */ 601849Swollman 611849Swollman cld /* set search forward */ 621849Swollman xorl %eax,%eax /* set search for null terminator */ 631849Swollman movl $-1,%ecx /* set search for lots of characters */ 641849Swollman repne /* search! */ 651849Swollman scasb 661849Swollman 671849Swollman leal -1(%edi),%ecx /* correct dst address */ 681849Swollman 691849Swollman .align 2,0x90 701849SwollmanL1: movb (%edx),%al /* unroll loop, but not too much */ 711849Swollman movb %al,(%ecx) 721849Swollman testb %al,%al 731849Swollman je L2 741849Swollman movb 1(%edx),%al 751849Swollman movb %al,1(%ecx) 761849Swollman testb %al,%al 771849Swollman je L2 781849Swollman movb 2(%edx),%al 791849Swollman movb %al,2(%ecx) 801849Swollman testb %al,%al 811849Swollman je L2 821849Swollman movb 3(%edx),%al 831849Swollman movb %al,3(%ecx) 841849Swollman testb %al,%al 851849Swollman je L2 861849Swollman movb 4(%edx),%al 871849Swollman movb %al,4(%ecx) 881849Swollman testb %al,%al 891849Swollman je L2 901849Swollman movb 5(%edx),%al 911849Swollman movb %al,5(%ecx) 921849Swollman testb %al,%al 931849Swollman je L2 941849Swollman movb 6(%edx),%al 951849Swollman movb %al,6(%ecx) 961849Swollman testb %al,%al 971849Swollman je L2 981849Swollman movb 7(%edx),%al 991849Swollman movb %al,7(%ecx) 1001849Swollman addl $8,%edx 1011849Swollman addl $8,%ecx 1021849Swollman testb %al,%al 1031849Swollman jne L1 1041849SwollmanL2: popl %eax /* pop destination address */ 1051849Swollman popl %edi /* restore edi */ 1061849Swollman ret 107