]> git.ipfire.org Git - people/ms/u-boot.git/blob - lib_blackfin/memcmp.S
Merge with /home/wd/git/u-boot/custodian/u-boot-mpc86xx
[people/ms/u-boot.git] / lib_blackfin / memcmp.S
1 /*
2 * File: arch/blackfin/lib/memcmp.S
3 * Based on:
4 * Author:
5 *
6 * Created:
7 * Description:
8 *
9 * Rev: $Id: memcmp.S 2386 2006-11-01 04:57:26Z magicyang $
10 *
11 * Modified:
12 * Copyright 2004-2006 Analog Devices Inc.
13 *
14 * Bugs: Enter bugs at http://blackfin.uclinux.org/
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see the file COPYING, or write
28 * to the Free Software Foundation, Inc.,
29 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
31
32 .align 2
33
34 /*
35 * C Library function MEMCMP
36 * R0 = First Address
37 * R1 = Second Address
38 * R2 = count
39 * Favours word aligned data.
40 */
41
42 .globl _memcmp;
43 _memcmp:
44 I1 = P3;
45 P0 = R0; /* P0 = s1 address */
46 P3 = R1; /* P3 = s2 Address */
47 P2 = R2 ; /* P2 = count */
48 CC = R2 <= 7(IU);
49 IF CC JUMP .Ltoo_small;
50 I0 = R1; /* s2 */
51 R1 = R1 | R0; /* OR addresses together */
52 R1 <<= 30; /* check bottom two bits */
53 CC = AZ; /* AZ set if zero. */
54 IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */
55
56 P1 = P2 >> 2; /* count = n/4 */
57 R3 = 3;
58 R2 = R2 & R3; /* remainder */
59 P2 = R2; /* set remainder */
60
61 LSETUP (.Lquad_loop_s , .Lquad_loop_e) LC0=P1;
62 .Lquad_loop_s:
63 NOP;
64 R0 = [P0++];
65 R1 = [I0++];
66 CC = R0 == R1;
67 IF !CC JUMP .Lquad_different;
68 .Lquad_loop_e:
69 NOP;
70
71 P3 = I0; /* s2 */
72 .Ltoo_small:
73 CC = P2 == 0; /* Check zero count*/
74 IF CC JUMP .Lfinished; /* very unlikely*/
75
76 .Lbytes:
77 LSETUP (.Lbyte_loop_s , .Lbyte_loop_e) LC0=P2;
78 .Lbyte_loop_s:
79 R1 = B[P3++](Z); /* *s2 */
80 R0 = B[P0++](Z); /* *s1 */
81 CC = R0 == R1;
82 IF !CC JUMP .Ldifferent;
83 .Lbyte_loop_e:
84 NOP;
85
86 .Ldifferent:
87 R0 = R0 - R1;
88 P3 = I1;
89 RTS;
90
91 .Lquad_different:
92 /* We've read two quads which don't match.
93 * Can't just compare them, because we're
94 * a little-endian machine, so the MSBs of
95 * the regs occur at later addresses in the
96 * string.
97 * Arrange to re-read those two quads again,
98 * byte-by-byte.
99 */
100 P0 += -4; /* back up to the start of the */
101 P3 = I0; /* quads, and increase the*/
102 P2 += 4; /* remainder count*/
103 P3 += -4;
104 JUMP .Lbytes;
105
106 .Lfinished:
107 R0 = 0;
108 P3 = I1;
109 RTS;