aboutsummaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2012-06-26 12:42:24 +0100
committerMichael Brown <mcb30@ipxe.org>2012-06-27 19:15:17 +0100
commit6a4ff519c8c21c8acbedb5e2db4d92c14e99d9f1 (patch)
treea612387309352b1c87cafdf715b0f2b72c1e4f89 /src/arch
parent80cdf6acc7ab27060ce1bd164ada214e20a69e1a (diff)
downloadipxe-6a4ff519c8c21c8acbedb5e2db4d92c14e99d9f1.zip
ipxe-6a4ff519c8c21c8acbedb5e2db4d92c14e99d9f1.tar.gz
ipxe-6a4ff519c8c21c8acbedb5e2db4d92c14e99d9f1.tar.bz2
[libc] Simplify memcpy() implementation
The "rep" prefix can be used with an iteration count of zero, which allows the variable-length memcpy() to be implemented without using any conditional jumps. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/x86/core/x86_string.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/arch/x86/core/x86_string.c b/src/arch/x86/core/x86_string.c
index 5838eba..8c3a4d2 100644
--- a/src/arch/x86/core/x86_string.c
+++ b/src/arch/x86/core/x86_string.c
@@ -43,21 +43,15 @@ void * __memcpy ( void *dest, const void *src, size_t len ) {
* moves. Using movsl rather than movsb speeds these up by
* around 32%.
*/
- if ( len >> 2 ) {
- __asm__ __volatile__ ( "rep movsl"
- : "=&D" ( edi ), "=&S" ( esi ),
- "=&c" ( discard_ecx )
- : "0" ( edi ), "1" ( esi ),
- "2" ( len >> 2 )
- : "memory" );
- }
- if ( len & 0x02 ) {
- __asm__ __volatile__ ( "movsw" : "=&D" ( edi ), "=&S" ( esi )
- : "0" ( edi ), "1" ( esi ) : "memory" );
- }
- if ( len & 0x01 ) {
- __asm__ __volatile__ ( "movsb" : "=&D" ( edi ), "=&S" ( esi )
- : "0" ( edi ), "1" ( esi ) : "memory" );
- }
+ __asm__ __volatile__ ( "rep movsl"
+ : "=&D" ( edi ), "=&S" ( esi ),
+ "=&c" ( discard_ecx )
+ : "0" ( edi ), "1" ( esi ), "2" ( len >> 2 )
+ : "memory" );
+ __asm__ __volatile__ ( "rep movsb"
+ : "=&D" ( edi ), "=&S" ( esi ),
+ "=&c" ( discard_ecx )
+ : "0" ( edi ), "1" ( esi ), "2" ( len & 3 )
+ : "memory" );
return dest;
}