mirror of
https://github.com/ipxe/ipxe
synced 2025-12-28 18:42:53 +03:00
[libc] Reduce overall code size by externalising memmove()
Typical saving is 15-20 bytes in each file using memmove(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -35,7 +35,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
* @v len Length
|
||||
* @ret dest Destination address
|
||||
*/
|
||||
void * __memcpy ( void *dest, const void *src, size_t len ) {
|
||||
void * __attribute__ (( noinline )) __memcpy ( void *dest, const void *src,
|
||||
size_t len ) {
|
||||
void *edi = dest;
|
||||
const void *esi = src;
|
||||
int discard_ecx;
|
||||
@@ -56,3 +57,50 @@ void * __memcpy ( void *dest, const void *src, size_t len ) {
|
||||
: "memory" );
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy memory area backwards
|
||||
*
|
||||
* @v dest Destination address
|
||||
* @v src Source address
|
||||
* @v len Length
|
||||
* @ret dest Destination address
|
||||
*/
|
||||
void * __attribute__ (( noinline )) __memcpy_reverse ( void *dest,
|
||||
const void *src,
|
||||
size_t len ) {
|
||||
void *edi = ( dest + len - 1 );
|
||||
const void *esi = ( src + len - 1 );
|
||||
int discard_ecx;
|
||||
|
||||
/* Assume memmove() is not performance-critical, and perform a
|
||||
* bytewise copy for simplicity.
|
||||
*/
|
||||
__asm__ __volatile__ ( "std\n\t"
|
||||
"rep movsb\n\t"
|
||||
"cld\n\t"
|
||||
: "=&D" ( edi ), "=&S" ( esi ),
|
||||
"=&c" ( discard_ecx )
|
||||
: "0" ( edi ), "1" ( esi ),
|
||||
"2" ( len )
|
||||
: "memory" );
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy (possibly overlapping) memory area
|
||||
*
|
||||
* @v dest Destination address
|
||||
* @v src Source address
|
||||
* @v len Length
|
||||
* @ret dest Destination address
|
||||
*/
|
||||
void * __memmove ( void *dest, const void *src, size_t len ) {
|
||||
|
||||
if ( dest <= src ) {
|
||||
return __memcpy ( dest, src, len );
|
||||
} else {
|
||||
return __memcpy_reverse ( dest, src, len );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user