blob: 64012f78346ed7f06b57ee0bc7c8c81ca2e0fc5d [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* memset.S
2 * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved.
3 *
4 * This file is subject to the terms and conditions of the GNU Library General
5 * Public License. See the file "COPYING.LIB" in the main directory of this
6 * archive for more details.
7 *
8 * Non-LGPL License also available as part of VisualDSP++
9 * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
10 */
11
12#include <sysdep.h>
13
14/* void *memset(void *s, int c, size_t n);
15 * R0 = address (s) (leave unchanged to form result)
16 * R1 = filler byte (c)
17 * R2 = count (n)
18 *
19 * Note: Favours word aligned data.
20 */
21
22.text
23
24.align 2
25
26.weak _memset
27ENTRY(_memset)
28 P0 = R0 ; /* P0 = address */
29 P2 = R2 ; /* P2 = count */
30 R3 = R0 + R2; /* end */
31 CC = R2 <= 7(IU);
32 IF CC JUMP .Ltoo_small;
33 R1 = R1.B (Z); /* R1 = fill char */
34 R2 = 3;
35 R2 = R0 & R2; /* addr bottom two bits */
36 CC = R2 == 0; /* AZ set if zero. */
37 IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
38
39.Laligned:
40 P1 = P2 >> 2; /* count = n/4 */
41 R2 = R1 << 8; /* create quad filler */
42 R2.L = R2.L + R1.L(NS);
43 R2.H = R2.L + R1.H(NS);
44 P2 = R3;
45
46 LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
47.Lquad_loop:
48 [P0++] = R2;
49
50 CC = P0 == P2;
51 IF !CC JUMP .Lbytes_left;
52 RTS;
53
54.Lbytes_left:
55 R2 = R3; /* end point */
56 R3 = P0; /* current position */
57 R2 = R2 - R3; /* bytes left */
58 P2 = R2;
59
60.Ltoo_small:
61 CC = P2 == 0; /* Check zero count */
62 IF CC JUMP .Lfinished; /* Unusual */
63
64.Lbytes:
65 LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
66.Lbyte_loop:
67 B[P0++] = R1;
68
69.Lfinished:
70 RTS;
71
72.Lforce_align:
73 CC = BITTST (R0, 0); /* odd byte */
74 R0 = 4;
75 R0 = R0 - R2;
76 P1 = R0;
77 R0 = P0; /* Recover return address */
78 IF !CC JUMP .Lskip1;
79 B[P0++] = R1;
80.Lskip1:
81 CC = R2 <= 2; /* 2 bytes */
82 P2 -= P1; /* reduce count */
83 IF !CC JUMP .Laligned;
84 B[P0++] = R1;
85 B[P0++] = R1;
86 JUMP .Laligned;
87
88.size _memset,.-_memset
89
90libc_hidden_def (memset)