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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 /* void *memcpy(void *s1, const void *s2, size_t n);
26 This routine could be optimized further for MIPS64, but this is left
27 as an exercise for the future. When it is done, the file should be kept
28 as a sisterfile to this one, and placed in the sysdeps/mips/mips64
31 #if __BYTE_ORDER == __BIG_ENDIAN
32 # define LWHI lwl /* high part is left in big-endian */
33 # define SWHI swl /* high part is left in big-endian */
34 # define LWLO lwr /* low part is right in big-endian */
35 # define SWLO swr /* low part is right in big-endian */
37 # define LWHI lwr /* high part is right in little-endian */
38 # define SWHI swr /* high part is right in little-endian */
39 # define LWLO lwl /* low part is left in little-endian */
40 # define SWLO swl /* low part is left in little-endian */
59 slti t0, a2, 8 # Less than 8?
60 bne t0, zero, L(last8)
61 move v0, a0 # Setup exit value before too late
63 xor t0, a1, a0 # Find a0/a1 displacement
65 bne t0, zero, L(shift) # Go handle the unaligned case
67 andi t1, 0x3 # a0/a1 are aligned, but are we
68 beq t1, zero, L(chk8w) # starting in the middle of a word?
70 LWHI t0, 0(a1) # Yes we are... take care of that
75 L(chk8w): andi t0, a2, 0x1f # 32 or more bytes left?
78 addu a3, a1 # a3 = end address of loop
79 move a2, t0 # a2 = what will be left after loop
80 L(lop8w): lw t0, 0(a1) # Loop taking 8 words at a time
100 L(chk1w): andi t0, a2, 0x3 # 4 or more bytes left?
102 subu a3, a2, t0 # Yes, handle them one word at a time
103 addu a3, a1 # a3 again end address
105 L(lop1w): lw t0, 0(a1)
111 L(last8): blez a2, L(lst8e) # Handle last 8 bytes, one at a time
113 L(lst8l): lb t0, 0(a1)
118 L(lst8e): jr ra # Bye, bye
121 L(shift): subu a3, zero, a0 # Src and Dest unaligned
122 andi a3, 0x3 # (unoptimized case...)
123 beq a3, zero, L(shft1)
124 subu a2, a3 # a2 = bytes left
125 LWHI t0, 0(a1) # Take care of first odd part
130 L(shft1): andi t0, a2, 0x3
133 L(shfth): LWHI t1, 0(a1) # Limp through, word by word
139 b L(last8) # Handle anything which may be left