Kaynağa Gözat

[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>
tags/v1.20.1
Michael Brown 12 yıl önce
ebeveyn
işleme
6a4ff519c8
1 değiştirilmiş dosya ile 10 ekleme ve 16 silme
  1. 10
    16
      src/arch/x86/core/x86_string.c

+ 10
- 16
src/arch/x86/core/x86_string.c Dosyayı Görüntüle

@@ -43,21 +43,15 @@ void * __memcpy ( void *dest, const void *src, size_t len ) {
43 43
 	 * moves.  Using movsl rather than movsb speeds these up by
44 44
 	 * around 32%.
45 45
 	 */
46
-	if ( len >> 2 ) {
47
-		__asm__ __volatile__ ( "rep movsl"
48
-				       : "=&D" ( edi ), "=&S" ( esi ),
49
-				         "=&c" ( discard_ecx )
50
-				       : "0" ( edi ), "1" ( esi ),
51
-				         "2" ( len >> 2 )
52
-				       : "memory" );
53
-	}
54
-	if ( len & 0x02 ) {
55
-		__asm__ __volatile__ ( "movsw" : "=&D" ( edi ), "=&S" ( esi )
56
-				       : "0" ( edi ), "1" ( esi ) : "memory" );
57
-	}
58
-	if ( len & 0x01 ) {
59
-		__asm__ __volatile__ ( "movsb" : "=&D" ( edi ), "=&S" ( esi )
60
-				       : "0" ( edi ), "1" ( esi ) : "memory" );
61
-	}
46
+	__asm__ __volatile__ ( "rep movsl"
47
+			       : "=&D" ( edi ), "=&S" ( esi ),
48
+				 "=&c" ( discard_ecx )
49
+			       : "0" ( edi ), "1" ( esi ), "2" ( len >> 2 )
50
+			       : "memory" );
51
+	__asm__ __volatile__ ( "rep movsb"
52
+			       : "=&D" ( edi ), "=&S" ( esi ),
53
+				 "=&c" ( discard_ecx )
54
+			       : "0" ( edi ), "1" ( esi ), "2" ( len & 3 )
55
+			       : "memory" );
62 56
 	return dest;
63 57
 }

Loading…
İptal
Kaydet