blob: 7e6ee198eb7d0421fddb2650d1eb6cfb377d8228 [file] [log] [blame]
Aubrey.Li9da597f2007-03-09 13:38:44 +08001/*
2 * File: arch/blackfin/lib/memset.S
3 * Based on:
4 * Author:
5 *
6 * Created:
7 * Description:
8 *
9 * Rev: $Id: memset.S 2769 2007-02-19 16:45:53Z hennerich $
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
33.align 2
34
35/*
36 * C Library function MEMSET
37 * R0 = address (leave unchanged to form result)
38 * R1 = filler byte
39 * R2 = count
40 * Favours word aligned data.
41 */
42
43.globl _memset;
44_memset:
45 P0 = R0 ; /* P0 = address */
46 P2 = R2 ; /* P2 = count */
47 R3 = R0 + R2; /* end */
48 CC = R2 <= 7(IU);
49 IF CC JUMP .Ltoo_small;
50 R1 = R1.B (Z); /* R1 = fill char */
51 R2 = 3;
52 R2 = R0 & R2; /* addr bottom two bits */
53 CC = R2 == 0; /* AZ set if zero. */
54 IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
55
56.Laligned:
57 P1 = P2 >> 2; /* count = n/4 */
58 R2 = R1 << 8; /* create quad filler */
59 R2.L = R2.L + R1.L(NS);
60 R2.H = R2.L + R1.H(NS);
61 P2 = R3;
62
63 LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
64.Lquad_loop:
65 [P0++] = R2;
66
67 CC = P0 == P2;
68 IF !CC JUMP .Lbytes_left;
69 RTS;
70
71.Lbytes_left:
72 R2 = R3; /* end point */
73 R3 = P0; /* current position */
74 R2 = R2 - R3; /* bytes left */
75 P2 = R2;
76
77.Ltoo_small:
78 CC = P2 == 0; /* Check zero count */
79 IF CC JUMP .Lfinished; /* Unusual */
80
81.Lbytes:
82 LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
83.Lbyte_loop:
84 B[P0++] = R1;
85
86.Lfinished:
87 RTS;
88
89.Lforce_align:
90 CC = BITTST (R0, 0); /* odd byte */
91 R0 = 4;
92 R0 = R0 - R2;
93 P1 = R0;
94 R0 = P0; /* Recover return address */
95 IF !CC JUMP .Lskip1;
96 B[P0++] = R1;
97.Lskip1:
98 CC = R2 <= 2; /* 2 bytes */
99 P2 -= P1; /* reduce count */
100 IF !CC JUMP .Laligned;
101 B[P0++] = R1;
102 B[P0++] = R1;
103 JUMP .Laligned;