summaryrefslogtreecommitdiff
path: root/libc/string/i386
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string/i386')
-rw-r--r--libc/string/i386/memchr.c31
-rw-r--r--libc/string/i386/strrchr.c29
2 files changed, 34 insertions, 26 deletions
diff --git a/libc/string/i386/memchr.c b/libc/string/i386/memchr.c
index fe4537914..bff0538d7 100644
--- a/libc/string/i386/memchr.c
+++ b/libc/string/i386/memchr.c
@@ -32,20 +32,23 @@
#include <string.h>
-/* Experimentally off - libc_hidden_proto(memchr) */
-void *memchr(const void *cs, int c, size_t count)
+#undef memchr
+void *memchr(const void *s, int c, size_t count)
{
- int d0;
- register void * __res;
- if (!count)
- return NULL;
- __asm__ __volatile__(
- "repne\n\t"
- "scasb\n\t"
- "je 1f\n\t"
- "movl $1,%0\n"
- "1:\tdecl %0"
- :"=D" (__res), "=&c" (d0) : "a" (c),"0" (cs),"1" (count));
- return __res;
+ void *edi;
+ int ecx;
+ __asm__ __volatile__(
+ " jecxz 1f\n"
+ " repne; scasb\n"
+ " leal -1(%%edi), %%edi\n"
+ " je 2f\n"
+ "1:\n"
+ " xorl %%edi, %%edi\n" /* NULL */
+ "2:\n"
+ : "=&D" (edi), "=&c" (ecx)
+ : "a" (c), "0" (s), "1" (count)
+ /* : no clobbers */
+ );
+ return edi;
}
libc_hidden_def(memchr)
diff --git a/libc/string/i386/strrchr.c b/libc/string/i386/strrchr.c
index ef378685b..3209b1d76 100644
--- a/libc/string/i386/strrchr.c
+++ b/libc/string/i386/strrchr.c
@@ -35,18 +35,23 @@
/* Experimentally off - libc_hidden_proto(strrchr) */
char *strrchr(const char *s, int c)
{
- int d0, d1;
- register char * __res;
- __asm__ __volatile__(
- "movb %%al,%%ah\n"
- "1:\tlodsb\n\t"
- "cmpb %%ah,%%al\n\t"
- "jne 2f\n\t"
- "leal -1(%%esi),%0\n"
- "2:\ttestb %%al,%%al\n\t"
- "jne 1b"
- :"=g" (__res), "=&S" (d0), "=&a" (d1) :"0" (0),"1" (s),"2" (c));
- return __res;
+ char *retval;
+
+ __asm__ __volatile__(
+ " movb %%cl, %%ch\n"
+ "1: movb (%1), %%cl\n" /* load char */
+ " cmpb %%cl, %%ch\n" /* char == c? */
+ " jne 2f\n"
+ " movl %1, %0\n"
+ "2: incl %1\n"
+ " testb %%cl, %%cl\n" /* char == NUL? */
+ " jnz 1b\n"
+ /* "=c": use ecx, not ebx (-fpic uses it). */
+ : "=a" (retval), "=r" (s), "=c" (c)
+ : "0" (0), "1" (s), "2" (c)
+ /* : no clobbers */
+ );
+ return retval;
}
libc_hidden_def(strrchr)
#ifdef __UCLIBC_SUSV3_LEGACY__