111894Speter/* 211894Speter * Copyright (c) 1993 Winning Strategies, Inc. 39Sjkh * All rights reserved. 49Sjkh * 511894Speter * Redistribution and use in source and binary forms, with or without 69Sjkh * modification, are permitted provided that the following conditions 79Sjkh * are met: 89Sjkh * 1. Redistributions of source code must retain the above copyright 99Sjkh * notice, this list of conditions and the following disclaimer. 1011894Speter * 2. Redistributions in binary form must reproduce the above copyright 1111894Speter * notice, this list of conditions and the following disclaimer in the 129Sjkh * documentation and/or other materials provided with the distribution. 139Sjkh * 3. All advertising materials mentioning features or use of this software 149Sjkh * must display the following acknowledgement: 159Sjkh * This product includes software developed by Winning Strategies, Inc. 169Sjkh * 4. The name of the author may not be used to endorse or promote products 179Sjkh * derived from this software without specific prior written permission 189Sjkh * 199Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 209Sjkh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 219Sjkh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 229Sjkh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 239Sjkh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 249Sjkh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 259Sjkh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 269Sjkh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2711894Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2811894Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2911894Speter */ 309Sjkh 319Sjkh#include <machine/asm.h> 329Sjkh__FBSDID("$FreeBSD: releng/10.3/lib/libc/i386/string/strcat.S 217106 2011-01-07 16:08:40Z kib $"); 339Sjkh 349Sjkh/* 359Sjkh * strcat(s, append) 369Sjkh * append a copy of the null-terminated string "append" to the end 379Sjkh * of the null-terminated string s, then add a terminating `\0'. 389Sjkh * 399Sjkh * Written by: 4011894Speter * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. 4111894Speter */ 4211894Speter 438858Srgrimes/* 4411894Speter * I've unrolled the loop eight times: large enough to make a 4511894Speter * significant difference, and small enough not to totally trash the 4611894Speter * cache. 4711894Speter */ 4811894Speter 4911894SpeterENTRY(strcat) 5011894Speter pushl %edi /* save edi */ 5111894Speter movl 8(%esp),%edi /* dst address */ 5211894Speter movl 12(%esp),%edx /* src address */ 5311894Speter pushl %edi /* push destination address */ 5411894Speter 5511894Speter cld /* set search forward */ 5611894Speter xorl %eax,%eax /* set search for null terminator */ 5711894Speter movl $-1,%ecx /* set search for lots of characters */ 5811894Speter repne /* search! */ 5911894Speter scasb 6011894Speter 6111894Speter leal -1(%edi),%ecx /* correct dst address */ 6211894Speter 6311894Speter .align 2,0x90 6411894SpeterL1: movb (%edx),%al /* unroll loop, but not too much */ 6511894Speter movb %al,(%ecx) 6611894Speter testb %al,%al 6711894Speter je L2 6811894Speter movb 1(%edx),%al 6911894Speter movb %al,1(%ecx) 7011894Speter testb %al,%al 7111894Speter je L2 7211894Speter movb 2(%edx),%al 7311894Speter movb %al,2(%ecx) 7411894Speter testb %al,%al 7511894Speter je L2 7611894Speter movb 3(%edx),%al 7711894Speter movb %al,3(%ecx) 789Sjkh testb %al,%al 799Sjkh je L2 809Sjkh movb 4(%edx),%al 819Sjkh movb %al,4(%ecx) 829Sjkh testb %al,%al 839Sjkh je L2 849Sjkh movb 5(%edx),%al 859Sjkh movb %al,5(%ecx) 869Sjkh testb %al,%al 879Sjkh je L2 889Sjkh movb 6(%edx),%al 899Sjkh movb %al,6(%ecx) 909Sjkh testb %al,%al 919Sjkh je L2 929Sjkh movb 7(%edx),%al 939Sjkh movb %al,7(%ecx) 949Sjkh addl $8,%edx 959Sjkh addl $8,%ecx 969Sjkh testb %al,%al 979Sjkh jne L1 989SjkhL2: popl %eax /* pop destination address */ 999Sjkh popl %edi /* restore edi */ 1009Sjkh ret 1019SjkhEND(strcat) 1029Sjkh 1039Sjkh .section .note.GNU-stack,"",%progbits 1049Sjkh