#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strcat.S,v 1.2 2014/03/22 19:38:46 jakllsch Exp $")
#endif
ENTRY(strcat)
pushl %ebx
movl 8(%esp),%ecx
movl 12(%esp),%eax
.Lscan:
.Lscan_align:
testb $3,%cl
je .Lscan_aligned
cmpb $0,(%ecx)
je .Lcopy
incl %ecx
jmp .Lscan_align
_ALIGN_TEXT
.Lscan_aligned:
.Lscan_loop:
movl (%ecx),%ebx
addl $4,%ecx
leal -0x01010101(%ebx),%edx
testl $0x80808080,%edx
je .Lscan_loop
testb %bl,%bl
jne 1f
subl $4,%ecx
jmp .Lcopy
1: testb %bh,%bh
jne 1f
subl $3,%ecx
jmp .Lcopy
1: shrl $16,%ebx
testb %bl,%bl
jne 1f
subl $2,%ecx
jmp .Lcopy
1: testb %bh,%bh
jne .Lscan_loop
subl $1,%ecx
.Lcopy:
.Lcopy_align:
testl $3,%eax
je .Lcopy_aligned
movb (%eax),%bl
incl %eax
movb %bl,(%ecx)
incl %ecx
testb %bl,%bl
jne .Lcopy_align
jmp .Ldone
_ALIGN_TEXT
.Lcopy_loop:
movl %ebx,(%ecx)
addl $4,%ecx
.Lcopy_aligned:
movl (%eax),%ebx
addl $4,%eax
leal -0x01010101(%ebx),%edx
testl $0x80808080,%edx
je .Lcopy_loop
movb %bl,(%ecx)
incl %ecx
testb %bl,%bl
je .Ldone
movb %bh,(%ecx)
incl %ecx
testb %bh,%bh
je .Ldone
shrl $16,%ebx
movb %bl,(%ecx)
incl %ecx
testb %bl,%bl
je .Ldone
movb %bh,(%ecx)
incl %ecx
testb %bh,%bh
jne .Lcopy_aligned
.Ldone:
movl 8(%esp),%eax
popl %ebx
ret
END(strcat)