#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strchr.S,v 1.3 2014/03/22 19:38:46 jakllsch Exp $")
#endif
ENTRY(strchr)
pushl %esi
pushl %ebx
movl 12(%esp),%eax
movzbl 16(%esp),%ecx
.Lalign:
testb $3,%al
je .Lword_aligned
movb (%eax),%bl
cmpb %cl,%bl
je .Ldone
testb %bl,%bl
je .Lzero
incl %eax
jmp .Lalign
.Lword_aligned:
movb %cl,%ch
movl %ecx,%edx
sall $16,%ecx
orl %edx,%ecx
_ALIGN_TEXT
.Lloop:
movl (%eax),%ebx
addl $4,%eax
movl %ebx,%esi
leal -0x01010101(%ebx),%edx
xorl %ecx,%esi
subl $0x01010101,%esi
orl %esi,%edx
testl $0x80808080,%edx
je .Lloop
_ALIGN_TEXT
cmpb %cl,%bl
jne 1f
subl $4,%eax
jmp .Ldone
1: testb %bl,%bl
je .Lzero
cmpb %cl,%bh
jne 1f
subl $3,%eax
jmp .Ldone
1: testb %bh,%bh
je .Lzero
shrl $16,%ebx
cmpb %cl,%bl
jne 1f
subl $2,%eax
jmp .Ldone
1: testb %bl,%bl
je .Lzero
cmpb %cl,%bh
jne 1f
decl %eax
jmp .Ldone
1: testb %bh,%bh
jne .Lloop
.Lzero:
xorl %eax,%eax
.Ldone:
popl %ebx
popl %esi
ret
END(strchr)
STRONG_ALIAS(index,strchr)