ia64/xen-unstable

view xen/arch/x86/string.c @ 15744:8c77ae93f982

x86: Improved memcpy() asm implementation.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kfraser@localhost.localdomain
date Fri Aug 10 15:01:09 2007 +0100 (2007-08-10)
parents ddd290cc8f0d
children 2052364cb456
line source
1 /******************************************************************************
2 * string.c
3 *
4 * These provide something for compiler-emitted string operations to link
5 * against.
6 */
8 #include <xen/config.h>
9 #include <xen/lib.h>
11 #undef memcpy
12 void *memcpy(void *dest, const void *src, size_t n)
13 {
14 long d0, d1, d2;
16 __asm__ __volatile__ (
17 #ifdef __i386__
18 " rep movsl ; "
19 #else
20 " rep movsq ; "
21 " testb $4,%b4 ; "
22 " je 0f ; "
23 " movsl ; "
24 "0: ; "
25 #endif
26 " testb $2,%b4 ; "
27 " je 1f ; "
28 " movsw ; "
29 "1: testb $1,%b4 ; "
30 " je 2f ; "
31 " movsb ; "
32 "2: "
33 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
34 : "0" (n/sizeof(long)), "q" (n), "1" (dest), "2" (src)
35 : "memory");
37 return dest;
38 }
40 #undef memset
41 void *memset(void *s, int c, size_t n)
42 {
43 long d0, d1;
45 __asm__ __volatile__ (
46 "rep stosb"
47 : "=&c" (d0), "=&D" (d1)
48 : "a" (c), "1" (s), "0" (n)
49 : "memory");
51 return s;
52 }
54 #undef memmove
55 void *memmove(void *dest, const void *src, size_t n)
56 {
57 long d0, d1, d2;
59 if ( dest < src )
60 return memcpy(dest, src, n);
62 __asm__ __volatile__ (
63 " std ; "
64 " rep movsb ; "
65 " cld "
66 : "=&c" (d0), "=&S" (d1), "=&D" (d2)
67 : "0" (n), "1" (n-1+(const char *)src), "2" (n-1+(char *)dest)
68 : "memory");
70 return dest;
71 }