1 #include <linux/string.h>
2 #include <linux/module.h>
7 void *memcpy(void *to
, const void *from
, size_t n
)
9 #ifdef CONFIG_X86_USE_3DNOW
10 return __memcpy3d(to
, from
, n
);
12 return __memcpy(to
, from
, n
);
15 EXPORT_SYMBOL(memcpy
);
17 void *memset(void *s
, int c
, size_t count
)
19 return __memset(s
, c
, count
);
21 EXPORT_SYMBOL(memset
);
23 void *memmove(void *dest
, const void *src
, size_t n
)
25 int d0
,d1
,d2
,d3
,d4
,d5
;
29 /* Handle more 16 bytes in loop */
33 /* Decide forward/backward copy mode */
38 * movs instruction have many startup latency
39 * so we handle small size by general register.
44 * movs instruction is only good for aligned case.
54 * We gobble 16 bytes forward in each loop.
66 "lea 0x10(%1), %1\n\t"
67 "lea 0x10(%2), %2\n\t"
73 * Handle data forward by movs.
77 "mov -4(%1, %0), %3\n\t"
78 "lea -4(%2, %0), %4\n\t"
84 * Handle data backward by movs.
90 "lea -4(%1, %0), %1\n\t"
91 "lea -4(%2, %0), %2\n\t"
100 * Start to prepare for backward copy.
112 * Calculate copy position to tail.
120 * We gobble 16 bytes backward in each loop.
125 "mov -1*4(%1), %3\n\t"
126 "mov -2*4(%1), %4\n\t"
127 "mov %3, -1*4(%2)\n\t"
128 "mov %4, -2*4(%2)\n\t"
129 "mov -3*4(%1), %3\n\t"
130 "mov -4*4(%1), %4\n\t"
131 "mov %3, -3*4(%2)\n\t"
132 "mov %4, -4*4(%2)\n\t"
133 "lea -0x10(%1), %1\n\t"
134 "lea -0x10(%2), %2\n\t"
137 * Calculate copy position to head.
144 * Move data from 8 bytes to 15 bytes.
150 "mov 0*4(%1), %3\n\t"
151 "mov 1*4(%1), %4\n\t"
152 "mov -2*4(%1, %0), %5\n\t"
153 "mov -1*4(%1, %0), %1\n\t"
155 "mov %3, 0*4(%2)\n\t"
156 "mov %4, 1*4(%2)\n\t"
157 "mov %5, -2*4(%2, %0)\n\t"
158 "mov %1, -1*4(%2, %0)\n\t"
162 * Move data from 4 bytes to 7 bytes.
168 "mov 0*4(%1), %3\n\t"
169 "mov -1*4(%1, %0), %4\n\t"
170 "mov %3, 0*4(%2)\n\t"
171 "mov %4, -1*4(%2, %0)\n\t"
175 * Move data from 2 bytes to 3 bytes.
181 "movw 0*2(%1), %%dx\n\t"
182 "movw -1*2(%1, %0), %%bx\n\t"
183 "movw %%dx, 0*2(%2)\n\t"
184 "movw %%bx, -1*2(%2, %0)\n\t"
188 * Move data for 1 byte.
194 "movb (%1), %%cl\n\t"
195 "movb %%cl, (%2)\n\t"
198 : "=&c" (d0
), "=&S" (d1
), "=&D" (d2
),
199 "=r" (d3
),"=r" (d4
), "=r"(d5
)
208 EXPORT_SYMBOL(memmove
);