blob: c33c55112184abb235f18aa5cdf3132ebec02d28 [file] [log] [blame]
Aubrey.Li9da597f2007-03-09 13:38:44 +08001/*
Aubrey Li314d22f2007-04-05 18:31:18 +08002 * File: memset.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
Aubrey.Li9da597f2007-03-09 13:38:44 +080023.align 2
24
25/*
26 * C Library function MEMSET
27 * R0 = address (leave unchanged to form result)
28 * R1 = filler byte
29 * R2 = count
30 * Favours word aligned data.
31 */
32
33.globl _memset;
34_memset:
35 P0 = R0 ; /* P0 = address */
36 P2 = R2 ; /* P2 = count */
37 R3 = R0 + R2; /* end */
38 CC = R2 <= 7(IU);
39 IF CC JUMP .Ltoo_small;
40 R1 = R1.B (Z); /* R1 = fill char */
41 R2 = 3;
42 R2 = R0 & R2; /* addr bottom two bits */
43 CC = R2 == 0; /* AZ set if zero. */
44 IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
45
46.Laligned:
47 P1 = P2 >> 2; /* count = n/4 */
48 R2 = R1 << 8; /* create quad filler */
49 R2.L = R2.L + R1.L(NS);
50 R2.H = R2.L + R1.H(NS);
51 P2 = R3;
52
53 LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
54.Lquad_loop:
55 [P0++] = R2;
56
57 CC = P0 == P2;
58 IF !CC JUMP .Lbytes_left;
59 RTS;
60
61.Lbytes_left:
62 R2 = R3; /* end point */
63 R3 = P0; /* current position */
64 R2 = R2 - R3; /* bytes left */
65 P2 = R2;
66
67.Ltoo_small:
68 CC = P2 == 0; /* Check zero count */
69 IF CC JUMP .Lfinished; /* Unusual */
70
71.Lbytes:
72 LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
73.Lbyte_loop:
74 B[P0++] = R1;
75
76.Lfinished:
77 RTS;
78
79.Lforce_align:
80 CC = BITTST (R0, 0); /* odd byte */
81 R0 = 4;
82 R0 = R0 - R2;
83 P1 = R0;
84 R0 = P0; /* Recover return address */
85 IF !CC JUMP .Lskip1;
86 B[P0++] = R1;
87.Lskip1:
88 CC = R2 <= 2; /* 2 bytes */
89 P2 -= P1; /* reduce count */
90 IF !CC JUMP .Laligned;
91 B[P0++] = R1;
92 B[P0++] = R1;
93 JUMP .Laligned;