1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include <string.h>
- #undef memmove
- void *memmove(void *dest, const void *src, size_t n)
- {
- int eax, ecx, esi, edi;
- __asm__ __volatile__(
- " movl %%eax, %%edi\n"
- " cmpl %%esi, %%eax\n"
- " je 2f\n"
- " jb 1f\n"
- " leal -1(%%esi,%%ecx), %%esi\n"
- " leal -1(%%eax,%%ecx), %%edi\n"
- " std\n"
- "1: rep; movsb\n"
- " cld\n"
- "2:\n"
- : "=&c" (ecx), "=&S" (esi), "=&a" (eax), "=&D" (edi)
- : "0" (n), "1" (src), "2" (dest)
- : "memory"
- );
- return (void*)eax;
- }
- #ifndef memmove
- libc_hidden_def(memmove)
- #else
- int main()
- {
- static char str[] = "abcdef.123";
- memmove(str + 1, str, 5);
- printf(strcmp(str, "aabcde.123") == 0 ? "ok\n" : "BAD!\n");
- memmove(str, str + 1, 5);
- printf(strcmp(str, "abcdee.123") == 0 ? "ok\n" : "BAD!\n");
- }
- #endif
|