blob: 6c098aca157441c3356e772afbe7613db6213ef7 [file] [log] [blame]
Christopher Ferris5f45d582013-08-07 13:09:51 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
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
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29
30/*
31 * This code assumes it is running on a processor that supports all arm v7
32 * instructions, that supports neon instructions, and that has a 32 byte
33 * cache line.
34 */
35
36// Assumes neon instructions and a cache line size of 32 bytes.
37
Nick Kralevich32bbf8a2013-10-02 16:54:58 -070038ENTRY_PRIVATE(MEMCPY_BASE)
Christopher Ferrisa57c9c02013-08-21 09:41:12 -070039 .cfi_def_cfa_offset 8
40 .cfi_rel_offset r0, 0
41 .cfi_rel_offset lr, 4
42
Christopher Ferris5f45d582013-08-07 13:09:51 -070043 /* do we have at least 16-bytes to copy (needed for alignment below) */
44 cmp r2, #16
45 blo 5f
46
47 /* align destination to cache-line for the write-buffer */
48 rsb r3, r0, #0
49 ands r3, r3, #0xF
50 beq 2f
51
52 /* copy up to 15-bytes (count in r3) */
53 sub r2, r2, r3
54 movs ip, r3, lsl #31
55 itt mi
56 ldrbmi lr, [r1], #1
57 strbmi lr, [r0], #1
58 itttt cs
59 ldrbcs ip, [r1], #1
60 ldrbcs lr, [r1], #1
61 strbcs ip, [r0], #1
62 strbcs lr, [r0], #1
63 movs ip, r3, lsl #29
64 bge 1f
65 // copies 4 bytes, destination 32-bits aligned
66 vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
67 vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
681: bcc 2f
69 // copies 8 bytes, destination 64-bits aligned
70 vld1.8 {d0}, [r1]!
71 vst1.8 {d0}, [r0, :64]!
72
732: /* make sure we have at least 64 bytes to copy */
74 subs r2, r2, #64
75 blo 2f
76
771: /* The main loop copies 64 bytes at a time */
78 vld1.8 {d0 - d3}, [r1]!
79 vld1.8 {d4 - d7}, [r1]!
Christopher Ferrisc3c58fb2013-10-15 12:10:06 -070080 pld [r1, #(32*8)]
Christopher Ferris5f45d582013-08-07 13:09:51 -070081 subs r2, r2, #64
82 vst1.8 {d0 - d3}, [r0, :128]!
83 vst1.8 {d4 - d7}, [r0, :128]!
84 bhs 1b
85
862: /* fix-up the remaining count and make sure we have >= 32 bytes left */
87 adds r2, r2, #32
88 blo 4f
89
90 /* Copy 32 bytes. These cache lines were already preloaded */
91 vld1.8 {d0 - d3}, [r1]!
92 sub r2, r2, #32
93 vst1.8 {d0 - d3}, [r0, :128]!
94
954: /* less than 32 left */
96 add r2, r2, #32
97 tst r2, #0x10
98 beq 5f
99 // copies 16 bytes, 128-bits aligned
100 vld1.8 {d0, d1}, [r1]!
101 vst1.8 {d0, d1}, [r0, :128]!
102
1035: /* copy up to 15-bytes (count in r2) */
104 movs ip, r2, lsl #29
105 bcc 1f
106 vld1.8 {d0}, [r1]!
107 vst1.8 {d0}, [r0]!
1081: bge 2f
109 vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
110 vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0]!
1112: movs ip, r2, lsl #31
112 itt mi
113 ldrbmi r3, [r1], #1
114 strbmi r3, [r0], #1
115 itttt cs
116 ldrbcs ip, [r1], #1
117 ldrbcs lr, [r1], #1
118 strbcs ip, [r0], #1
119 strbcs lr, [r0], #1
120
Christopher Ferrise1e434a2015-07-06 12:03:40 -0700121 ldmfd sp!, {r0, pc}
Christopher Ferrisa57c9c02013-08-21 09:41:12 -0700122END(MEMCPY_BASE)