]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Simplify memcpy() implementation
authorMichael Brown <mcb30@ipxe.org>
Tue, 26 Jun 2012 11:42:24 +0000 (12:42 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 27 Jun 2012 18:15:17 +0000 (19:15 +0100)
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>
src/arch/x86/core/x86_string.c

index 5838ebace29de5e3904d7926ba744240efcf71fc..8c3a4d2a0d70d5c9e671f3f158f933bdf9d0a3c9 100644 (file)
@@ -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;
 }