1 /* Copyright 2002 Andi Kleen */
3 #include <linux/linkage.h>
4 #include <asm/cpufeature.h>
5 #include <asm/alternative-asm.h>
8 * We build a jump to memcpy_orig by default which gets NOPped out on
9 * the majority of x86 CPUs which set REP_GOOD. In addition, CPUs which
10 * have the enhanced REP MOVSB/STOSB feature (ERMS), change those NOPs
11 * to a jmp to memcpy_erms which does the REP; MOVSB mem copy.
17 * memcpy - Copy a memory block.
25 * rax original destination
29 ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
30 "jmp memcpy_erms", X86_FEATURE_ERMS
44 * memcpy_erms() - enhanced fast string memcpy. This is faster and
45 * simpler than memcpy. Use memcpy_erms when possible.
61 * We check whether memory false dependence could occur,
62 * then jump to corresponding copy mode.
71 * Move in blocks of 4x8 bytes:
84 jae .Lcopy_forward_loop
90 * Calculate copy position to tail.
96 * At most 3 ALU operations in one cycle,
97 * so append NOPS in the same 16 bytes trunk.
100 .Lcopy_backward_loop:
104 movq -3*8(%rsi), %r10
105 movq -4*8(%rsi), %r11
106 leaq -4*8(%rsi), %rsi
109 movq %r10, -3*8(%rdi)
110 movq %r11, -4*8(%rdi)
111 leaq -4*8(%rdi), %rdi
112 jae .Lcopy_backward_loop
115 * Calculate copy position to head.
125 * Move data from 16 bytes to 31 bytes.
129 movq -2*8(%rsi, %rdx), %r10
130 movq -1*8(%rsi, %rdx), %r11
133 movq %r10, -2*8(%rdi, %rdx)
134 movq %r11, -1*8(%rdi, %rdx)
141 * Move data from 8 bytes to 15 bytes.
144 movq -1*8(%rsi, %rdx), %r9
146 movq %r9, -1*8(%rdi, %rdx)
154 * Move data from 4 bytes to 7 bytes.
157 movl -4(%rsi, %rdx), %r8d
159 movl %r8d, -4(%rdi, %rdx)
166 * Move data from 1 bytes to 3 bytes.
171 movzbq (%rsi, %rdx), %r9
173 movb %r9b, (%rdi, %rdx)