summaryrefslogtreecommitdiff
path: root/libc/string/i386
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-19 15:10:25 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-19 15:10:25 +0000
commita0da3cfbbff226c7792be30e2bb277386e7cd086 (patch)
treefe95a266173eb9b2fa10a9abe9fa916819a9a318 /libc/string/i386
parent5bd420df5ed83791e0c65b445fbb54614d1a9d0a (diff)
strchr: a bit faster version for i386 (same code size)
Diffstat (limited to 'libc/string/i386')
-rw-r--r--libc/string/i386/strchr.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/libc/string/i386/strchr.c b/libc/string/i386/strchr.c
index 46b1dfb6e..93cc9583e 100644
--- a/libc/string/i386/strchr.c
+++ b/libc/string/i386/strchr.c
@@ -32,23 +32,25 @@
#include <string.h>
-/* Experimentally off - libc_hidden_proto(strchr) */
+#undef strchr
char *strchr(const char *s, int c)
{
- int d0;
- register char * __res;
- __asm__ __volatile__(
- "movb %%al,%%ah\n"
- "1:\tlodsb\n\t"
- "cmpb %%ah,%%al\n\t"
- "je 2f\n\t"
- "testb %%al,%%al\n\t"
- "jne 1b\n\t"
- "movl $1,%1\n"
- "2:\tmovl %1,%0\n\t"
- "decl %0"
- :"=a" (__res), "=&S" (d0) : "1" (s),"0" (c));
- return __res;
+ int esi;
+ register char * eax;
+ __asm__ __volatile__(
+ " movb %%al, %%ah\n"
+ "1: lodsb\n"
+ " cmpb %%ah, %%al\n"
+ " je 2f\n"
+ " testb %%al, %%al\n"
+ " jnz 1b\n"
+ " movl $1, %%esi\n" /* can use shorter xor + inc */
+ "2: leal -1(%%esi), %%eax\n"
+ : "=a" (eax), "=&S" (esi)
+ : "0" (c), "1" (s)
+ /* no clobbers */
+ );
+ return eax;
}
libc_hidden_def(strchr)
#ifdef __UCLIBC_SUSV3_LEGACY__