]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/arm/string/memset.S
Merge ACPICA 20150717.
[FreeBSD/FreeBSD.git] / lib / libc / arm / string / memset.S
1 /*      $NetBSD: memset.S,v 1.4 2003/10/14 07:51:45 scw Exp $   */
2
3 /*
4  * Copyright 2003 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Steve C. Woodford for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed for the NetBSD Project by
20  *      Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 /*
38  * Copyright (c) 1995 Mark Brinicombe.
39  * All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  *    notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in the
48  *    documentation and/or other materials provided with the distribution.
49  * 3. All advertising materials mentioning features or use of this software
50  *    must display the following acknowledgement:
51  *      This product includes software developed by Mark Brinicombe.
52  * 4. The name of the company nor the name of the author may be used to
53  *    endorse or promote products derived from this software without specific
54  *    prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
57  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
58  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
60  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
61  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
62  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66  * SUCH DAMAGE.
67  */
68
69 #include <machine/asm.h>
70 __FBSDID("$FreeBSD$");
71
72 .syntax unified
73
74 /*
75  * memset: Sets a block of memory to the specified value
76  *
77  * On entry:
78  *   r0 - dest address
79  *   r1 - byte to write
80  *   r2 - number of bytes to write
81  *
82  * On exit:
83  *   r0 - dest address
84  */
85 #ifdef _BZERO
86 /* LINTSTUB: Func: void bzero(void *, size_t) */
87 ENTRY(bzero)
88         mov     r3, #0x00
89 #else
90 /* LINTSTUB: Func: void *memset(void *, int, size_t) */
91 ENTRY(memset)
92         and     r3, r1, #0xff           /* We deal with bytes */
93         mov     r1, r2
94 #endif
95         cmp     r1, #0x04               /* Do we have less than 4 bytes */
96         mov     ip, r0
97         blt     .Lmemset_lessthanfour
98
99         /* Ok first we will word align the address */
100         ands    r2, ip, #0x03           /* Get the bottom two bits */
101         bne     .Lmemset_wordunaligned  /* The address is not word aligned */
102
103         /* We are now word aligned */
104 .Lmemset_wordaligned:
105 #ifndef _BZERO
106         orr     r3, r3, r3, lsl #8      /* Extend value to 16-bits */
107 #endif
108 #ifdef _ARM_ARCH_5E
109         tst     ip, #0x04               /* Quad-align for armv5e */
110 #else
111         cmp     r1, #0x10
112 #endif
113 #ifndef _BZERO
114         orr     r3, r3, r3, lsl #16     /* Extend value to 32-bits */
115 #endif
116 #ifdef _ARM_ARCH_5E
117         itt     ne
118         subne   r1, r1, #0x04           /* Quad-align if necessary */
119         strne   r3, [ip], #0x04
120         cmp     r1, #0x10
121 #endif
122         blt     .Lmemset_loop4          /* If less than 16 then use words */
123         mov     r2, r3                  /* Duplicate data */
124         cmp     r1, #0x80               /* If < 128 then skip the big loop */
125         blt     .Lmemset_loop32
126
127         /* Do 128 bytes at a time */
128 .Lmemset_loop128:
129         subs    r1, r1, #0x80
130 #ifdef _ARM_ARCH_5E
131         itttt   ge
132         strdge  r2, [ip], #0x08
133         strdge  r2, [ip], #0x08
134         strdge  r2, [ip], #0x08
135         strdge  r2, [ip], #0x08
136         itttt   ge
137         strdge  r2, [ip], #0x08
138         strdge  r2, [ip], #0x08
139         strdge  r2, [ip], #0x08
140         strdge  r2, [ip], #0x08
141         itttt   ge
142         strdge  r2, [ip], #0x08
143         strdge  r2, [ip], #0x08
144         strdge  r2, [ip], #0x08
145         strdge  r2, [ip], #0x08
146         itttt   ge
147         strdge  r2, [ip], #0x08
148         strdge  r2, [ip], #0x08
149         strdge  r2, [ip], #0x08
150         strdge  r2, [ip], #0x08
151 #else
152         stmiage ip!, {r2-r3}
153         stmiage ip!, {r2-r3}
154         stmiage ip!, {r2-r3}
155         stmiage ip!, {r2-r3}
156         stmiage ip!, {r2-r3}
157         stmiage ip!, {r2-r3}
158         stmiage ip!, {r2-r3}
159         stmiage ip!, {r2-r3}
160         stmiage ip!, {r2-r3}
161         stmiage ip!, {r2-r3}
162         stmiage ip!, {r2-r3}
163         stmiage ip!, {r2-r3}
164         stmiage ip!, {r2-r3}
165         stmiage ip!, {r2-r3}
166         stmiage ip!, {r2-r3}
167         stmiage ip!, {r2-r3}
168 #endif
169         bgt     .Lmemset_loop128
170         it      eq
171         RETeq                   /* Zero length so just exit */
172
173         add     r1, r1, #0x80           /* Adjust for extra sub */
174
175         /* Do 32 bytes at a time */
176 .Lmemset_loop32:
177         subs    r1, r1, #0x20
178         itttt   ge
179 #ifdef _ARM_ARCH_5E
180         strdge  r2, [ip], #0x08
181         strdge  r2, [ip], #0x08
182         strdge  r2, [ip], #0x08
183         strdge  r2, [ip], #0x08
184 #else
185         stmiage ip!, {r2-r3}
186         stmiage ip!, {r2-r3}
187         stmiage ip!, {r2-r3}
188         stmiage ip!, {r2-r3}
189 #endif
190         bgt     .Lmemset_loop32
191         it      eq
192         RETeq                   /* Zero length so just exit */
193
194         adds    r1, r1, #0x10           /* Partially adjust for extra sub */
195
196         /* Deal with 16 bytes or more */
197         itt     ge
198 #ifdef _ARM_ARCH_5E
199         strdge  r2, [ip], #0x08
200         strdge  r2, [ip], #0x08
201 #else
202         stmiage ip!, {r2-r3}
203         stmiage ip!, {r2-r3}
204 #endif
205         it      eq
206         RETeq                   /* Zero length so just exit */
207
208         it      lt
209         addlt   r1, r1, #0x10           /* Possibly adjust for extra sub */
210
211         /* We have at least 4 bytes so copy as words */
212 .Lmemset_loop4:
213         subs    r1, r1, #0x04
214         it      ge
215         strge   r3, [ip], #0x04
216         bgt     .Lmemset_loop4
217         it      eq
218         RETeq                   /* Zero length so just exit */
219
220 #ifdef _ARM_ARCH_5E
221         /* Compensate for 64-bit alignment check */
222         adds    r1, r1, #0x04
223         it      eq
224         RETeq
225         cmp     r1, #2
226 #else
227         cmp     r1, #-2
228 #endif
229
230         strb    r3, [ip], #0x01         /* Set 1 byte */
231         it      ge
232         strbge  r3, [ip], #0x01         /* Set another byte */
233         it      gt
234         strbgt  r3, [ip]                /* and a third */
235         RET                     /* Exit */
236
237 .Lmemset_wordunaligned:
238         rsb     r2, r2, #0x004
239         strb    r3, [ip], #0x01         /* Set 1 byte */
240         cmp     r2, #0x02
241         it      ge
242         strbge  r3, [ip], #0x01         /* Set another byte */
243         sub     r1, r1, r2
244         it      gt
245         strbgt  r3, [ip], #0x01         /* and a third */
246         cmp     r1, #0x04               /* More than 4 bytes left? */
247         it      ge
248         bge     .Lmemset_wordaligned    /* Yup */
249
250 .Lmemset_lessthanfour:
251         cmp     r1, #0x00
252         it      eq
253         RETeq                   /* Zero length so exit */
254         strb    r3, [ip], #0x01         /* Set 1 byte */
255         cmp     r1, #0x02
256         it      ge
257         strbge  r3, [ip], #0x01         /* Set another byte */
258         it      gt
259         strbgt  r3, [ip]                /* and a third */
260         RET                     /* Exit */
261 #ifdef _BZERO
262 END(bzero)
263 #else
264 END(memset)
265 #endif