]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/memmove.S
sys/{x86,amd64}: remove one of doubled ;s
[FreeBSD/FreeBSD.git] / sys / arm64 / arm64 / memmove.S
1 /* Copyright (c) 2013, Linaro Limited
2    All rights reserved.
3
4    Redistribution and use in source and binary forms, with or without
5    modification, are permitted provided that the following conditions are met:
6        * Redistributions of source code must retain the above copyright
7          notice, this list of conditions and the following disclaimer.
8        * Redistributions in binary form must reproduce the above copyright
9          notice, this list of conditions and the following disclaimer in the
10          documentation and/or other materials provided with the distribution.
11        * Neither the name of the Linaro nor the
12          names of its contributors may be used to endorse or promote products
13          derived from this software without specific prior written permission.
14
15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26
27 /*
28  * Copyright (c) 2015 ARM Ltd
29  * All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  * 1. Redistributions of source code must retain the above copyright
35  *    notice, this list of conditions and the following disclaimer.
36  * 2. Redistributions in binary form must reproduce the above copyright
37  *    notice, this list of conditions and the following disclaimer in the
38  *    documentation and/or other materials provided with the distribution.
39  * 3. The name of the company may not be used to endorse or promote
40  *    products derived from this software without specific prior written
41  *    permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
44  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46  * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
48  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
50  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
51  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
52  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54
55 #include <machine/asm.h>
56 __FBSDID("$FreeBSD$");
57
58 /* Assumptions:
59  *
60  * ARMv8-a, AArch64, unaligned accesses
61  */
62
63 /* Parameters and result.  */
64 #define dstin   x0
65 #define src     x1
66 #define count   x2
67 #define srcend  x3
68 #define dstend  x4
69 #define tmp1    x5
70 #define A_l     x6
71 #define A_h     x7
72 #define B_l     x8
73 #define B_h     x9
74 #define C_l     x10
75 #define C_h     x11
76 #define D_l     x12
77 #define D_h     x13
78 #define E_l     count
79 #define E_h     tmp1
80
81 /* All memmoves up to 96 bytes are done by memcpy as it supports overlaps.
82    Larger backwards copies are also handled by memcpy. The only remaining
83    case is forward large copies.  The destination is aligned, and an
84    unrolled loop processes 64 bytes per iteration.
85 */
86
87 ENTRY(bcopy)
88         /* Switch the input pointers when called as bcopy */
89         mov     x3, x1
90         mov     x1, x0
91         mov     x0, x3
92 EENTRY(memmove)
93         sub     tmp1, dstin, src
94         cmp     count, 96
95         ccmp    tmp1, count, 2, hi
96         b.hs    memcpy
97
98         cbz     tmp1, 3f
99         add     dstend, dstin, count
100         add     srcend, src, count
101
102         /* Align dstend to 16 byte alignment so that we don't cross cache line
103            boundaries on both loads and stores.  There are at least 96 bytes
104            to copy, so copy 16 bytes unaligned and then align.  The loop
105            copies 64 bytes per iteration and prefetches one iteration ahead.  */
106
107         and     tmp1, dstend, 15
108         ldp     D_l, D_h, [srcend, -16]
109         sub     srcend, srcend, tmp1
110         sub     count, count, tmp1
111         ldp     A_l, A_h, [srcend, -16]
112         stp     D_l, D_h, [dstend, -16]
113         ldp     B_l, B_h, [srcend, -32]
114         ldp     C_l, C_h, [srcend, -48]
115         ldp     D_l, D_h, [srcend, -64]!
116         sub     dstend, dstend, tmp1
117         subs    count, count, 128
118         b.ls    2f
119         nop
120 1:
121         stp     A_l, A_h, [dstend, -16]
122         ldp     A_l, A_h, [srcend, -16]
123         stp     B_l, B_h, [dstend, -32]
124         ldp     B_l, B_h, [srcend, -32]
125         stp     C_l, C_h, [dstend, -48]
126         ldp     C_l, C_h, [srcend, -48]
127         stp     D_l, D_h, [dstend, -64]!
128         ldp     D_l, D_h, [srcend, -64]!
129         subs    count, count, 64
130         b.hi    1b
131
132         /* Write the last full set of 64 bytes.  The remainder is at most 64
133            bytes, so it is safe to always copy 64 bytes from the start even if
134            there is just 1 byte left.  */
135 2:
136         ldp     E_l, E_h, [src, 48]
137         stp     A_l, A_h, [dstend, -16]
138         ldp     A_l, A_h, [src, 32]
139         stp     B_l, B_h, [dstend, -32]
140         ldp     B_l, B_h, [src, 16]
141         stp     C_l, C_h, [dstend, -48]
142         ldp     C_l, C_h, [src]
143         stp     D_l, D_h, [dstend, -64]
144         stp     E_l, E_h, [dstin, 48]
145         stp     A_l, A_h, [dstin, 32]
146         stp     B_l, B_h, [dstin, 16]
147         stp     C_l, C_h, [dstin]
148 3:      ret
149 EEND(memmove)
150 END(bcopy)