Move all files into ports/ subdirectory in preparation for merge with glibc
[glibc.git] / ports / sysdeps / mips / memcpy.S
blob753f67ca17c34efb730d527774e10e9df4f7cf42
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.
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/>.  */
19 #include <sysdep.h>
22 /* void *memcpy(void *s1, const void *s2, size_t n);  */
24 #if __MIPSEB
25 #  define LWHI  lwl             /* high part is left in big-endian      */
26 #  define SWHI  swl             /* high part is left in big-endian      */
27 #  define LWLO  lwr             /* low part is right in big-endian      */
28 #  define SWLO  swr             /* low part is right in big-endian      */
29 #else
30 #  define LWHI  lwr             /* high part is right in little-endian  */
31 #  define SWHI  swr             /* high part is right in little-endian  */
32 #  define LWLO  lwl             /* low part is left in little-endian    */
33 #  define SWLO  swl             /* low part is left in little-endian    */
34 #endif
36 ENTRY (memcpy)
37         .set    noreorder
39         slti    t0, a2, 8               # Less than 8?
40         bne     t0, zero, L(last8)
41         move    v0, a0                  # Setup exit value before too late
43         xor     t0, a1, a0              # Find a0/a1 displacement
44         andi    t0, 0x3
45         bne     t0, zero, L(shift)      # Go handle the unaligned case
46         subu    t1, zero, a1
47         andi    t1, 0x3                 # a0/a1 are aligned, but are we
48         beq     t1, zero, L(chk8w)      #  starting in the middle of a word?
49         subu    a2, t1
50         LWHI    t0, 0(a1)               # Yes we are... take care of that
51         addu    a1, t1
52         SWHI    t0, 0(a0)
53         addu    a0, t1
55 L(chk8w):       
56         andi    t0, a2, 0x1f            # 32 or more bytes left?
57         beq     t0, a2, L(chk1w)
58         subu    a3, a2, t0              # Yes
59         addu    a3, a1                  # a3 = end address of loop
60         move    a2, t0                  # a2 = what will be left after loop
61 L(lop8w):       
62         lw      t0,  0(a1)              # Loop taking 8 words at a time
63         lw      t1,  4(a1)
64         lw      t2,  8(a1)
65         lw      t3, 12(a1)
66         lw      t4, 16(a1)
67         lw      t5, 20(a1)
68         lw      t6, 24(a1)
69         lw      t7, 28(a1)
70         addiu   a0, 32
71         addiu   a1, 32
72         sw      t0, -32(a0)
73         sw      t1, -28(a0)
74         sw      t2, -24(a0)
75         sw      t3, -20(a0)
76         sw      t4, -16(a0)
77         sw      t5, -12(a0)
78         sw      t6,  -8(a0)
79         bne     a1, a3, L(lop8w)
80         sw      t7,  -4(a0)
82 L(chk1w):       
83         andi    t0, a2, 0x3             # 4 or more bytes left?
84         beq     t0, a2, L(last8)
85         subu    a3, a2, t0              # Yes, handle them one word at a time
86         addu    a3, a1                  # a3 again end address
87         move    a2, t0
88 L(lop1w):       
89         lw      t0, 0(a1)
90         addiu   a0, 4
91         addiu   a1, 4
92         bne     a1, a3, L(lop1w)
93         sw      t0, -4(a0)
95 L(last8):       
96         blez    a2, L(lst8e)            # Handle last 8 bytes, one at a time
97         addu    a3, a2, a1
98 L(lst8l):       
99         lb      t0, 0(a1)
100         addiu   a0, 1
101         addiu   a1, 1
102         bne     a1, a3, L(lst8l)
103         sb      t0, -1(a0)
104 L(lst8e):       
105         jr      ra                      # Bye, bye
106         nop
108 L(shift):       
109         subu    a3, zero, a0            # Src and Dest unaligned 
110         andi    a3, 0x3                 #  (unoptimized case...)
111         beq     a3, zero, L(shft1)
112         subu    a2, a3                  # a2 = bytes left
113         LWHI    t0, 0(a1)               # Take care of first odd part
114         LWLO    t0, 3(a1)
115         addu    a1, a3
116         SWHI    t0, 0(a0)
117         addu    a0, a3
118 L(shft1):       
119         andi    t0, a2, 0x3
120         subu    a3, a2, t0
121         addu    a3, a1
122 L(shfth):       
123         LWHI    t1, 0(a1)               # Limp through, word by word
124         LWLO    t1, 3(a1)
125         addiu   a0, 4
126         addiu   a1, 4
127         bne     a1, a3, L(shfth)
128         sw      t1, -4(a0)
129         b       L(last8)                # Handle anything which may be left
130         move    a2, t0
132         .set    reorder
133 END (memcpy)
134 libc_hidden_builtin_def (memcpy)