1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Normally compiler builtins are used, but sometimes the compiler calls out
4 * of line code. Based on asm-i386/string.h.
6 * This assembly file is re-written from memmove_64.c file.
7 * - Copyright 2011 Fenghua Yu <fenghua.yu@intel.com>
9 #include <linux/linkage.h>
10 #include <asm/cpufeatures.h>
11 #include <asm/alternative-asm.h>
12 #include <asm/export.h>
17 * Implement memmove(). This can handle overlap between src and dst.
29 SYM_FUNC_START_ALIAS(memmove)
30 SYM_FUNC_START(__memmove)
34 /* Decide forward/backward copy mode */
36 jge .Lmemmove_begin_forward
42 /* FSRM implies ERMS => no length checks, do the copy directly */
43 .Lmemmove_begin_forward:
44 ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM
45 ALTERNATIVE "", "movq %rdx, %rcx; rep movsb; retq", X86_FEATURE_ERMS
48 * movsq instruction have many startup latency
49 * so we handle small size by general register.
54 * movsq instruction is only good for aligned case.
62 * We gobble 32 bytes forward in each loop.
81 * Handle data forward by movsq.
86 movq -8(%rsi, %rdx), %r11
87 lea -8(%rdi, %rdx), %r10
92 .Lmemmove_end_forward:
95 * Handle data backward by movsq.
102 leaq -8(%rsi, %rdx), %rsi
103 leaq -8(%rdi, %rdx), %rdi
112 * Start to prepare for backward copy.
124 * Calculate copy position to tail.
130 * We gobble 32 bytes backward in each loop.
134 movq -1*8(%rsi), %r11
135 movq -2*8(%rsi), %r10
138 leaq -4*8(%rsi), %rsi
140 movq %r11, -1*8(%rdi)
141 movq %r10, -2*8(%rdi)
144 leaq -4*8(%rdi), %rdi
147 * Calculate copy position to head.
156 * Move data from 16 bytes to 31 bytes.
160 movq -2*8(%rsi, %rdx), %r9
161 movq -1*8(%rsi, %rdx), %r8
164 movq %r9, -2*8(%rdi, %rdx)
165 movq %r8, -1*8(%rdi, %rdx)
172 * Move data from 8 bytes to 15 bytes.
175 movq -1*8(%rsi, %rdx), %r10
177 movq %r10, -1*8(%rdi, %rdx)
183 * Move data from 4 bytes to 7 bytes.
186 movl -4(%rsi, %rdx), %r10d
188 movl %r10d, -4(%rdi, %rdx)
194 * Move data from 2 bytes to 3 bytes.
197 movw -2(%rsi, %rdx), %r10w
199 movw %r10w, -2(%rdi, %rdx)
205 * Move data for 1 byte.
211 SYM_FUNC_END(__memmove)
212 SYM_FUNC_END_ALIAS(memmove)
213 EXPORT_SYMBOL(__memmove)
214 EXPORT_SYMBOL(memmove)