1/* 2 * Written by J.T. Conklin <jtc@netbsd.org>. 3 * Public domain. 4 */ 5 6#include <machine/asm.h> 7 8#if defined(LIBC_SCCS) 9 .text 10 .asciz "$OpenBSD: strcat.S,v 1.2 1996/08/19 08:13:12 tholo Exp $" 11#endif 12 13/* 14 * NOTE: I've unrolled the loop eight times: large enough to make a 15 * significant difference, and small enough not to totally trash the 16 * cache. 17 */ 18 19ENTRY(strcat) 20 pushl %edi /* save edi */ 21 movl 8(%esp),%edi /* dst address */ 22 movl 12(%esp),%edx /* src address */ 23 pushl %edi /* push destination address */ 24 25 cld /* set search forward */ 26 xorl %eax,%eax /* set search for null terminator */ 27 movl $-1,%ecx /* set search for lots of characters */ 28 repne /* search! */ 29 scasb 30 31 leal -1(%edi),%ecx /* correct dst address */ 32 33 .align 2,0x90 34L1: movb (%edx),%al /* unroll loop, but not too much */ 35 movb %al,(%ecx) 36 testb %al,%al 37 jz L2 38 movb 1(%edx),%al 39 movb %al,1(%ecx) 40 testb %al,%al 41 jz L2 42 movb 2(%edx),%al 43 movb %al,2(%ecx) 44 testb %al,%al 45 jz L2 46 movb 3(%edx),%al 47 movb %al,3(%ecx) 48 testb %al,%al 49 jz L2 50 movb 4(%edx),%al 51 movb %al,4(%ecx) 52 testb %al,%al 53 jz L2 54 movb 5(%edx),%al 55 movb %al,5(%ecx) 56 testb %al,%al 57 jz L2 58 movb 6(%edx),%al 59 movb %al,6(%ecx) 60 testb %al,%al 61 jz L2 62 movb 7(%edx),%al 63 movb %al,7(%ecx) 64 addl $8,%edx 65 addl $8,%ecx 66 testb %al,%al 67 jnz L1 68L2: popl %eax /* pop destination address */ 69 popl %edi /* restore edi */ 70 ret 71