diff options
| author | Michael Brown | 2012-11-05 01:25:25 +0100 |
|---|---|---|
| committer | Michael Brown | 2012-11-12 17:58:49 +0100 |
| commit | de20c526e68f7ec1155cdb7dcaeb2ff4c8c2c580 (patch) | |
| tree | 7bd001122acc5bad2709ca20a87b9065d576ebbe /src/arch/x86/core/x86_string.c | |
| parent | [libc] Reduce overall code size by externalising strncmp() (diff) | |
| download | ipxe-de20c526e68f7ec1155cdb7dcaeb2ff4c8c2c580.tar.gz ipxe-de20c526e68f7ec1155cdb7dcaeb2ff4c8c2c580.tar.xz ipxe-de20c526e68f7ec1155cdb7dcaeb2ff4c8c2c580.zip | |
[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>
Diffstat (limited to 'src/arch/x86/core/x86_string.c')
| -rw-r--r-- | src/arch/x86/core/x86_string.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/arch/x86/core/x86_string.c b/src/arch/x86/core/x86_string.c index 962a7d84d..69c73f704 100644 --- a/src/arch/x86/core/x86_string.c +++ b/src/arch/x86/core/x86_string.c @@ -106,6 +106,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) * * @v str1 First string |
