Drop unnecessary CLD instructions.
authorH. Peter Anvin <hpa@zytor.com>
Tue, 4 Mar 2008 00:55:15 +0000 (16:55 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 4 Mar 2008 00:55:15 +0000 (16:55 -0800)
The EFI ABI spec states that DF=0 on ABI boundaries, and gcc expects
this.  Assume it is safe to rely upon everywhere; drop unnecessary cld
instructions, except on entry and (obviously) after std.

com32/lib/memcpy.S
com32/lib/mempcpy.S
com32/lib/memset.c
com32/lib/sys/vesa/drawtxt.c
com32/lib/sys/vesa/fill.h
com32/modules/mboot.c

index ed8e20e..a893d24 100644 (file)
@@ -19,7 +19,6 @@ memcpy:
        movl    %ecx, %edx
 
        shrl    $2, %ecx
-       cld
        rep ; movsl
 
        jnc     1f              # The shrl had carry out if odd word count
index aa17f47..eeab918 100644 (file)
@@ -19,7 +19,6 @@ mempcpy:
        movl    %ecx, %edx
 
        shrl    $2, %ecx
-       cld
        rep ; movsl
 
        jnc     1f              # The shrl had carry out if odd word count
index 522cc59..516ad47 100644 (file)
@@ -8,23 +8,11 @@
 void *memset(void *dst, int c, size_t n)
 {
   char *q = dst;
-
-#if defined(__i386__)
   size_t nl = n >> 2;
-  asm volatile("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb"
+
+  asm volatile("rep ; stosl ; movl %3,%0 ; rep ; stosb"
               : "+c" (nl), "+D" (q)
               : "a" ((unsigned char)c * 0x01010101U), "r" (n & 3));
-#elif defined(__x86_64__)
-  size_t nq = n >> 3;
-  asm volatile("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb"
-              : "+c" (nq), "+D" (q)
-              : "a" ((unsigned char)c * 0x0101010101010101U),
-              "r" ((uint32_t)n & 7));
-#else
-  while ( n-- ) {
-    *q++ = c;
-  }
-#endif
 
   return dst;
 }
index 6e21a34..662eebe 100644 (file)
@@ -40,7 +40,7 @@ static int cursor_x, cursor_y;
 
 static inline void *copy_dword(void *dst, void *src, size_t dword_count)
 {
-  asm volatile("cld; rep; movsl"
+  asm volatile("rep; movsl"
               : "+D" (dst), "+S" (src), "+c" (dword_count));
   return dst;                  /* Updated destination pointer */
 }
index 4d4a9f9..63ca577 100644 (file)
@@ -37,19 +37,19 @@ static inline struct vesa_char *vesacon_fill(struct vesa_char *ptr,
 {
   switch (sizeof(struct vesa_char)) {
   case 1:
-    asm volatile("cld; rep; stosb"
+    asm volatile("rep; stosb"
                 : "+D" (ptr), "+c" (count)
                 : "a" (fill)
                 : "memory");
     break;
   case 2:
-    asm volatile("cld; rep; stosw"
+    asm volatile("rep; stosw"
                 : "+D" (ptr), "+c" (count)
                 : "a" (fill)
                 : "memory");
     break;
   case 4:
-    asm volatile("cld; rep; stosl"
+    asm volatile("rep; stosl"
                 : "+D" (ptr), "+c" (count)
                 : "a" (fill)
                 : "memory");
index 3d74425..6c3ce34 100644 (file)
@@ -835,7 +835,7 @@ static void trampoline_start(section_t *secs, int sec_count,
             /* asm bzero() code from com32/lib/memset.c */
             char *q = (char *) secs[i].dest;
             size_t nl = secs[i].size >> 2;
-            asm volatile("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb"
+            asm volatile("rep ; stosl ; movl %3,%0 ; rep ; stosb"
                          : "+c" (nl), "+D" (q)
                          : "a" (0x0U), "r" (secs[i].size & 3));
         } else {
@@ -844,12 +844,12 @@ static void trampoline_start(section_t *secs, int sec_count,
             char *q = (char *) secs[i].dest;
             size_t n = secs[i].size;
             if ( q < p ) {
-                asm volatile("cld ; rep ; movsb"
+                asm volatile("rep ; movsb"
                              : "+c" (n), "+S" (p), "+D" (q));
             } else {
                 p += (n-1);
                 q += (n-1);
-                asm volatile("std ; rep ; movsb"
+                asm volatile("std ; rep ; movsb ; cld"
                              : "+c" (n), "+S" (p), "+D" (q));
             }
         }