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