1 /* Copyright 2002 Andi Kleen */
3 #include <linux/linkage.h>
4 #include <asm/cpufeature.h>
5 #include <asm/dwarf2.h>
6 #include <asm/alternative-asm.h>
9 * We build a jump to memcpy_orig by default which gets NOPped out on
10 * the majority of x86 CPUs which set REP_GOOD. In addition, CPUs which
11 * have the enhanced REP MOVSB/STOSB feature (ERMS), change those NOPs
12 * to a jmp to memcpy_erms which does the REP; MOVSB mem copy.
18 * memcpy - Copy a memory block.
26 * rax original destination
30 ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
31 "jmp memcpy_erms", X86_FEATURE_ERMS
45 * memcpy_erms() - enhanced fast string memcpy. This is faster and
46 * simpler than memcpy. Use memcpy_erms when possible.
63 * We check whether memory false dependence could occur,
64 * then jump to corresponding copy mode.
73 * Move in blocks of 4x8 bytes:
86 jae .Lcopy_forward_loop
92 * Calculate copy position to tail.
98 * At most 3 ALU operations in one cycle,
99 * so append NOPS in the same 16 bytes trunk.
102 .Lcopy_backward_loop:
106 movq -3*8(%rsi), %r10
107 movq -4*8(%rsi), %r11
108 leaq -4*8(%rsi), %rsi
111 movq %r10, -3*8(%rdi)
112 movq %r11, -4*8(%rdi)
113 leaq -4*8(%rdi), %rdi
114 jae .Lcopy_backward_loop
117 * Calculate copy position to head.
127 * Move data from 16 bytes to 31 bytes.
131 movq -2*8(%rsi, %rdx), %r10
132 movq -1*8(%rsi, %rdx), %r11
135 movq %r10, -2*8(%rdi, %rdx)
136 movq %r11, -1*8(%rdi, %rdx)
143 * Move data from 8 bytes to 15 bytes.
146 movq -1*8(%rsi, %rdx), %r9
148 movq %r9, -1*8(%rdi, %rdx)
156 * Move data from 4 bytes to 7 bytes.
159 movl -4(%rsi, %rdx), %r8d
161 movl %r8d, -4(%rdi, %rdx)
168 * Move data from 1 bytes to 3 bytes.
173 movzbq (%rsi, %rdx), %r9
175 movb %r9b, (%rdi, %rdx)