blob: 6c834a7e8537821b73ffcdb771fc9abae9d193a2 [file] [log] [blame]
Aubrey.Li9da597f2007-03-09 13:38:44 +08001/*
Aubrey Li314d22f2007-04-05 18:31:18 +08002 * File: memcmp.S
Aubrey.Li9da597f2007-03-09 13:38:44 +08003 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright 2004-2007 Analog Devices Inc.
5 * Enter bugs at http://blackfin.uclinux.org/
Aubrey.Li9da597f2007-03-09 13:38:44 +08006 *
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;
Mike Frysinger6c097ce2008-02-19 00:36:14 -050034.type _memcmp, STT_FUNC;
Aubrey.Li9da597f2007-03-09 13:38:44 +080035_memcmp:
36 I1 = P3;
37 P0 = R0; /* P0 = s1 address */
38 P3 = R1; /* P3 = s2 Address */
39 P2 = R2 ; /* P2 = count */
40 CC = R2 <= 7(IU);
41 IF CC JUMP .Ltoo_small;
42 I0 = R1; /* s2 */
43 R1 = R1 | R0; /* OR addresses together */
44 R1 <<= 30; /* check bottom two bits */
45 CC = AZ; /* AZ set if zero. */
46 IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */
47
48 P1 = P2 >> 2; /* count = n/4 */
49 R3 = 3;
50 R2 = R2 & R3; /* remainder */
51 P2 = R2; /* set remainder */
52
53 LSETUP (.Lquad_loop_s , .Lquad_loop_e) LC0=P1;
54.Lquad_loop_s:
55 NOP;
56 R0 = [P0++];
57 R1 = [I0++];
58 CC = R0 == R1;
59 IF !CC JUMP .Lquad_different;
60.Lquad_loop_e:
61 NOP;
62
63 P3 = I0; /* s2 */
64.Ltoo_small:
65 CC = P2 == 0; /* Check zero count*/
66 IF CC JUMP .Lfinished; /* very unlikely*/
67
68.Lbytes:
69 LSETUP (.Lbyte_loop_s , .Lbyte_loop_e) LC0=P2;
70.Lbyte_loop_s:
71 R1 = B[P3++](Z); /* *s2 */
72 R0 = B[P0++](Z); /* *s1 */
73 CC = R0 == R1;
74 IF !CC JUMP .Ldifferent;
75.Lbyte_loop_e:
76 NOP;
77
78.Ldifferent:
79 R0 = R0 - R1;
80 P3 = I1;
81 RTS;
82
83.Lquad_different:
84/* We've read two quads which don't match.
85 * Can't just compare them, because we're
86 * a little-endian machine, so the MSBs of
87 * the regs occur at later addresses in the
88 * string.
89 * Arrange to re-read those two quads again,
90 * byte-by-byte.
91 */
92 P0 += -4; /* back up to the start of the */
93 P3 = I0; /* quads, and increase the*/
94 P2 += 4; /* remainder count*/
95 P3 += -4;
96 JUMP .Lbytes;
97
98.Lfinished:
99 R0 = 0;
100 P3 = I1;
101 RTS;
Mike Frysinger6c097ce2008-02-19 00:36:14 -0500102
103.size _memcmp, .-_memcmp