]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/string/arm/memset.S
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <features.h>
21 #include <sys/syscall.h>
22 #include <bits/arm_asm.h>
23
24 .text
25 .global memset
26 .type memset,%function
27 .align 4
28
29 #if defined(THUMB1_ONLY)
30 .thumb_func
31 memset:
32         mov     ip, r0
33         cmp     r2, #8          @ at least 8 bytes to do?
34         bcc     2f
35
36         lsl     r3, r1, #8
37         orr     r1, r3
38         lsl     r3, r1, #16
39         orr     r1, r3
40
41         mov     r3, #3
42 1:      @ Fill up to the first word boundary
43         tst     r0, r3
44         beq     1f
45         strb    r1, [r0]
46         add     r0, r0, #1
47         sub     r2, r2, #1
48         b       1b
49 1:      @ Fill aligned words
50         str     r1, [r0]
51         add     r0, r0, #4
52         sub     r2, r2, #4
53         cmp     r2, #4
54         bcs     1b
55
56 2:      @ Fill the remaining bytes
57         cmp     r2, #0
58         beq     2f
59 1:
60         strb    r1, [r0]
61         add     r0, r0, #1
62         sub     r2, r2, #1
63         bne     1b
64 2:
65         mov     r0, ip
66         bx lr
67 #else
68 memset:
69         mov     a4, a1
70         cmp     a3, $8          @ at least 8 bytes to do?
71         blt     2f
72         orr     a2, a2, a2, lsl $8
73         orr     a2, a2, a2, lsl $16
74 1:
75         tst     a4, $3          @ aligned yet?
76 #if defined(__thumb2__)
77         itt     ne
78         strbne  a2, [a4], $1
79         subne   a3, a3, $1
80 #else
81         strneb  a2, [a4], $1
82         subne   a3, a3, $1
83 #endif
84         bne     1b
85         mov     ip, a2
86 1:
87         cmp     a3, $8          @ 8 bytes still to do?
88         blt     2f
89         stmia   a4!, {a2, ip}
90         sub     a3, a3, $8
91         cmp     a3, $8          @ 8 bytes still to do?
92         blt     2f
93         stmia   a4!, {a2, ip}
94         sub     a3, a3, $8
95         cmp     a3, $8          @ 8 bytes still to do?
96         blt     2f
97         stmia   a4!, {a2, ip}
98         sub     a3, a3, $8
99         cmp     a3, $8          @ 8 bytes still to do?
100 #if defined(__thumb2__)
101         itt     ge
102         stmiage a4!, {a2, ip}
103         subge   a3, a3, $8
104 #else
105         stmgeia a4!, {a2, ip}
106         subge   a3, a3, $8
107 #endif
108         bge     1b
109 2:
110         movs    a3, a3          @ anything left?
111         IT(t, eq)
112 #if defined(__USE_BX__)
113         bxeq    lr
114 #else
115         moveq   pc, lr          @ nope
116 #endif
117 #if defined (__thumb2__)
118 1:
119         strb    a2, [a4], #1
120         subs    a3, a3, #1
121         bne     1b
122         bx      lr
123 #else
124         rsb     a3, a3, $7
125         add     pc, pc, a3, lsl $2
126         mov     r0, r0
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         strb    a2, [a4], $1
134 #if defined(__USE_BX__)
135         bx      lr
136 #else
137         mov     pc, lr
138 #endif
139 #endif
140 #endif
141
142 .size memset,.-memset
143
144 libc_hidden_def(memset)