2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <mach/machine/asm.h>
25 #include <architecture/arm/asm_help.h>
28 * A reasonably well-optimized bzero/memset. Should work equally well on arm11 and arm9 based
31 * The algorithm is to align the destination pointer on a 32 byte boundary and then
32 * blast data 64 bytes at a time, in two stores of 32 bytes per loop.
38 /* void *memset(void *ptr, int c, size_t len); */
40 /* move len into r1, unpack c into r2 */
43 orr r1, r1, r1, lsl #8
44 orr r2, r1, r1, lsl #16
49 /* void bzero(void *ptr, size_t len); */
51 /* zero out r2 so we can be just like memset(0) */
55 /* move the base pointer into r12 and leave r0 alone so that we return the original pointer */
58 /* copy r2 into r3 for 64-bit stores */
61 /* check for zero len */
65 /* fall back to a bytewise store for less than 32 bytes */
69 /* check for 32 byte unaligned ptr */
73 /* make sure we have more than 64 bytes to zero */
75 blt L_lessthan64aligned
77 /* >= 64 bytes of len, 32 byte aligned */
80 /* we need some registers, avoid r7 (frame pointer) and r9 (thread register) */
81 stmfd sp!, { r4-r6, r8, r10-r11 }
89 /* pre-subtract 64 from the len to avoid an extra compare in the loop */
93 stmia r12!, { r2-r6, r8, r10-r11 }
95 stmia r12!, { r2-r6, r8, r10-r11 }
98 /* restore the saved regs */
99 ldmfd sp!, { r4-r6, r8, r10-r11 }
101 /* check for completion (had previously subtracted an extra 64 from len) */
106 /* do we have 16 or more bytes left */
108 stmgeia r12!, { r2-r3 }
109 stmgeia r12!, { r2-r3 }
111 bgt L_lessthan64aligned
115 /* store 0 to 15 bytes */
116 mov r1, r1, lsl #28 /* move the remaining len bits [3:0] to the flags area of cpsr */
119 stmmiia r12!, { r2-r3 } /* n is set, store 8 bytes */
120 streq r2, [r12], #4 /* z is set, store 4 bytes */
121 strcsh r2, [r12], #2 /* c is set, store 2 bytes */
122 strvsb r2, [r12], #1 /* v is set, store 1 byte */
126 /* bytewise copy, 2 bytes at a time, alignment not guaranteed */
134 /* unaligned on 32 byte boundary, store 1-15 bytes until we're 16 byte aligned */
136 rsb r3, r3, #0x00000000
139 strvsb r2, [r12], #1 /* v is set, unaligned in the 1s column */
140 strcsh r2, [r12], #2 /* c is set, unaligned in the 2s column */
141 streq r2, [r12], #4 /* z is set, unaligned in the 4s column */
142 strmi r2, [r12], #4 /* n is set, unaligned in the 8s column */
145 subs r1, r1, r3, lsr #28
148 /* we had previously trashed r3, restore it */
151 /* now make sure we're 32 byte aligned */
153 stmneia r12!, { r2-r3 }
154 stmneia r12!, { r2-r3 }
157 /* we're now aligned, check for >= 64 bytes left */
159 bge L_64ormorealigned
160 b L_lessthan64aligned
162 X_LEAF(___bzero, _bzero)