Browse Source

libc/string/i386/rawmemchr.c: i386 version, adapted from strlen()
libc/string/i386/strlen.c: small optimization, same code size)

text data bss dec hex filename
- 240449 1759 11960 254168 3e0d8 lib/libuClibc-0.9.30-svn.so
+ 240339 1759 11960 254058 3e06a lib/libuClibc-0.9.30-svn.so

Denis Vlasenko 15 years ago
parent
commit
7dd4382306
2 changed files with 33 additions and 9 deletions
  1. 24 0
      libc/string/i386/rawmemchr.c
  2. 9 9
      libc/string/i386/strlen.c

+ 24 - 0
libc/string/i386/rawmemchr.c

@@ -0,0 +1,24 @@
+/*
+ * Adapted from strlen.c code
+ *
+ * Copyright (C) 2008 Denys Vlasenko <vda.linux@googlemail.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <string.h>
+
+#undef rawmemchr
+void *rawmemchr(const void *s, int c)
+{
+	void *eax;
+	int ecx, edi;
+	__asm__ __volatile__(
+		"	repne; scasb\n"
+		"	leal	-1(%%edi), %%eax\n"
+		: "=&c" (ecx), "=&D" (edi), "=&a" (eax)
+		: "0" (0xffffffff), "1" (s), "2" (c)
+	);
+	return eax;
+}
+libc_hidden_def(rawmemchr)

+ 9 - 9
libc/string/i386/strlen.c

@@ -35,14 +35,14 @@
 #undef strlen
 size_t strlen(const char *s)
 {
-    int d0;
-    register int __res;
-    __asm__ __volatile__(
-	    "repne\n\t"
-	    "scasb\n\t"
-	    "notl %0\n\t"
-	    "decl %0"
-	    :"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffff));
-    return __res;
+	int eax, ecx, edi;
+	__asm__ __volatile__(
+		"	repne; scasb\n"
+		"	notl	%%ecx\n"
+		"	leal	-1(%%ecx), %%eax\n"
+		: "=&c" (ecx), "=&D" (edi), "=&a" (eax)
+		: "0" (0xffffffff), "1" (s), "2" (0)
+	);
+	return eax;
 }
 libc_hidden_def(strlen)