]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_blackfin/memcpy.S
Merge http://www.denx.de/git/u-boot
[karo-tx-uboot.git] / lib_blackfin / memcpy.S
1 /*
2  * File:         arch/blackfin/lib/memcpy.S
3  * Based on:
4  * Author:
5  *
6  * Created:
7  * Description:  internal version of memcpy(), issued by the compiler
8  *               to copy blocks of data around.
9  *               This is really memmove() - it has to be able to deal with
10  *               possible overlaps, because that ambiguity is when the compiler
11  *               gives up and calls a function. We have our own, internal version
12  *               so that we get something we trust, even if the user has redefined
13  *               the normal symbol.
14  * Rev:          $Id: memcpy.S 2775 2007-02-21 13:58:44Z hennerich $
15  *
16  * Modified:
17  *               Copyright 2004-2006 Analog Devices Inc.
18  *
19  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, see the file COPYING, or write
33  * to the Free Software Foundation, Inc.,
34  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
35  */
36 .align 2
37
38 .globl _memcpy_ASM;
39 _memcpy_ASM:
40         CC = R2 <=  0;  /* length not positive?*/
41         IF CC JUMP  .L_P1L2147483647;   /* Nothing to do */
42
43         P0 = R0 ;       /* dst*/
44         P1 = R1 ;       /* src*/
45         P2 = R2 ;       /* length */
46
47         /* check for overlapping data */
48         CC = R1 < R0;   /* src < dst */
49         IF !CC JUMP .Lno_overlap;
50         R3 = R1 + R2;
51         CC = R0 < R3;   /* and dst < src+len */
52         IF CC JUMP .Lhas_overlap;
53
54 .Lno_overlap:
55         /* Check for aligned data.*/
56
57         R3 = R1 | R0;
58         R0 = 0x3;
59         R3 = R3 & R0;
60         CC = R3;        /* low bits set on either address? */
61         IF CC JUMP .Lnot_aligned;
62
63         /* Both addresses are word-aligned, so we can copy
64         at least part of the data using word copies.*/
65         P2 = P2 >> 2;
66         CC = P2 <= 2;
67         IF !CC JUMP .Lmore_than_seven;
68         /* less than eight bytes... */
69         P2 = R2;
70         LSETUP(.Lthree_start, .Lthree_end) LC0=P2;
71         R0 = R1;        /* setup src address for return */
72 .Lthree_start:
73         R3 = B[P1++] (X);
74 .Lthree_end:
75         B[P0++] = R3;
76
77         RTS;
78
79 .Lmore_than_seven:
80         /* There's at least eight bytes to copy. */
81         P2 += -1;       /* because we unroll one iteration */
82         LSETUP(.Lword_loop, .Lword_loop) LC0=P2;
83         R0 = R1;
84         I1 = P1;
85         R3 = [I1++];
86 .Lword_loop:
87         MNOP || [P0++] = R3 || R3 = [I1++];
88
89         [P0++] = R3;
90         /* Any remaining bytes to copy? */
91         R3 = 0x3;
92         R3 = R2 & R3;
93         CC = R3 == 0;
94         P1 = I1;        /* in case there's something left, */
95         IF !CC JUMP .Lbytes_left;
96         RTS;
97 .Lbytes_left:   P2 = R3;
98 .Lnot_aligned:
99         /* From here, we're copying byte-by-byte. */
100         LSETUP (.Lbyte_start , .Lbyte_end) LC0=P2;
101         R0 = R1;        /* Save src address for return */
102 .Lbyte_start:
103         R1 = B[P1++] (X);
104 .Lbyte_end:
105         B[P0++] = R1;
106
107 .L_P1L2147483647:
108         RTS;
109
110 .Lhas_overlap:
111 /* Need to reverse the copying, because the
112  * dst would clobber the src.
113  * Don't bother to work out alignment for
114  * the reverse case.
115  */
116         R0 = R1;        /* save src for later. */
117         P0 = P0 + P2;
118         P0 += -1;
119         P1 = P1 + P2;
120         P1 += -1;
121         LSETUP(.Lover_start, .Lover_end) LC0=P2;
122 .Lover_start:
123         R1 = B[P1--] (X);
124 .Lover_end:
125         B[P0--] = R1;
126
127         RTS;