summaryrefslogtreecommitdiff
path: root/libc/string/i386/memchr.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/memchr.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/memchr.c')
-rw-r--r--libc/string/i386/memchr.c31
1 files changed, 17 insertions, 14 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)