]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/string/bfin/memmove.S
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / string / bfin / memmove.S
1 /* memmove.S
2  * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved.
3  *
4  * This file is subject to the terms and conditions of the GNU Library General
5  * Public License. See the file "COPYING.LIB" in the main directory of this
6  * archive for more details.
7  *
8  * Non-LGPL License also available as part of VisualDSP++
9  * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
10  */
11
12 #include <sysdep.h>
13
14 /* void *memmove(void *dest, const void *src, size_t n);
15  * R0 = To Address (dest) (leave unchanged to form result)
16  * R1 = From Address (src)
17  * R2 = count (n)
18  *
19  * Note: Data may overlap
20  */
21
22 .text
23
24 .align 2
25
26 .weak _memmove
27 ENTRY(_memmove)
28         I1 = P3;
29         P0 = R0;                  /* P0 = To address */
30         P3 = R1;                  /* P3 = From Address */
31         P2 = R2;                  /* P2 = count */
32         CC = P2 == 0;             /* Check zero count*/
33         IF CC JUMP .Lfinished;    /* very unlikely */
34
35         CC = R1 < R0 (IU);        /* From < To */
36         IF !CC JUMP .Lno_overlap;
37         R3 = R1 + R2;
38         CC = R0 <= R3 (IU);       /* (From+len) >= To */
39         IF CC JUMP .Loverlap;
40 .Lno_overlap:
41         R3 = 11;
42         CC = R2 <= R3;
43         IF CC JUMP .Lbytes;
44         R3 = R1 | R0;             /* OR addresses together */
45         R3 <<= 30;                /* check bottom two bits */
46         CC =  AZ;                 /* AZ set if zero.*/
47         IF !CC JUMP .Lbytes;      /* Jump if addrs not aligned.*/
48
49         I0 = P3;
50         P1 = P2 >> 2;             /* count = n/4 */
51         P1 += -1;
52         R3 =  3;
53         R2 = R2 & R3;             /* remainder */
54         P2 = R2;                  /* set remainder */
55         R1 = [I0++];
56
57 #if !defined(__WORKAROUND_AVOID_DAG1)
58         LSETUP (.Lquad_loop, .Lquad_loop) LC0=P1;
59 .Lquad_loop:    MNOP || [P0++] = R1 || R1 = [I0++];
60 #else
61         LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
62 .Lquad_loop_s:  [P0++] = R1;
63 .Lquad_loop_e:  R1 = [I0++];
64 #endif
65         [P0++] = R1;
66
67         CC = P2 == 0;             /* any remaining bytes? */
68         P3 = I0;                  /* Ammend P3 to updated ptr. */
69         IF !CC JUMP .Lbytes;
70         P3 = I1;
71         RTS;
72
73 .Lbytes:     LSETUP (.Lbyte2_s, .Lbyte2_e) LC0=P2;
74 .Lbyte2_s:   R1 = B[P3++](Z);
75 .Lbyte2_e:   B[P0++] = R1;
76
77 .Lfinished:  P3 = I1;
78         RTS;
79
80 .Loverlap:
81         P2 += -1;
82         P0 = P0 + P2;
83         P3 = P3 + P2;
84         R1 = B[P3--] (Z);
85         CC = P2 == 0;
86         IF CC JUMP .Lno_loop;
87 #if defined(__WORKAROUND_SPECULATIVE_LOADS)
88         NOP;
89         NOP;
90 #endif
91         LSETUP (.Lol_s, .Lol_e) LC0 = P2;
92 .Lol_s:    B[P0--] = R1;
93 .Lol_e:    R1 = B[P3--] (Z);
94 .Lno_loop: B[P0] = R1;
95         P3 = I1;
96         RTS;
97
98 .size _memmove,.-_memmove
99
100 libc_hidden_def (memmove)