x86: set cpu_index to nr_cpus instead of 0
[linux-2.6/s3c2410-cpufreq.git] / arch / blackfin / lib / memcpy.S
blobe654a18a0754c861f10a9fc049227060a8854cfe
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  *
15  * Modified:
16  *               Copyright 2004-2006 Analog Devices Inc.
17  *
18  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
19  *
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 2 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, see the file COPYING, or write
32  * to the Free Software Foundation, Inc.,
33  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
34  */
36 #include <linux/linkage.h>
38 /* void *memcpy(void *dest, const void *src, size_t n);
39  * R0 = To Address (dest) (leave unchanged to form result)
40  * R1 = From Address (src)
41  * R2 = count
42  *
43  * Note: Favours word alignment
44  */
46 #ifdef CONFIG_MEMCPY_L1
47 .section .l1.text
48 #else
49 .text
50 #endif
52 .align 2
54 ENTRY(_memcpy)
55         CC = R2 <=  0;  /* length not positive? */
56         IF CC JUMP .L_P1L2147483647;    /* Nothing to do */
58         P0 = R0 ;       /* dst*/
59         P1 = R1 ;       /* src*/
60         P2 = R2 ;       /* length */
62         /* check for overlapping data */
63         CC = R1 < R0;   /* src < dst */
64         IF !CC JUMP .Lno_overlap;
65         R3 = R1 + R2;
66         CC = R0 < R3;   /* and dst < src+len */
67         IF CC JUMP .Lhas_overlap;
69 .Lno_overlap:
70         /* Check for aligned data.*/
72         R3 = R1 | R0;
73         R1 = 0x3;
74         R3 = R3 & R1;
75         CC = R3;        /* low bits set on either address? */
76         IF CC JUMP .Lnot_aligned;
78         /* Both addresses are word-aligned, so we can copy
79         at least part of the data using word copies.*/
80         P2 = P2 >> 2;
81         CC = P2 <= 2;
82         IF !CC JUMP .Lmore_than_seven;
83         /* less than eight bytes... */
84         P2 = R2;
85         LSETUP(.Lthree_start, .Lthree_end) LC0=P2;
86 .Lthree_start:
87         R3 = B[P1++] (X);
88 .Lthree_end:
89         B[P0++] = R3;
91         RTS;
93 .Lmore_than_seven:
94         /* There's at least eight bytes to copy. */
95         P2 += -1;       /* because we unroll one iteration */
96         LSETUP(.Lword_loops, .Lword_loope) LC0=P2;
97         I1 = P1;
98         R3 = [I1++];
99 #if ANOMALY_05000202
100 .Lword_loops:
101         [P0++] = R3;
102 .Lword_loope:
103         R3 = [I1++];
104 #else
105 .Lword_loops:
106 .Lword_loope:
107         MNOP || [P0++] = R3 || R3 = [I1++];
108 #endif
109         [P0++] = R3;
110         /* Any remaining bytes to copy? */
111         R3 = 0x3;
112         R3 = R2 & R3;
113         CC = R3 == 0;
114         P1 = I1;        /* in case there's something left, */
115         IF !CC JUMP .Lbytes_left;
116         RTS;
117 .Lbytes_left:   P2 = R3;
118 .Lnot_aligned:
119         /* From here, we're copying byte-by-byte. */
120         LSETUP (.Lbyte_start, .Lbyte_end) LC0=P2;
121 .Lbyte_start:
122         R1 = B[P1++] (X);
123 .Lbyte_end:
124         B[P0++] = R1;
126 .L_P1L2147483647:
127         RTS;
129 .Lhas_overlap:
130         /* Need to reverse the copying, because the
131          * dst would clobber the src.
132          * Don't bother to work out alignment for
133          * the reverse case.
134          */
135         P0 = P0 + P2;
136         P0 += -1;
137         P1 = P1 + P2;
138         P1 += -1;
139         LSETUP(.Lover_start, .Lover_end) LC0=P2;
140 .Lover_start:
141         R1 = B[P1--] (X);
142 .Lover_end:
143         B[P0--] = R1;
145         RTS;
147 ENDPROC(_memcpy)