1 /* $NetBSD: memcpy.S,v 1.1 2014/08/10 05:47:35 matt Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <machine/asm.h>
34 RCSID("$NetBSD: memcpy.S,v 1.1 2014/08/10 05:47:35 matt Exp $")
36 /* LINTSTUB: void *memcpy(void * restrict, const void * restrict, size_t); */
44 b.ls .Lmemcpy_last_dword
47 b.eq .Lmemcpy_dword_aligned
50 * The dst address doesn't have dword alignment. The src address may or may
51 * not have the same alignment. Make dst dword aligned. Hope src will be
52 * dword aligned but if it isn't, take advantage of unaligned access.
54 add x2, x2, x3 /* add unalignment to length */
55 sub x2, x2, #8 /* now subtract a dword */
57 tbz x10, #0, .Lmemcpy_hword_aligned
60 .Lmemcpy_hword_aligned:
61 tbz x10, #1, .Lmemcpy_word_aligned
64 .Lmemcpy_word_aligned:
65 tbz x10, #2, .Lmemcpy_dword_aligned
68 .Lmemcpy_dword_aligned:
70 * destination is now dword aligned.
73 b.mi .Lmemcpy_last_oword
76 ldp x4, x5, [x11], #16
77 ldp x6, x7, [x11], #16
78 stp x4, x5, [x10], #16
79 stp x6, x7, [x10], #16
82 b.pl .Lmemcpy_oword_loop
86 * We have 31 bytes or less to copy. First see if we can write a qword
88 tbz x2, #4, .Lmemcpy_last_qword
89 ldp x4, x5, [x11], #16 /* read word */
90 stp x4, x5, [x10], #16 /* write word */
94 * We have 15 bytes or less to copy. First see if we can write a dword
96 tbz x2, #3, .Lmemcpy_last_dword
97 ldr x4, [x11], #8 /* read word */
98 str x4, [x10], #8 /* write word */
102 * We have 7 bytes or less to copy. First see if we can write a word
104 tbz x2, #2, .Lmemcpy_last_word
105 ldr w4, [x11], #4 /* read word */
106 str w4, [x10], #4 /* write word */
110 * We have 3 bytes or less to copy. First see if we can write a hword
112 tbz x2, #1, .Lmemcpy_last_hword
118 * We have 1 or none bytes to copy.
120 tbz x2, #0, .Lmemcpy_ret