Home | History | Annotate | Line # | Download | only in string
      1  1.1  christos /*	$NetBSD: bzero.S,v 1.1 2005/12/20 19:28:50 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1992, 1993
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This software was developed by the Computer Systems Engineering group
      8  1.1  christos  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.1  christos  * contributed to Berkeley.
     10  1.1  christos  *
     11  1.1  christos  * Redistribution and use in source and binary forms, with or without
     12  1.1  christos  * modification, are permitted provided that the following conditions
     13  1.1  christos  * are met:
     14  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     16  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  christos  *    documentation and/or other materials provided with the distribution.
     19  1.1  christos  * 3. Neither the name of the University nor the names of its contributors
     20  1.1  christos  *    may be used to endorse or promote products derived from this software
     21  1.1  christos  *    without specific prior written permission.
     22  1.1  christos  *
     23  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  christos  * SUCH DAMAGE.
     34  1.1  christos  *
     35  1.1  christos  * from: Header: bzero.s,v 1.1 92/06/25 12:52:46 torek Exp
     36  1.1  christos  */
     37  1.1  christos 
     38  1.1  christos #include <machine/asm.h>
     39  1.1  christos #if defined(LIBC_SCCS) && !defined(lint)
     40  1.1  christos #if 0
     41  1.1  christos 	.asciz "@(#)bzero.s	8.1 (Berkeley) 6/4/93"
     42  1.1  christos #else
     43  1.1  christos 	RCSID("$NetBSD: bzero.S,v 1.1 2005/12/20 19:28:50 christos Exp $")
     44  1.1  christos #endif
     45  1.1  christos #endif  /* LIBC_SCCS and not lint */
     46  1.1  christos 
     47  1.1  christos /*
     48  1.1  christos  * We should unroll the loop, but at the moment this would
     49  1.1  christos  * gain nothing since the `std' instructions are what limits us.
     50  1.1  christos  */
     51  1.1  christos 
     52  1.1  christos #ifdef MEMSET
     53  1.1  christos /*
     54  1.1  christos  * void *
     55  1.1  christos  * memset(void *addr, int pattern, size_t len)
     56  1.1  christos  */
     57  1.1  christos ENTRY(memset)
     58  1.1  christos 	! %o0 = addr, %o1 = pattern, %o2 = len
     59  1.1  christos 	/*
     60  1.1  christos 	 * Expand the byte pattern to fill 64 bits in an even-aligned
     61  1.1  christos 	 * register pair; shuffle arguments to match those of bzero.
     62  1.1  christos 	 */
     63  1.1  christos 	and	%o1, 0xff, %o3
     64  1.1  christos 	mov	%o2, %o1		! shuffle argument
     65  1.1  christos 	sll	%o3, 8, %o2
     66  1.1  christos 	or	%o2, %o3, %o2
     67  1.1  christos 	mov	%o0, %g1		! save original pointer
     68  1.1  christos 	sll	%o2, 16, %o3
     69  1.1  christos 	or	%o2, %o3, %o2
     70  1.1  christos 	! Optimize a common case: addr and len are both multiples of 8.
     71  1.1  christos 	or	%o0, %o1, %o5
     72  1.1  christos 	btst	7, %o5			! ((addr | len) & 7) != 0?
     73  1.1  christos 	bnz	1f			! if so, cannot optimize
     74  1.1  christos 	 mov	%o2, %o3		! in any case, complete pat expansion
     75  1.1  christos #else
     76  1.1  christos /*
     77  1.1  christos  * void
     78  1.1  christos  * bzero(void *addr, size_t len)
     79  1.1  christos  */
     80  1.1  christos ENTRY(bzero)
     81  1.1  christos 	! %o0 = addr, %o1 = len
     82  1.1  christos 
     83  1.1  christos 	clr	%o2
     84  1.1  christos 	! Optimize a common case: addr and len are both multiples of 8.
     85  1.1  christos 	or	%o0, %o1, %o5
     86  1.1  christos 	btst	7, %o5			! ((addr | len) & 7) != 0?
     87  1.1  christos 	bnz	1f			! if so, cannot optimize
     88  1.1  christos 	 clr	%o3			! in any case, we want o3=0
     89  1.1  christos #endif
     90  1.1  christos 
     91  1.1  christos 	/* `Good' operands, can just store doubles. */
     92  1.1  christos 0:
     93  1.1  christos 	deccc	8, %o1			! while ((len -= 8) >= 0)
     94  1.1  christos 	bge,a	0b
     95  1.1  christos 	 std	%o2, [%o0 + %o1]	!	*(quad *)(addr + len) = 0;
     96  1.1  christos 	retl
     97  1.1  christos 	 nop
     98  1.1  christos 
     99  1.1  christos 	/*
    100  1.1  christos 	 * Either the address is unaligned, or the count is not a
    101  1.1  christos 	 * multiple of 8, or both.  We will have to align the address
    102  1.1  christos 	 * in order to use anything `better' than stb.
    103  1.1  christos 	 */
    104  1.1  christos 1:
    105  1.1  christos 	cmp	%o1, 15			! len >= 15?
    106  1.1  christos 	bge,a	Lstd			! yes, use std
    107  1.1  christos 	 btst	1, %o0			! (but first check alignment)
    108  1.1  christos 
    109  1.1  christos 	! not enough to bother: do byte-at-a-time loop.
    110  1.1  christos 2:
    111  1.1  christos 	deccc	%o1			! while (--len >= 0)
    112  1.1  christos 	bge,a	2b
    113  1.1  christos 	 stb	%o2, [%o0 + %o1]	!	addr[len] = 0;
    114  1.1  christos 	retl
    115  1.1  christos 	 nop
    116  1.1  christos 
    117  1.1  christos Lstd:
    118  1.1  christos 	/*
    119  1.1  christos 	 * There are at least 15 bytes to zero.
    120  1.1  christos 	 * We may have to zero some initial stuff to align
    121  1.1  christos 	 * the address.
    122  1.1  christos 	 */
    123  1.1  christos 	bz,a	1f			! if (addr & 1) {
    124  1.1  christos 	 btst	2, %o0
    125  1.1  christos 	stb	%o2, [%o0]		!	*addr = 0;
    126  1.1  christos 	inc	%o0			!	addr++;
    127  1.1  christos 	dec	%o1			!	len--;
    128  1.1  christos 	btst	2, %o0			! }
    129  1.1  christos 1:
    130  1.1  christos 	bz,a	1f			! if (addr & 2) {
    131  1.1  christos 	 btst	4, %o0
    132  1.1  christos 	sth	%o2, [%o0]		!	*(short *)addr = 0;
    133  1.1  christos 	inc	2, %o0			!	addr += 2;
    134  1.1  christos 	dec	2, %o1			!	len -= 2;
    135  1.1  christos 	btst	4, %o0			! }
    136  1.1  christos 1:
    137  1.1  christos 	bz	1f			! if (addr & 4) {
    138  1.1  christos 	 dec	8, %o1
    139  1.1  christos 	st	%o2, [%o0]		!	*(int *)addr = 0;
    140  1.1  christos 	inc	4, %o0			!	addr += 4;
    141  1.1  christos 	dec	4, %o1			!	len -= 4;
    142  1.1  christos 					! }
    143  1.1  christos 	/*
    144  1.1  christos 	 * Address is double word aligned; len is 8 less than
    145  1.1  christos 	 * the number of bytes remaining (i.e., len is 0 if
    146  1.1  christos 	 * the remaining count is 8, 1 if it is 9, etc.).
    147  1.1  christos 	 */
    148  1.1  christos 1:
    149  1.1  christos 	std	%o2, [%o0]		! do {
    150  1.1  christos 2:					!	*(quad *)addr = 0;
    151  1.1  christos 	inc	8, %o0			!	addr += 8;
    152  1.1  christos 	deccc	8, %o1			! } while ((len -= 8) >= 0);
    153  1.1  christos 	 bge,a	2b
    154  1.1  christos 	std	%o2, [%o0]
    155  1.1  christos 
    156  1.1  christos 	/*
    157  1.1  christos 	 * Len is in [-8..-1] where -8 => done, -7 => 1 byte to zero,
    158  1.1  christos 	 * -6 => two bytes, etc.  Mop up this remainder, if any.
    159  1.1  christos 	 */
    160  1.1  christos 	btst	4, %o1
    161  1.1  christos 	bz	1f			! if (len & 4) {
    162  1.1  christos 	 btst	2, %o1
    163  1.1  christos 	st	%o2, [%o0]		!	*(int *)addr = 0;
    164  1.1  christos 	inc	4, %o0			!	addr += 4;
    165  1.1  christos 1:
    166  1.1  christos 	bz	1f			! if (len & 2) {
    167  1.1  christos 	 btst	1, %o1
    168  1.1  christos 	sth	%o2, [%o0]		!	*(short *)addr = 0;
    169  1.1  christos 	inc	2, %o0			!	addr += 2;
    170  1.1  christos 1:
    171  1.1  christos 	bnz,a	1f			! if (len & 1)
    172  1.1  christos 	 stb	%o2, [%o0]		!	*addr = 0;
    173  1.1  christos 1:
    174  1.1  christos 	retl
    175  1.1  christos #ifdef MEMSET
    176  1.1  christos 	 mov	%g1, %o0		! restore original pointer
    177  1.1  christos #else
    178  1.1  christos 	 nop
    179  1.1  christos #endif
    180