2 * Normally compiler builtins are used, but sometimes the compiler calls out
3 * of line code. Based on asm-i386/string.h.
5 * This assembly file is re-written from memmove_64.c file.
6 * - Copyright 2011 Fenghua Yu <fenghua.yu@intel.com>
9 #include <linux/linkage.h>
10 #include <asm/dwarf2.h>
11 #include <asm/cpufeature.h>
12 #include <asm/alternative-asm.h>
17 * Implement memmove(). This can handle overlap between src and dst.
30 /* Handle more 32 bytes in loop */
35 /* Decide forward/backward copy mode */
37 jge .Lmemmove_begin_forward
43 .Lmemmove_begin_forward:
45 * movsq instruction have many startup latency
46 * so we handle small size by general register.
51 * movsq instruction is only good for aligned case.
59 * We gobble 32 bytes forward in each loop.
78 * Handle data forward by movsq.
83 movq -8(%rsi, %rdx), %r11
84 lea -8(%rdi, %rdx), %r10
89 .Lmemmove_end_forward:
92 * Handle data backward by movsq.
99 leaq -8(%rsi, %rdx), %rsi
100 leaq -8(%rdi, %rdx), %rdi
109 * Start to prepare for backward copy.
119 * Calculate copy position to tail.
125 * We gobble 32 bytes backward in each loop.
129 movq -1*8(%rsi), %r11
130 movq -2*8(%rsi), %r10
133 leaq -4*8(%rsi), %rsi
135 movq %r11, -1*8(%rdi)
136 movq %r10, -2*8(%rdi)
139 leaq -4*8(%rdi), %rdi
142 * Calculate copy position to head.
151 * Move data from 16 bytes to 31 bytes.
155 movq -2*8(%rsi, %rdx), %r9
156 movq -1*8(%rsi, %rdx), %r8
159 movq %r9, -2*8(%rdi, %rdx)
160 movq %r8, -1*8(%rdi, %rdx)
167 * Move data from 8 bytes to 15 bytes.
170 movq -1*8(%rsi, %rdx), %r10
172 movq %r10, -1*8(%rdi, %rdx)
178 * Move data from 4 bytes to 7 bytes.
181 movl -4(%rsi, %rdx), %r10d
183 movl %r10d, -4(%rdi, %rdx)
189 * Move data from 2 bytes to 3 bytes.
192 movw -2(%rsi, %rdx), %r10w
194 movw %r10w, -2(%rdi, %rdx)
200 * Move data for 1 byte.
208 .section .altinstr_replacement,"ax"
209 .Lmemmove_begin_forward_efs:
210 /* Forward moving data. */
214 .Lmemmove_end_forward_efs:
217 .section .altinstructions,"a"
218 altinstruction_entry .Lmemmove_begin_forward, \
219 .Lmemmove_begin_forward_efs,X86_FEATURE_ERMS, \
220 .Lmemmove_end_forward-.Lmemmove_begin_forward, \
221 .Lmemmove_end_forward_efs-.Lmemmove_begin_forward_efs