1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/string.h>
3 #include <linux/export.h>
8 __visible
void *memcpy(void *to
, const void *from
, size_t n
)
10 #if defined(CONFIG_X86_USE_3DNOW) && !defined(CONFIG_FORTIFY_SOURCE)
11 return __memcpy3d(to
, from
, n
);
13 return __memcpy(to
, from
, n
);
16 EXPORT_SYMBOL(memcpy
);
18 __visible
void *memset(void *s
, int c
, size_t count
)
20 return __memset(s
, c
, count
);
22 EXPORT_SYMBOL(memset
);
24 __visible
void *memmove(void *dest
, const void *src
, size_t n
)
26 int d0
,d1
,d2
,d3
,d4
,d5
;
30 /* Handle more 16 bytes in loop */
34 /* Decide forward/backward copy mode */
39 * movs instruction have many startup latency
40 * so we handle small size by general register.
45 * movs instruction is only good for aligned case.
55 * We gobble 16 bytes forward in each loop.
67 "lea 0x10(%1), %1\n\t"
68 "lea 0x10(%2), %2\n\t"
74 * Handle data forward by movs.
78 "mov -4(%1, %0), %3\n\t"
79 "lea -4(%2, %0), %4\n\t"
85 * Handle data backward by movs.
91 "lea -4(%1, %0), %1\n\t"
92 "lea -4(%2, %0), %2\n\t"
101 * Start to prepare for backward copy.
113 * Calculate copy position to tail.
121 * We gobble 16 bytes backward in each loop.
126 "mov -1*4(%1), %3\n\t"
127 "mov -2*4(%1), %4\n\t"
128 "mov %3, -1*4(%2)\n\t"
129 "mov %4, -2*4(%2)\n\t"
130 "mov -3*4(%1), %3\n\t"
131 "mov -4*4(%1), %4\n\t"
132 "mov %3, -3*4(%2)\n\t"
133 "mov %4, -4*4(%2)\n\t"
134 "lea -0x10(%1), %1\n\t"
135 "lea -0x10(%2), %2\n\t"
138 * Calculate copy position to head.
145 * Move data from 8 bytes to 15 bytes.
151 "mov 0*4(%1), %3\n\t"
152 "mov 1*4(%1), %4\n\t"
153 "mov -2*4(%1, %0), %5\n\t"
154 "mov -1*4(%1, %0), %1\n\t"
156 "mov %3, 0*4(%2)\n\t"
157 "mov %4, 1*4(%2)\n\t"
158 "mov %5, -2*4(%2, %0)\n\t"
159 "mov %1, -1*4(%2, %0)\n\t"
163 * Move data from 4 bytes to 7 bytes.
169 "mov 0*4(%1), %3\n\t"
170 "mov -1*4(%1, %0), %4\n\t"
171 "mov %3, 0*4(%2)\n\t"
172 "mov %4, -1*4(%2, %0)\n\t"
176 * Move data from 2 bytes to 3 bytes.
182 "movw 0*2(%1), %%dx\n\t"
183 "movw -1*2(%1, %0), %%bx\n\t"
184 "movw %%dx, 0*2(%2)\n\t"
185 "movw %%bx, -1*2(%2, %0)\n\t"
189 * Move data for 1 byte.
195 "movb (%1), %%cl\n\t"
196 "movb %%cl, (%2)\n\t"
199 : "=&c" (d0
), "=&S" (d1
), "=&D" (d2
),
200 "=r" (d3
),"=r" (d4
), "=r"(d5
)
209 EXPORT_SYMBOL(memmove
);