]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Reduce overall code size by externalising strlen()
authorMichael Brown <mcb30@ipxe.org>
Mon, 5 Nov 2012 00:25:25 +0000 (00:25 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 12 Nov 2012 16:58:49 +0000 (16:58 +0000)
Typical saving is 5-20 bytes in each file using strlen().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/core/x86_string.c
src/arch/x86/include/bits/string.h

index 962a7d84df766ba51dfaaafb4a9ae64ddaafd595..69c73f7042b2871a8ee804e08e4322376d765acf 100644 (file)
@@ -105,6 +105,24 @@ void * __memmove ( void *dest, const void *src, size_t len ) {
        }
 }
 
+/**
+ * Calculate length of string
+ *
+ * @v string           String
+ * @ret len            Length (excluding NUL)
+ */
+size_t strlen ( const char *string ) {
+       const char *discard_D;
+       size_t len_plus_one;
+
+       __asm__ __volatile__ ( "repne scasb\n\t"
+                              "not %1\n\t"
+                              : "=&D" ( discard_D ), "=&c" ( len_plus_one )
+                              : "0" ( string ), "1" ( -1UL ), "a" ( 0 ) );
+
+       return ( len_plus_one - 1 );
+}
+
 /**
  * Compare strings (up to a specified length)
  *
index 75a1f01a88428212d40f2c1bfb9ac5e35e5d3a55..249dd543878cc41104bba7733c90db46f325217b 100644 (file)
@@ -234,17 +234,7 @@ return dest;
 extern int strncmp ( const char *str1, const char *str2, size_t len );
 
 #define __HAVE_ARCH_STRLEN
-static inline 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;
-}
+
+extern size_t strlen ( const char *string );
 
 #endif /* ETHERBOOT_BITS_STRING_H */