xref: /freebsd/lib/libc/arm/string/memset.S (revision 31489a9a2653e123121e8ca39b4be802013d2b50)
12357939bSOlivier Houchard/*	$NetBSD: memset.S,v 1.4 2003/10/14 07:51:45 scw Exp $	*/
22357939bSOlivier Houchard
32357939bSOlivier Houchard/*
42357939bSOlivier Houchard * Copyright 2003 Wasabi Systems, Inc.
52357939bSOlivier Houchard * All rights reserved.
62357939bSOlivier Houchard *
72357939bSOlivier Houchard * Written by Steve C. Woodford for Wasabi Systems, Inc.
82357939bSOlivier Houchard *
92357939bSOlivier Houchard * Redistribution and use in source and binary forms, with or without
102357939bSOlivier Houchard * modification, are permitted provided that the following conditions
112357939bSOlivier Houchard * are met:
122357939bSOlivier Houchard * 1. Redistributions of source code must retain the above copyright
132357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer.
142357939bSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright
152357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer in the
162357939bSOlivier Houchard *    documentation and/or other materials provided with the distribution.
172357939bSOlivier Houchard * 3. All advertising materials mentioning features or use of this software
182357939bSOlivier Houchard *    must display the following acknowledgement:
192357939bSOlivier Houchard *      This product includes software developed for the NetBSD Project by
202357939bSOlivier Houchard *      Wasabi Systems, Inc.
212357939bSOlivier Houchard * 4. The name of Wasabi Systems, Inc. may not be used to endorse
222357939bSOlivier Houchard *    or promote products derived from this software without specific prior
232357939bSOlivier Houchard *    written permission.
242357939bSOlivier Houchard *
252357939bSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
262357939bSOlivier Houchard * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
272357939bSOlivier Houchard * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
282357939bSOlivier Houchard * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
292357939bSOlivier Houchard * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
302357939bSOlivier Houchard * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
312357939bSOlivier Houchard * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
322357939bSOlivier Houchard * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
332357939bSOlivier Houchard * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
342357939bSOlivier Houchard * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
352357939bSOlivier Houchard * POSSIBILITY OF SUCH DAMAGE.
362357939bSOlivier Houchard */
372357939bSOlivier Houchard/*
382357939bSOlivier Houchard * Copyright (c) 1995 Mark Brinicombe.
392357939bSOlivier Houchard * All rights reserved.
402357939bSOlivier Houchard *
412357939bSOlivier Houchard * Redistribution and use in source and binary forms, with or without
422357939bSOlivier Houchard * modification, are permitted provided that the following conditions
432357939bSOlivier Houchard * are met:
442357939bSOlivier Houchard * 1. Redistributions of source code must retain the above copyright
452357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer.
462357939bSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright
472357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer in the
482357939bSOlivier Houchard *    documentation and/or other materials provided with the distribution.
492357939bSOlivier Houchard * 3. All advertising materials mentioning features or use of this software
502357939bSOlivier Houchard *    must display the following acknowledgement:
512357939bSOlivier Houchard *	This product includes software developed by Mark Brinicombe.
522357939bSOlivier Houchard * 4. The name of the company nor the name of the author may be used to
532357939bSOlivier Houchard *    endorse or promote products derived from this software without specific
542357939bSOlivier Houchard *    prior written permission.
552357939bSOlivier Houchard *
562357939bSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
572357939bSOlivier Houchard * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
582357939bSOlivier Houchard * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
592357939bSOlivier Houchard * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
602357939bSOlivier Houchard * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
612357939bSOlivier Houchard * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
622357939bSOlivier Houchard * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
632357939bSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
642357939bSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
652357939bSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
662357939bSOlivier Houchard * SUCH DAMAGE.
672357939bSOlivier Houchard */
682357939bSOlivier Houchard
692357939bSOlivier Houchard#include <machine/asm.h>
702357939bSOlivier Houchard__FBSDID("$FreeBSD$");
712357939bSOlivier Houchard
722357939bSOlivier Houchard/*
732357939bSOlivier Houchard * memset: Sets a block of memory to the specified value
742357939bSOlivier Houchard *
752357939bSOlivier Houchard * On entry:
762357939bSOlivier Houchard *   r0 - dest address
772357939bSOlivier Houchard *   r1 - byte to write
782357939bSOlivier Houchard *   r2 - number of bytes to write
792357939bSOlivier Houchard *
802357939bSOlivier Houchard * On exit:
812357939bSOlivier Houchard *   r0 - dest address
822357939bSOlivier Houchard */
832357939bSOlivier Houchard#ifdef _BZERO
842357939bSOlivier Houchard/* LINTSTUB: Func: void bzero(void *, size_t) */
852357939bSOlivier HouchardENTRY(bzero)
862357939bSOlivier Houchard	mov	r3, #0x00
872357939bSOlivier Houchard#else
882357939bSOlivier Houchard/* LINTSTUB: Func: void *memset(void *, int, size_t) */
892357939bSOlivier HouchardENTRY(memset)
902357939bSOlivier Houchard	and	r3, r1, #0xff		/* We deal with bytes */
912357939bSOlivier Houchard	mov	r1, r2
922357939bSOlivier Houchard#endif
932357939bSOlivier Houchard	cmp	r1, #0x04		/* Do we have less than 4 bytes */
942357939bSOlivier Houchard	mov	ip, r0
952357939bSOlivier Houchard	blt	.Lmemset_lessthanfour
962357939bSOlivier Houchard
972357939bSOlivier Houchard	/* Ok first we will word align the address */
982357939bSOlivier Houchard	ands	r2, ip, #0x03		/* Get the bottom two bits */
992357939bSOlivier Houchard	bne	.Lmemset_wordunaligned	/* The address is not word aligned */
1002357939bSOlivier Houchard
1012357939bSOlivier Houchard	/* We are now word aligned */
1022357939bSOlivier Houchard.Lmemset_wordaligned:
1032357939bSOlivier Houchard#ifndef _BZERO
1042357939bSOlivier Houchard	orr	r3, r3, r3, lsl #8	/* Extend value to 16-bits */
1052357939bSOlivier Houchard#endif
1062357939bSOlivier Houchard#ifdef __XSCALE__
1072357939bSOlivier Houchard	tst	ip, #0x04		/* Quad-align for Xscale */
1082357939bSOlivier Houchard#else
1092357939bSOlivier Houchard	cmp	r1, #0x10
1102357939bSOlivier Houchard#endif
1112357939bSOlivier Houchard#ifndef _BZERO
1122357939bSOlivier Houchard	orr	r3, r3, r3, lsl #16	/* Extend value to 32-bits */
1132357939bSOlivier Houchard#endif
1142357939bSOlivier Houchard#ifdef __XSCALE__
1152357939bSOlivier Houchard	subne	r1, r1, #0x04		/* Quad-align if necessary */
1162357939bSOlivier Houchard	strne	r3, [ip], #0x04
1172357939bSOlivier Houchard	cmp	r1, #0x10
1182357939bSOlivier Houchard#endif
1192357939bSOlivier Houchard	blt	.Lmemset_loop4		/* If less than 16 then use words */
1202357939bSOlivier Houchard	mov	r2, r3			/* Duplicate data */
1212357939bSOlivier Houchard	cmp	r1, #0x80		/* If < 128 then skip the big loop */
1222357939bSOlivier Houchard	blt	.Lmemset_loop32
1232357939bSOlivier Houchard
1242357939bSOlivier Houchard	/* Do 128 bytes at a time */
1252357939bSOlivier Houchard.Lmemset_loop128:
1262357939bSOlivier Houchard	subs	r1, r1, #0x80
1272357939bSOlivier Houchard#ifdef __XSCALE__
1282357939bSOlivier Houchard	strged	r2, [ip], #0x08
1292357939bSOlivier Houchard	strged	r2, [ip], #0x08
1302357939bSOlivier Houchard	strged	r2, [ip], #0x08
1312357939bSOlivier Houchard	strged	r2, [ip], #0x08
1322357939bSOlivier Houchard	strged	r2, [ip], #0x08
1332357939bSOlivier Houchard	strged	r2, [ip], #0x08
1342357939bSOlivier Houchard	strged	r2, [ip], #0x08
1352357939bSOlivier Houchard	strged	r2, [ip], #0x08
1362357939bSOlivier Houchard	strged	r2, [ip], #0x08
1372357939bSOlivier Houchard	strged	r2, [ip], #0x08
1382357939bSOlivier Houchard	strged	r2, [ip], #0x08
1392357939bSOlivier Houchard	strged	r2, [ip], #0x08
1402357939bSOlivier Houchard	strged	r2, [ip], #0x08
1412357939bSOlivier Houchard	strged	r2, [ip], #0x08
1422357939bSOlivier Houchard	strged	r2, [ip], #0x08
1432357939bSOlivier Houchard	strged	r2, [ip], #0x08
1442357939bSOlivier Houchard#else
1452357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1462357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1472357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1482357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1492357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1502357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1512357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1522357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1532357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1542357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1552357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1562357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1572357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1582357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1592357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1602357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1612357939bSOlivier Houchard#endif
1622357939bSOlivier Houchard	bgt	.Lmemset_loop128
16331489a9aSOlivier Houchard	RETeq			/* Zero length so just exit */
1642357939bSOlivier Houchard
1652357939bSOlivier Houchard	add	r1, r1, #0x80		/* Adjust for extra sub */
1662357939bSOlivier Houchard
1672357939bSOlivier Houchard	/* Do 32 bytes at a time */
1682357939bSOlivier Houchard.Lmemset_loop32:
1692357939bSOlivier Houchard	subs	r1, r1, #0x20
1702357939bSOlivier Houchard#ifdef __XSCALE__
1712357939bSOlivier Houchard	strged	r2, [ip], #0x08
1722357939bSOlivier Houchard	strged	r2, [ip], #0x08
1732357939bSOlivier Houchard	strged	r2, [ip], #0x08
1742357939bSOlivier Houchard	strged	r2, [ip], #0x08
1752357939bSOlivier Houchard#else
1762357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1772357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1782357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1792357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1802357939bSOlivier Houchard#endif
1812357939bSOlivier Houchard	bgt	.Lmemset_loop32
18231489a9aSOlivier Houchard	RETeq			/* Zero length so just exit */
1832357939bSOlivier Houchard
1842357939bSOlivier Houchard	adds	r1, r1, #0x10		/* Partially adjust for extra sub */
1852357939bSOlivier Houchard
1862357939bSOlivier Houchard	/* Deal with 16 bytes or more */
1872357939bSOlivier Houchard#ifdef __XSCALE__
1882357939bSOlivier Houchard	strged	r2, [ip], #0x08
1892357939bSOlivier Houchard	strged	r2, [ip], #0x08
1902357939bSOlivier Houchard#else
1912357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1922357939bSOlivier Houchard	stmgeia	ip!, {r2-r3}
1932357939bSOlivier Houchard#endif
19431489a9aSOlivier Houchard	RETeq			/* Zero length so just exit */
1952357939bSOlivier Houchard
1962357939bSOlivier Houchard	addlt	r1, r1, #0x10		/* Possibly adjust for extra sub */
1972357939bSOlivier Houchard
1982357939bSOlivier Houchard	/* We have at least 4 bytes so copy as words */
1992357939bSOlivier Houchard.Lmemset_loop4:
2002357939bSOlivier Houchard	subs	r1, r1, #0x04
2012357939bSOlivier Houchard	strge	r3, [ip], #0x04
2022357939bSOlivier Houchard	bgt	.Lmemset_loop4
20331489a9aSOlivier Houchard	RETeq			/* Zero length so just exit */
2042357939bSOlivier Houchard
2052357939bSOlivier Houchard#ifdef __XSCALE__
2062357939bSOlivier Houchard	/* Compensate for 64-bit alignment check */
2072357939bSOlivier Houchard	adds	r1, r1, #0x04
20831489a9aSOlivier Houchard	RETeq
2092357939bSOlivier Houchard	cmp	r1, #2
2102357939bSOlivier Houchard#else
2112357939bSOlivier Houchard	cmp	r1, #-2
2122357939bSOlivier Houchard#endif
2132357939bSOlivier Houchard
2142357939bSOlivier Houchard	strb	r3, [ip], #0x01		/* Set 1 byte */
2152357939bSOlivier Houchard	strgeb	r3, [ip], #0x01		/* Set another byte */
2162357939bSOlivier Houchard	strgtb	r3, [ip]		/* and a third */
21731489a9aSOlivier Houchard	RET			/* Exit */
2182357939bSOlivier Houchard
2192357939bSOlivier Houchard.Lmemset_wordunaligned:
2202357939bSOlivier Houchard	rsb	r2, r2, #0x004
2212357939bSOlivier Houchard	strb	r3, [ip], #0x01		/* Set 1 byte */
2222357939bSOlivier Houchard	cmp	r2, #0x02
2232357939bSOlivier Houchard	strgeb	r3, [ip], #0x01		/* Set another byte */
2242357939bSOlivier Houchard	sub	r1, r1, r2
2252357939bSOlivier Houchard	strgtb	r3, [ip], #0x01		/* and a third */
2262357939bSOlivier Houchard	cmp	r1, #0x04		/* More than 4 bytes left? */
2272357939bSOlivier Houchard	bge	.Lmemset_wordaligned	/* Yup */
2282357939bSOlivier Houchard
2292357939bSOlivier Houchard.Lmemset_lessthanfour:
2302357939bSOlivier Houchard	cmp	r1, #0x00
23131489a9aSOlivier Houchard	RETeq			/* Zero length so exit */
2322357939bSOlivier Houchard	strb	r3, [ip], #0x01		/* Set 1 byte */
2332357939bSOlivier Houchard	cmp	r1, #0x02
2342357939bSOlivier Houchard	strgeb	r3, [ip], #0x01		/* Set another byte */
2352357939bSOlivier Houchard	strgtb	r3, [ip]		/* and a third */
23631489a9aSOlivier Houchard	RET			/* Exit */
237