summaryrefslogtreecommitdiff
path: root/libc/string/i386/strrchr.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-17 01:31:29 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-17 01:31:29 +0000
commit3d21a36bcd1441e88529eb990d0f9d8ac41a2a4d (patch)
tree9f7a4b991c35b4bbf8c503efe742b1b9187cfeb3 /libc/string/i386/strrchr.c
parentb233676db696ec4bb4a9d55e76ec8012e6f7a22c (diff)
memchr: smaller i386 version
strrchr: smaller i386 version text data bss dec hex filename - 33 0 0 33 21 libc/string/i386/memchr.o + 28 0 0 28 1c libc/string/i386/memchr.o - 31 0 0 31 1f libc/string/i386/strrchr.o + 26 0 0 26 1a libc/string/i386/strrchr.o
Diffstat (limited to 'libc/string/i386/strrchr.c')
-rw-r--r--libc/string/i386/strrchr.c29
1 files changed, 17 insertions, 12 deletions
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__