Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/string.h> |
| 2 | #include <linux/module.h> |
| 3 | |
| 4 | #undef memcpy |
| 5 | #undef memset |
| 6 | |
| 7 | void *memcpy(void *to, const void *from, size_t n) |
| 8 | { |
| 9 | #ifdef CONFIG_X86_USE_3DNOW |
| 10 | return __memcpy3d(to, from, n); |
| 11 | #else |
| 12 | return __memcpy(to, from, n); |
| 13 | #endif |
| 14 | } |
| 15 | EXPORT_SYMBOL(memcpy); |
| 16 | |
| 17 | void *memset(void *s, int c, size_t count) |
| 18 | { |
| 19 | return __memset(s, c, count); |
| 20 | } |
| 21 | EXPORT_SYMBOL(memset); |
| 22 | |
| 23 | void *memmove(void *dest, const void *src, size_t n) |
| 24 | { |
| 25 | int d0, d1, d2; |
| 26 | |
| 27 | if (dest < src) { |
Ma, Ling | fdf4289 | 2010-08-23 14:11:12 -0700 | [diff] [blame^] | 28 | if ((dest + n) < src) |
| 29 | return memcpy(dest, src, n); |
| 30 | else |
| 31 | __asm__ __volatile__( |
| 32 | "rep\n\t" |
| 33 | "movsb\n\t" |
| 34 | : "=&c" (d0), "=&S" (d1), "=&D" (d2) |
| 35 | :"0" (n), |
| 36 | "1" (src), |
| 37 | "2" (dest) |
| 38 | :"memory"); |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } else { |
Ma, Ling | fdf4289 | 2010-08-23 14:11:12 -0700 | [diff] [blame^] | 41 | |
| 42 | if((src + count) < dest) |
| 43 | return memcpy(dest, src, count); |
| 44 | else |
| 45 | __asm__ __volatile__( |
| 46 | "std\n\t" |
| 47 | "rep\n\t" |
| 48 | "movsb\n\t" |
| 49 | "cld" |
| 50 | : "=&c" (d0), "=&S" (d1), "=&D" (d2) |
| 51 | :"0" (n), |
| 52 | "1" (n-1+src), |
| 53 | "2" (n-1+dest) |
| 54 | :"memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
Ma, Ling | fdf4289 | 2010-08-23 14:11:12 -0700 | [diff] [blame^] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | return dest; |
| 58 | } |
| 59 | EXPORT_SYMBOL(memmove); |