1 /* Copyright (C) 2002-2012 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Hartvig Ekner <hartvige@mips.com>, 2002.
4 Ported to mips3 n32/n64 by Alexandre Oliva <aoliva@redhat.com>
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
24 /* void *memcpy(void *s1, const void *s2, size_t n);
26 This could probably be optimized further. */
29 # define LDHI ldl /* high part is left in big-endian */
30 # define SDHI sdl /* high part is left in big-endian */
31 # define LDLO ldr /* low part is right in big-endian */
32 # define SDLO sdr /* low part is right in big-endian */
34 # define LDHI ldr /* high part is right in little-endian */
35 # define SDHI sdr /* high part is right in little-endian */
36 # define LDLO ldl /* low part is left in little-endian */
37 # define SDLO sdl /* low part is left in little-endian */
43 slti t0, a2, 16 # Less than 16?
44 bne t0, zero, L(last16)
45 move v0, a0 # Setup exit value before too late
47 xor t0, a1, a0 # Find a0/a1 displacement
49 bne t0, zero, L(shift) # Go handle the unaligned case
51 andi t1, 0x7 # a0/a1 are aligned, but are we
52 beq t1, zero, L(chk8w) # starting in the middle of a word?
54 LDHI t0, 0(a1) # Yes we are... take care of that
60 andi t0, a2, 0x3f # 64 or more bytes left?
62 PTR_SUBU a3, a2, t0 # Yes
63 PTR_ADDU a3, a1 # a3 = end address of loop
64 move a2, t0 # a2 = what will be left after loop
66 ld t0, 0(a1) # Loop taking 8 words at a time
87 andi t0, a2, 0x7 # 8 or more bytes left?
89 PTR_SUBU a3, a2, t0 # Yes, handle them one dword at a time
90 PTR_ADDU a3, a1 # a3 again end address
100 blez a2, L(lst16e) # Handle last 16 bytes, one at a time
106 bne a1, a3, L(lst16l)
113 PTR_SUBU a3, zero, a0 # Src and Dest unaligned
114 andi a3, 0x7 # (unoptimized case...)
115 beq a3, zero, L(shft1)
116 PTR_SUBU a2, a3 # a2 = bytes left
117 LDHI t0, 0(a1) # Take care of first odd part
127 LDHI t1, 0(a1) # Limp through, dword by dword
133 b L(last16) # Handle anything which may be left
138 libc_hidden_builtin_def (memcpy)