OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libc / string / arm / memset.S
1 /* Copyright (C) 1998 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Philip Blundell <philb@gnu.org>
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #include <features.h>
20 #include <sys/syscall.h>
21 #include <bits/arm_asm.h>
22
23 .text
24 .global memset
25 .type memset,%function
26 .align 4
27
28 #if defined(THUMB1_ONLY)
29 .thumb_func
30 memset:
31         mov     ip, r0
32         cmp     r2, #8          @ at least 8 bytes to do?
33         bcc     2f
34
35         lsl     r3, r1, #8
36         orr     r1, r3
37         lsl     r3, r1, #16
38         orr     r1, r3
39
40         mov     r3, #3
41 1:      @ Fill up to the first word boundary
42         tst     r0, r3
43         beq     1f
44         strb    r1, [r0]
45         add     r0, r0, #1
46         sub     r2, r2, #1
47         b       1b
48 1:      @ Fill aligned words
49         str     r1, [r0]
50         add     r0, r0, #4
51         sub     r2, r2, #4
52         cmp     r2, #4
53         bcs     1b
54
55 2:      @ Fill the remaining bytes
56         cmp     r2, #0
57         beq     2f
58 1:
59         strb    r1, [r0]
60         add     r0, r0, #1
61         sub     r2, r2, #1
62         bne     1b
63 2:
64         mov     r0, ip
65         bx lr
66 #else
67 memset:
68         mov     a4, a1
69         cmp     a3, $8          @ at least 8 bytes to do?
70         blt     2f
71         orr     a2, a2, a2, lsl $8
72         orr     a2, a2, a2, lsl $16
73 1:
74         tst     a4, $3          @ aligned yet?
75 #if defined(__thumb2__)
76         itt     ne
77         strbne  a2, [a4], $1
78         subne   a3, a3, $1
79 #else
80         strneb  a2, [a4], $1
81         subne   a3, a3, $1
82 #endif
83         bne     1b
84         mov     ip, a2
85 1:
86         cmp     a3, $8          @ 8 bytes still to do?
87         blt     2f
88         stmia   a4!, {a2, ip}
89         sub     a3, a3, $8
90         cmp     a3, $8          @ 8 bytes still to do?
91         blt     2f
92         stmia   a4!, {a2, ip}
93         sub     a3, a3, $8
94         cmp     a3, $8          @ 8 bytes still to do?
95         blt     2f
96         stmia   a4!, {a2, ip}
97         sub     a3, a3, $8
98         cmp     a3, $8          @ 8 bytes still to do?
99 #if defined(__thumb2__)
100         itt     ge
101         stmiage a4!, {a2, ip}
102         subge   a3, a3, $8
103 #else
104         stmgeia a4!, {a2, ip}
105         subge   a3, a3, $8
106 #endif
107         bge     1b
108 2:
109         movs    a3, a3          @ anything left?
110         IT(t, eq)
111 #if defined(__USE_BX__)
112         bxeq    lr
113 #else
114         moveq   pc, lr          @ nope
115 #endif
116 #if defined (__thumb2__)
117 1:
118         strb    a2, [a4], #1
119         subs    a3, a3, #1
120         bne     1b
121         bx      lr
122 #else
123         rsb     a3, a3, $7
124         add     pc, pc, a3, lsl $2
125         mov     r0, r0
126         strb    a2, [a4], $1
127         strb    a2, [a4], $1
128         strb    a2, [a4], $1
129         strb    a2, [a4], $1
130         strb    a2, [a4], $1
131         strb    a2, [a4], $1
132         strb    a2, [a4], $1
133 #if defined(__USE_BX__)
134         bx      lr
135 #else
136         mov     pc, lr
137 #endif
138 #endif
139 #endif
140
141 .size memset,.-memset
142
143 libc_hidden_def(memset)