2 * Copyright (c) 2018 The FreeBSD Foundation
4 * This software was developed by Mateusz Guzik <mjg@FreeBSD.org>
5 * under sponsorship from the FreeBSD Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <machine/asm.h>
30 __FBSDID("$FreeBSD$");
32 #define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */
35 * memmove(dst, src, cnt)
40 * Register state at entry is supposed to be as follows:
45 * The macro possibly clobbers the above and: rcx, r8, r9, 10
46 * It does not clobber rax nor r11.
48 .macro MEMMOVE erms overlap begin end
52 * For sizes 0..32 all data is read before it is written, so there
53 * is no correctness issue with direction of copying.
61 cmpq %rcx,%r8 /* overlapping && src < dst? */
93 movq -16(%rsi,%rcx),%r9
94 movq -8(%rsi,%rcx),%r10
97 movq %r9,-16(%rdi,%rcx)
98 movq %r10,-8(%rdi,%rcx)
106 movq -8(%rsi,%rcx),%r8
108 movq %r8,-8(%rdi,%rcx,)
116 movl -4(%rsi,%rcx),%r8d
118 movl %r8d,-4(%rdi,%rcx)
126 movzwl -2(%rsi,%rcx),%r8d
128 movw %r8w,-2(%rdi,%rcx)
149 shrq $3,%rcx /* copy by 64-bit words */
153 andl $7,%ecx /* any bytes left? */
164 leaq -16(%rdx,%rcx),%rdx
166 leaq 16(%rdi,%rcx),%rdi
167 leaq 16(%rsi,%rcx),%rsi
175 shrq $3,%rcx /* copy by 64-bit words */
181 andl $7,%ecx /* any bytes left? */
196 leaq -8(%rdi,%rcx),%rdi
197 leaq -8(%rsi,%rcx),%rsi
272 leaq -1(%rdi,%rcx),%rdi
273 leaq -1(%rsi,%rcx),%rsi
278 leaq -8(%rdi,%rcx),%rdi
279 leaq -8(%rsi,%rcx),%rsi
304 MEMMOVE erms=0 overlap=1 begin=MEMMOVE_BEGIN end=MEMMOVE_END
308 MEMMOVE erms=0 overlap=1 begin=MEMMOVE_BEGIN end=MEMMOVE_END