Преглед изворни кода

[libc] Reduce overall code size by externalising strlen()

Typical saving is 5-20 bytes in each file using strlen().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown пре 11 година
родитељ
комит
de20c526e6
2 измењених фајлова са 20 додато и 12 уклоњено
  1. 18
    0
      src/arch/x86/core/x86_string.c
  2. 2
    12
      src/arch/x86/include/bits/string.h

+ 18
- 0
src/arch/x86/core/x86_string.c Прегледај датотеку

@@ -105,6 +105,24 @@ void * __memmove ( void *dest, const void *src, size_t len ) {
105 105
 	}
106 106
 }
107 107
 
108
+/**
109
+ * Calculate length of string
110
+ *
111
+ * @v string		String
112
+ * @ret len		Length (excluding NUL)
113
+ */
114
+size_t strlen ( const char *string ) {
115
+	const char *discard_D;
116
+	size_t len_plus_one;
117
+
118
+	__asm__ __volatile__ ( "repne scasb\n\t"
119
+			       "not %1\n\t"
120
+			       : "=&D" ( discard_D ), "=&c" ( len_plus_one )
121
+			       : "0" ( string ), "1" ( -1UL ), "a" ( 0 ) );
122
+
123
+	return ( len_plus_one - 1 );
124
+}
125
+
108 126
 /**
109 127
  * Compare strings (up to a specified length)
110 128
  *

+ 2
- 12
src/arch/x86/include/bits/string.h Прегледај датотеку

@@ -234,17 +234,7 @@ return dest;
234 234
 extern int strncmp ( const char *str1, const char *str2, size_t len );
235 235
 
236 236
 #define __HAVE_ARCH_STRLEN
237
-static inline size_t strlen(const char * s)
238
-{
239
-int d0;
240
-register int __res;
241
-__asm__ __volatile__(
242
-	"repne\n\t"
243
-	"scasb\n\t"
244
-	"notl %0\n\t"
245
-	"decl %0"
246
-	:"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffff));
247
-return __res;
248
-}
237
+
238
+extern size_t strlen ( const char *string );
249 239
 
250 240
 #endif /* ETHERBOOT_BITS_STRING_H */

Loading…
Откажи
Сачувај