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? */
92 movq -16(%rsi,%rcx),%r9
93 movq -8(%rsi,%rcx),%r10
96 movq %r9,-16(%rdi,%rcx)
97 movq %r10,-8(%rdi,%rcx)
105 movq -8(%rsi,%rcx),%r8
107 movq %r8,-8(%rdi,%rcx,)
115 movl -4(%rsi,%rcx),%r8d
117 movl %r8d,-4(%rdi,%rcx)
125 movzwl -2(%rsi,%rcx),%r8d
127 movw %r8w,-2(%rdi,%rcx)
148 shrq $3,%rcx /* copy by 64-bit words */
152 andl $7,%ecx /* any bytes left? */
163 leaq -16(%rdx,%rcx),%rdx
165 leaq 16(%rdi,%rcx),%rdi
166 leaq 16(%rsi,%rcx),%rsi
174 shrq $3,%rcx /* copy by 64-bit words */
180 andl $7,%ecx /* any bytes left? */
195 leaq -8(%rdi,%rcx),%rdi
196 leaq -8(%rsi,%rcx),%rsi
270 leaq -1(%rdi,%rcx),%rdi
271 leaq -1(%rsi,%rcx),%rsi
276 leaq -8(%rdi,%rcx),%rdi
277 leaq -8(%rsi,%rcx),%rsi
302 MEMMOVE erms=0 overlap=1 begin=MEMMOVE_BEGIN end=MEMMOVE_END
306 MEMMOVE erms=0 overlap=1 begin=MEMMOVE_BEGIN end=MEMMOVE_END