Merge with /home/wd/git/u-boot/custodian/u-boot-net
[oweals/u-boot.git] / lib_blackfin / memcmp.S
1 /*
2  * File: memcmp.S
3  *
4  * Copyright 2004-2007 Analog Devices Inc.
5  * Enter bugs at http://blackfin.uclinux.org/
6  *
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  */
22
23 .align 2
24
25 /*
26  * C Library function MEMCMP
27  * R0 = First Address
28  * R1 = Second Address
29  * R2 = count
30  * Favours word aligned data.
31  */
32
33 .globl _memcmp;
34 _memcmp:
35         I1 = P3;
36         P0 = R0;                        /* P0 = s1 address */
37         P3 = R1;                        /* P3 = s2 Address  */
38         P2 = R2 ;                       /* P2 = count */
39         CC = R2 <= 7(IU);
40         IF CC JUMP  .Ltoo_small;
41         I0 = R1;                        /* s2 */
42         R1 = R1 | R0;           /* OR addresses together */
43         R1 <<= 30;              /* check bottom two bits */
44         CC =  AZ;                       /* AZ set if zero. */
45         IF !CC JUMP  .Lbytes ;  /* Jump if addrs not aligned. */
46
47         P1 = P2 >> 2;           /* count = n/4 */
48         R3 =  3;
49         R2 = R2 & R3;           /* remainder */
50         P2 = R2;                        /* set remainder */
51
52         LSETUP (.Lquad_loop_s , .Lquad_loop_e) LC0=P1;
53 .Lquad_loop_s:
54         NOP;
55         R0 = [P0++];
56         R1 = [I0++];
57         CC = R0 == R1;
58         IF !CC JUMP .Lquad_different;
59 .Lquad_loop_e:
60         NOP;
61
62         P3 = I0;                        /* s2 */
63 .Ltoo_small:
64         CC = P2 == 0;           /* Check zero count*/
65         IF CC JUMP .Lfinished;  /* very unlikely*/
66
67 .Lbytes:
68         LSETUP (.Lbyte_loop_s , .Lbyte_loop_e) LC0=P2;
69 .Lbyte_loop_s:
70         R1 = B[P3++](Z);        /* *s2 */
71         R0 = B[P0++](Z);        /* *s1 */
72         CC = R0 == R1;
73         IF !CC JUMP .Ldifferent;
74 .Lbyte_loop_e:
75         NOP;
76
77 .Ldifferent:
78         R0 = R0 - R1;
79         P3 = I1;
80         RTS;
81
82 .Lquad_different:
83 /* We've read two quads which don't match.
84  * Can't just compare them, because we're
85  * a little-endian machine, so the MSBs of
86  * the regs occur at later addresses in the
87  * string.
88  * Arrange to re-read those two quads again,
89  * byte-by-byte.
90  */
91         P0 += -4;               /* back up to the start of the */
92         P3 = I0;                /* quads, and increase the*/
93         P2 += 4;                /* remainder count*/
94         P3 += -4;
95         JUMP .Lbytes;
96
97 .Lfinished:
98         R0 = 0;
99         P3 = I1;
100         RTS;