2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
* ====================================================
|
2008-05-27 07:31:08 +08:00
|
|
|
* Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved.
|
2000-02-18 03:39:52 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software is freely granted, provided that this notice
|
|
|
|
* is preserved.
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "i386mach.h"
|
2008-05-27 07:31:08 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
.global SYM (memchr)
|
2000-08-29 01:50:06 +08:00
|
|
|
SOTYPE_FUNCTION(memchr)
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
SYM (memchr):
|
2016-03-31 17:12:00 +08:00
|
|
|
#ifdef __iamcu__
|
|
|
|
pushl edi
|
|
|
|
movl eax,edi
|
|
|
|
movl edx,eax
|
|
|
|
xorl edx,edx
|
|
|
|
testl ecx,ecx
|
|
|
|
jz L20
|
|
|
|
|
|
|
|
repnz
|
|
|
|
scasb
|
|
|
|
|
|
|
|
setnz dl
|
|
|
|
decl edi
|
|
|
|
|
|
|
|
decl edx
|
|
|
|
andl edi,edx
|
|
|
|
L20:
|
|
|
|
movl edx,eax
|
|
|
|
|
|
|
|
popl edi
|
|
|
|
#else
|
2000-02-18 03:39:52 +08:00
|
|
|
pushl ebp
|
|
|
|
movl esp,ebp
|
2008-05-27 07:31:08 +08:00
|
|
|
pushl edi
|
|
|
|
movzbl 12(ebp),eax
|
|
|
|
movl 16(ebp),ecx
|
|
|
|
movl 8(ebp),edi
|
2000-02-18 03:39:52 +08:00
|
|
|
xorl edx,edx
|
|
|
|
testl ecx,ecx
|
2008-05-27 07:31:08 +08:00
|
|
|
jz L20
|
|
|
|
|
|
|
|
#ifdef __OPTIMIZE_SIZE__
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
cld
|
|
|
|
repnz
|
|
|
|
scasb
|
|
|
|
|
|
|
|
setnz dl
|
|
|
|
decl edi
|
2008-05-27 07:31:08 +08:00
|
|
|
|
|
|
|
#else /* !__OPTIMIZE_SIZE__ */
|
|
|
|
/* Do byte-wise checks until string is aligned. */
|
|
|
|
testl $3,edi
|
|
|
|
je L5
|
|
|
|
cmpb (edi),al
|
|
|
|
je L15
|
|
|
|
incl edi
|
|
|
|
decl ecx
|
|
|
|
je L20
|
|
|
|
|
|
|
|
testl $3,edi
|
|
|
|
je L5
|
|
|
|
cmpb (edi),al
|
|
|
|
je L15
|
|
|
|
incl edi
|
|
|
|
decl ecx
|
|
|
|
je L20
|
|
|
|
|
|
|
|
testl $3,edi
|
|
|
|
je L5
|
|
|
|
cmpb (edi),al
|
|
|
|
je L15
|
|
|
|
incl edi
|
|
|
|
decl ecx
|
|
|
|
je L20
|
|
|
|
|
|
|
|
/* Create a mask, then check a word at a time. */
|
|
|
|
L5:
|
|
|
|
movb al,ah
|
|
|
|
movl eax,edx
|
|
|
|
sall $16,edx
|
|
|
|
orl edx,eax
|
|
|
|
pushl ebx
|
|
|
|
|
|
|
|
.p2align 4,,7
|
|
|
|
L8:
|
|
|
|
subl $4,ecx
|
|
|
|
jc L9
|
|
|
|
movl (edi),edx
|
|
|
|
addl $4,edi
|
|
|
|
xorl eax,edx
|
|
|
|
leal -16843009(edx),ebx
|
|
|
|
notl edx
|
|
|
|
andl edx,ebx
|
|
|
|
testl $-2139062144,ebx
|
|
|
|
je L8
|
|
|
|
|
|
|
|
subl $4,edi
|
|
|
|
|
|
|
|
L9:
|
|
|
|
popl ebx
|
|
|
|
xorl edx,edx
|
|
|
|
addl $4,ecx
|
|
|
|
je L20
|
|
|
|
|
|
|
|
/* Final byte-wise checks. */
|
|
|
|
.p2align 4,,7
|
|
|
|
L10:
|
|
|
|
cmpb (edi),al
|
|
|
|
je L15
|
|
|
|
incl edi
|
|
|
|
decl ecx
|
|
|
|
jne L10
|
|
|
|
|
|
|
|
xorl edi,edi
|
|
|
|
|
|
|
|
#endif /* !__OPTIMIZE_SIZE__ */
|
|
|
|
|
|
|
|
L15:
|
2000-02-18 03:39:52 +08:00
|
|
|
decl edx
|
|
|
|
andl edi,edx
|
2008-05-27 07:31:08 +08:00
|
|
|
L20:
|
2000-02-18 03:39:52 +08:00
|
|
|
movl edx,eax
|
|
|
|
|
|
|
|
leal -4(ebp),esp
|
|
|
|
popl edi
|
|
|
|
leave
|
2016-03-31 17:12:00 +08:00
|
|
|
#endif
|
2000-02-18 03:39:52 +08:00
|
|
|
ret
|