1 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Hartvig Ekner <hartvige@mips.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
23 /* void *memcpy(void *s1, const void *s2, size_t n); */
29 #if __BYTE_ORDER == __BIG_ENDIAN
30 # define LDHI ldl /* high part is left in big-endian */
31 # define SDHI sdl /* high part is left in big-endian */
32 # define LDLO ldr /* low part is right in big-endian */
33 # define SDLO sdr /* low part is right in big-endian */
35 # define LDHI ldr /* high part is right in little-endian */
36 # define SDHI sdr /* high part is right in little-endian */
37 # define LDLO ldl /* low part is left in little-endian */
38 # define SDLO sdl /* low part is left in little-endian */
44 slti t0, a2, 16 # Less than 16?
45 bne t0, zero, L(last16)
46 move v0, a0 # Setup exit value before too late
48 xor t0, a1, a0 # Find a0/a1 displacement
50 bne t0, zero, L(shift) # Go handle the unaligned case
52 andi t1, 0x7 # a0/a1 are aligned, but are we
53 beq t1, zero, L(chk8w) # starting in the middle of a word?
55 LDHI t0, 0(a1) # Yes we are... take care of that
61 andi t0, a2, 0x3f # 64 or more bytes left?
63 PTR_SUBU a3, a2, t0 # Yes
64 PTR_ADDU a3, a1 # a3 = end address of loop
65 move a2, t0 # a2 = what will be left after loop
67 ld t0, 0(a1) # Loop taking 8 words at a time
88 andi t0, a2, 0x7 # 8 or more bytes left?
90 PTR_SUBU a3, a2, t0 # Yes, handle them one dword at a time
91 PTR_ADDU a3, a1 # a3 again end address
101 blez a2, L(lst16e) # Handle last 16 bytes, one at a time
107 bne a1, a3, L(lst16l)
114 PTR_SUBU a3, zero, a0 # Src and Dest unaligned
115 andi a3, 0x7 # (unoptimized case...)
116 beq a3, zero, L(shft1)
117 PTR_SUBU a2, a3 # a2 = bytes left
118 LDHI t0, 0(a1) # Take care of first odd part
128 LDHI t1, 0(a1) # Limp through, dword by dword
134 b L(last16) # Handle anything which may be left
140 #else /* !__mips64 */
142 #if __BYTE_ORDER == __BIG_ENDIAN
143 # define LWHI lwl /* high part is left in big-endian */
144 # define SWHI swl /* high part is left in big-endian */
145 # define LWLO lwr /* low part is right in big-endian */
146 # define SWLO swr /* low part is right in big-endian */
148 # define LWHI lwr /* high part is right in little-endian */
149 # define SWHI swr /* high part is right in little-endian */
150 # define LWLO lwl /* low part is left in little-endian */
151 # define SWLO swl /* low part is left in little-endian */
157 slti t0, a2, 8 # Less than 8?
158 bne t0, zero, L(last8)
159 move v0, a0 # Setup exit value before too late
161 xor t0, a1, a0 # Find a0/a1 displacement
163 bne t0, zero, L(shift) # Go handle the unaligned case
165 andi t1, 0x3 # a0/a1 are aligned, but are we
166 beq t1, zero, L(chk8w) # starting in the middle of a word?
168 LWHI t0, 0(a1) # Yes we are... take care of that
174 andi t0, a2, 0x1f # 32 or more bytes left?
176 subu a3, a2, t0 # Yes
177 addu a3, a1 # a3 = end address of loop
178 move a2, t0 # a2 = what will be left after loop
180 lw t0, 0(a1) # Loop taking 8 words at a time
201 andi t0, a2, 0x3 # 4 or more bytes left?
203 subu a3, a2, t0 # Yes, handle them one word at a time
204 addu a3, a1 # a3 again end address
214 blez a2, L(lst8e) # Handle last 8 bytes, one at a time
227 subu a3, zero, a0 # Src and Dest unaligned
228 andi a3, 0x3 # (unoptimized case...)
229 beq a3, zero, L(shft1)
230 subu a2, a3 # a2 = bytes left
231 LWHI t0, 0(a1) # Take care of first odd part
241 LWHI t1, 0(a1) # Limp through, word by word
247 b L(last8) # Handle anything which may be left
253 #endif /* !__mips64 */
255 libc_hidden_def(memcpy)