memset.S revision 256281
1284990Scy/* $NetBSD: memset.S,v 1.4 2003/10/14 07:51:45 scw Exp $ */ 2284990Scy 3284990Scy/* 4284990Scy * Copyright 2003 Wasabi Systems, Inc. 5284990Scy * All rights reserved. 6284990Scy * 7284990Scy * Written by Steve C. Woodford for Wasabi Systems, Inc. 8284990Scy * 9284990Scy * Redistribution and use in source and binary forms, with or without 10284990Scy * modification, are permitted provided that the following conditions 11284990Scy * are met: 12284990Scy * 1. Redistributions of source code must retain the above copyright 13284990Scy * notice, this list of conditions and the following disclaimer. 14284990Scy * 2. Redistributions in binary form must reproduce the above copyright 15284990Scy * notice, this list of conditions and the following disclaimer in the 16284990Scy * documentation and/or other materials provided with the distribution. 17284990Scy * 3. All advertising materials mentioning features or use of this software 18284990Scy * must display the following acknowledgement: 19284990Scy * This product includes software developed for the NetBSD Project by 20284990Scy * Wasabi Systems, Inc. 21284990Scy * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22284990Scy * or promote products derived from this software without specific prior 23284990Scy * written permission. 24284990Scy * 25290000Sglebius * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26290000Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27290000Sglebius * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28290000Sglebius * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29284990Scy * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30284990Scy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31284990Scy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32284990Scy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33290000Sglebius * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34290000Sglebius * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35290000Sglebius * POSSIBILITY OF SUCH DAMAGE. 36290000Sglebius */ 37290000Sglebius/* 38284990Scy * Copyright (c) 1995 Mark Brinicombe. 39284990Scy * All rights reserved. 40284990Scy * 41290000Sglebius * Redistribution and use in source and binary forms, with or without 42290000Sglebius * modification, are permitted provided that the following conditions 43284990Scy * are met: 44284990Scy * 1. Redistributions of source code must retain the above copyright 45284990Scy * notice, this list of conditions and the following disclaimer. 46284990Scy * 2. Redistributions in binary form must reproduce the above copyright 47284990Scy * notice, this list of conditions and the following disclaimer in the 48290000Sglebius * documentation and/or other materials provided with the distribution. 49284990Scy * 3. All advertising materials mentioning features or use of this software 50284990Scy * must display the following acknowledgement: 51284990Scy * This product includes software developed by Mark Brinicombe. 52284990Scy * 4. The name of the company nor the name of the author may be used to 53284990Scy * endorse or promote products derived from this software without specific 54284990Scy * prior written permission. 55284990Scy * 56284990Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 57290000Sglebius * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 58290000Sglebius * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59290000Sglebius * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 60290000Sglebius * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 61284990Scy * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 62284990Scy * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63284990Scy * 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: stable/10/lib/libc/arm/string/memset.S 172616 2007-10-13 12:06:31Z cognet $"); 71 72/* 73 * memset: Sets a block of memory to the specified value 74 * 75 * On entry: 76 * r0 - dest address 77 * r1 - byte to write 78 * r2 - number of bytes to write 79 * 80 * On exit: 81 * r0 - dest address 82 */ 83#ifdef _BZERO 84/* LINTSTUB: Func: void bzero(void *, size_t) */ 85ENTRY(bzero) 86 mov r3, #0x00 87#else 88/* LINTSTUB: Func: void *memset(void *, int, size_t) */ 89ENTRY(memset) 90 and r3, r1, #0xff /* We deal with bytes */ 91 mov r1, r2 92#endif 93 cmp r1, #0x04 /* Do we have less than 4 bytes */ 94 mov ip, r0 95 blt .Lmemset_lessthanfour 96 97 /* Ok first we will word align the address */ 98 ands r2, ip, #0x03 /* Get the bottom two bits */ 99 bne .Lmemset_wordunaligned /* The address is not word aligned */ 100 101 /* We are now word aligned */ 102.Lmemset_wordaligned: 103#ifndef _BZERO 104 orr r3, r3, r3, lsl #8 /* Extend value to 16-bits */ 105#endif 106#ifdef _ARM_ARCH_5E 107 tst ip, #0x04 /* Quad-align for armv5e */ 108#else 109 cmp r1, #0x10 110#endif 111#ifndef _BZERO 112 orr r3, r3, r3, lsl #16 /* Extend value to 32-bits */ 113#endif 114#ifdef _ARM_ARCH_5E 115 subne r1, r1, #0x04 /* Quad-align if necessary */ 116 strne r3, [ip], #0x04 117 cmp r1, #0x10 118#endif 119 blt .Lmemset_loop4 /* If less than 16 then use words */ 120 mov r2, r3 /* Duplicate data */ 121 cmp r1, #0x80 /* If < 128 then skip the big loop */ 122 blt .Lmemset_loop32 123 124 /* Do 128 bytes at a time */ 125.Lmemset_loop128: 126 subs r1, r1, #0x80 127#ifdef _ARM_ARCH_5E 128 strged r2, [ip], #0x08 129 strged r2, [ip], #0x08 130 strged r2, [ip], #0x08 131 strged r2, [ip], #0x08 132 strged r2, [ip], #0x08 133 strged r2, [ip], #0x08 134 strged r2, [ip], #0x08 135 strged r2, [ip], #0x08 136 strged r2, [ip], #0x08 137 strged r2, [ip], #0x08 138 strged r2, [ip], #0x08 139 strged r2, [ip], #0x08 140 strged r2, [ip], #0x08 141 strged r2, [ip], #0x08 142 strged r2, [ip], #0x08 143 strged r2, [ip], #0x08 144#else 145 stmgeia ip!, {r2-r3} 146 stmgeia ip!, {r2-r3} 147 stmgeia ip!, {r2-r3} 148 stmgeia ip!, {r2-r3} 149 stmgeia ip!, {r2-r3} 150 stmgeia ip!, {r2-r3} 151 stmgeia ip!, {r2-r3} 152 stmgeia ip!, {r2-r3} 153 stmgeia ip!, {r2-r3} 154 stmgeia ip!, {r2-r3} 155 stmgeia ip!, {r2-r3} 156 stmgeia ip!, {r2-r3} 157 stmgeia ip!, {r2-r3} 158 stmgeia ip!, {r2-r3} 159 stmgeia ip!, {r2-r3} 160 stmgeia ip!, {r2-r3} 161#endif 162 bgt .Lmemset_loop128 163 RETeq /* Zero length so just exit */ 164 165 add r1, r1, #0x80 /* Adjust for extra sub */ 166 167 /* Do 32 bytes at a time */ 168.Lmemset_loop32: 169 subs r1, r1, #0x20 170#ifdef _ARM_ARCH_5E 171 strged r2, [ip], #0x08 172 strged r2, [ip], #0x08 173 strged r2, [ip], #0x08 174 strged r2, [ip], #0x08 175#else 176 stmgeia ip!, {r2-r3} 177 stmgeia ip!, {r2-r3} 178 stmgeia ip!, {r2-r3} 179 stmgeia ip!, {r2-r3} 180#endif 181 bgt .Lmemset_loop32 182 RETeq /* Zero length so just exit */ 183 184 adds r1, r1, #0x10 /* Partially adjust for extra sub */ 185 186 /* Deal with 16 bytes or more */ 187#ifdef _ARM_ARCH_5E 188 strged r2, [ip], #0x08 189 strged r2, [ip], #0x08 190#else 191 stmgeia ip!, {r2-r3} 192 stmgeia ip!, {r2-r3} 193#endif 194 RETeq /* Zero length so just exit */ 195 196 addlt r1, r1, #0x10 /* Possibly adjust for extra sub */ 197 198 /* We have at least 4 bytes so copy as words */ 199.Lmemset_loop4: 200 subs r1, r1, #0x04 201 strge r3, [ip], #0x04 202 bgt .Lmemset_loop4 203 RETeq /* Zero length so just exit */ 204 205#ifdef _ARM_ARCH_5E 206 /* Compensate for 64-bit alignment check */ 207 adds r1, r1, #0x04 208 RETeq 209 cmp r1, #2 210#else 211 cmp r1, #-2 212#endif 213 214 strb r3, [ip], #0x01 /* Set 1 byte */ 215 strgeb r3, [ip], #0x01 /* Set another byte */ 216 strgtb r3, [ip] /* and a third */ 217 RET /* Exit */ 218 219.Lmemset_wordunaligned: 220 rsb r2, r2, #0x004 221 strb r3, [ip], #0x01 /* Set 1 byte */ 222 cmp r2, #0x02 223 strgeb r3, [ip], #0x01 /* Set another byte */ 224 sub r1, r1, r2 225 strgtb r3, [ip], #0x01 /* and a third */ 226 cmp r1, #0x04 /* More than 4 bytes left? */ 227 bge .Lmemset_wordaligned /* Yup */ 228 229.Lmemset_lessthanfour: 230 cmp r1, #0x00 231 RETeq /* Zero length so exit */ 232 strb r3, [ip], #0x01 /* Set 1 byte */ 233 cmp r1, #0x02 234 strgeb r3, [ip], #0x01 /* Set another byte */ 235 strgtb r3, [ip] /* and a third */ 236 RET /* Exit */ 237