mirror of
https://github.com/ipxe/ipxe
synced 2025-12-29 02:52:36 +03:00
[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>
This commit is contained in:
@@ -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)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user