blob: 24577bebdc4043a3ea54bd3d41b722b605fed585 [file] [log] [blame]
Aubrey.Li9da597f2007-03-09 13:38:44 +08001/*
Aubrey Li314d22f2007-04-05 18:31:18 +08002 * File: memcpy.S
Aubrey.Li9da597f2007-03-09 13:38:44 +08003 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright 2004-2007 Analog Devices Inc.
5 * Enter bugs at http://blackfin.uclinux.org/
Aubrey.Li9da597f2007-03-09 13:38:44 +08006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see the file COPYING, or write
19 * to the Free Software Foundation, Inc.,
20 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
Aubrey Li314d22f2007-04-05 18:31:18 +080022
Aubrey.Li9da597f2007-03-09 13:38:44 +080023.align 2
24
25.globl _memcpy_ASM;
26_memcpy_ASM:
27 CC = R2 <= 0; /* length not positive?*/
28 IF CC JUMP .L_P1L2147483647; /* Nothing to do */
29
30 P0 = R0 ; /* dst*/
31 P1 = R1 ; /* src*/
32 P2 = R2 ; /* length */
33
34 /* check for overlapping data */
35 CC = R1 < R0; /* src < dst */
36 IF !CC JUMP .Lno_overlap;
37 R3 = R1 + R2;
38 CC = R0 < R3; /* and dst < src+len */
39 IF CC JUMP .Lhas_overlap;
40
41.Lno_overlap:
42 /* Check for aligned data.*/
43
44 R3 = R1 | R0;
45 R0 = 0x3;
46 R3 = R3 & R0;
47 CC = R3; /* low bits set on either address? */
48 IF CC JUMP .Lnot_aligned;
49
50 /* Both addresses are word-aligned, so we can copy
51 at least part of the data using word copies.*/
52 P2 = P2 >> 2;
53 CC = P2 <= 2;
54 IF !CC JUMP .Lmore_than_seven;
55 /* less than eight bytes... */
56 P2 = R2;
57 LSETUP(.Lthree_start, .Lthree_end) LC0=P2;
58 R0 = R1; /* setup src address for return */
59.Lthree_start:
60 R3 = B[P1++] (X);
61.Lthree_end:
62 B[P0++] = R3;
63
64 RTS;
65
66.Lmore_than_seven:
67 /* There's at least eight bytes to copy. */
68 P2 += -1; /* because we unroll one iteration */
69 LSETUP(.Lword_loop, .Lword_loop) LC0=P2;
70 R0 = R1;
71 I1 = P1;
72 R3 = [I1++];
73.Lword_loop:
74 MNOP || [P0++] = R3 || R3 = [I1++];
75
76 [P0++] = R3;
77 /* Any remaining bytes to copy? */
78 R3 = 0x3;
79 R3 = R2 & R3;
80 CC = R3 == 0;
81 P1 = I1; /* in case there's something left, */
82 IF !CC JUMP .Lbytes_left;
83 RTS;
84.Lbytes_left: P2 = R3;
85.Lnot_aligned:
86 /* From here, we're copying byte-by-byte. */
87 LSETUP (.Lbyte_start , .Lbyte_end) LC0=P2;
88 R0 = R1; /* Save src address for return */
89.Lbyte_start:
90 R1 = B[P1++] (X);
91.Lbyte_end:
92 B[P0++] = R1;
93
94.L_P1L2147483647:
95 RTS;
96
97.Lhas_overlap:
98/* Need to reverse the copying, because the
99 * dst would clobber the src.
100 * Don't bother to work out alignment for
101 * the reverse case.
102 */
103 R0 = R1; /* save src for later. */
104 P0 = P0 + P2;
105 P0 += -1;
106 P1 = P1 + P2;
107 P1 += -1;
108 LSETUP(.Lover_start, .Lover_end) LC0=P2;
109.Lover_start:
110 R1 = B[P1--] (X);
111.Lover_end:
112 B[P0--] = R1;
113
114 RTS;