From 6a3dfed789e30191406785ad013619984fba6dda Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 3 Mar 2008 16:55:15 -0800 Subject: [PATCH] Drop unnecessary CLD instructions. 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 | 1 - com32/lib/mempcpy.S | 1 - com32/lib/memset.c | 16 ++-------------- com32/lib/sys/vesa/drawtxt.c | 2 +- com32/lib/sys/vesa/fill.h | 6 +++--- com32/modules/mboot.c | 6 +++--- 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/com32/lib/memcpy.S b/com32/lib/memcpy.S index ed8e20e..a893d24 100644 --- a/com32/lib/memcpy.S +++ b/com32/lib/memcpy.S @@ -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 diff --git a/com32/lib/mempcpy.S b/com32/lib/mempcpy.S index aa17f47..eeab918 100644 --- a/com32/lib/mempcpy.S +++ b/com32/lib/mempcpy.S @@ -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 diff --git a/com32/lib/memset.c b/com32/lib/memset.c index 522cc59..516ad47 100644 --- a/com32/lib/memset.c +++ b/com32/lib/memset.c @@ -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; } diff --git a/com32/lib/sys/vesa/drawtxt.c b/com32/lib/sys/vesa/drawtxt.c index 6e21a34..662eebe 100644 --- a/com32/lib/sys/vesa/drawtxt.c +++ b/com32/lib/sys/vesa/drawtxt.c @@ -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 */ } diff --git a/com32/lib/sys/vesa/fill.h b/com32/lib/sys/vesa/fill.h index 4d4a9f9..63ca577 100644 --- a/com32/lib/sys/vesa/fill.h +++ b/com32/lib/sys/vesa/fill.h @@ -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"); diff --git a/com32/modules/mboot.c b/com32/modules/mboot.c index 3d74425..6c3ce34 100644 --- a/com32/modules/mboot.c +++ b/com32/modules/mboot.c @@ -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)); } } -- 2.7.4