xref: /netbsd-src/lib/libc/arch/mips/string/bzero.S (revision 42b55ff43aca2f3b38e1d3d6d0d1beabda118045)
1*42b55ff4Smatt/*	$NetBSD: bzero.S,v 1.10 2009/12/14 02:53:52 matt Exp $	*/
281b108b4Sjonathan
3ae1bfcddSglass/*-
4ae1bfcddSglass * Copyright (c) 1991, 1993
5ae1bfcddSglass *	The Regents of the University of California.  All rights reserved.
6ae1bfcddSglass *
7ae1bfcddSglass * This code is derived from software contributed to Berkeley by
8ae1bfcddSglass * Ralph Campbell.
9ae1bfcddSglass *
10ae1bfcddSglass * Redistribution and use in source and binary forms, with or without
11ae1bfcddSglass * modification, are permitted provided that the following conditions
12ae1bfcddSglass * are met:
13ae1bfcddSglass * 1. Redistributions of source code must retain the above copyright
14ae1bfcddSglass *    notice, this list of conditions and the following disclaimer.
15ae1bfcddSglass * 2. Redistributions in binary form must reproduce the above copyright
16ae1bfcddSglass *    notice, this list of conditions and the following disclaimer in the
17ae1bfcddSglass *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
19ae1bfcddSglass *    may be used to endorse or promote products derived from this software
20ae1bfcddSglass *    without specific prior written permission.
21ae1bfcddSglass *
22ae1bfcddSglass * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23ae1bfcddSglass * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ae1bfcddSglass * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ae1bfcddSglass * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26ae1bfcddSglass * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ae1bfcddSglass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ae1bfcddSglass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ae1bfcddSglass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ae1bfcddSglass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ae1bfcddSglass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ae1bfcddSglass * SUCH DAMAGE.
33ae1bfcddSglass */
34ae1bfcddSglass
359f3b0506Sjonathan#include <mips/asm.h>
36ae1bfcddSglass
37ae1bfcddSglass#if defined(LIBC_SCCS) && !defined(lint)
3822882071Smatt#if 0
3922882071Smatt	RCSID("from: @(#)bzero.s	8.1 (Berkeley) 6/4/93")
4022882071Smatt#else
41*42b55ff4Smatt	RCSID("$NetBSD: bzero.S,v 1.10 2009/12/14 02:53:52 matt Exp $")
4222882071Smatt#endif
43ae1bfcddSglass#endif /* LIBC_SCCS and not lint */
44ae1bfcddSglass
45d9af5eb2Sjonathan
46d9af5eb2Sjonathan#define _LOCORE		/* XXX not really, just assembly-code source */
47d9af5eb2Sjonathan#include <machine/endian.h>
48d9af5eb2Sjonathan
49ae1bfcddSglass/* bzero(s1, n) */
50ae1bfcddSglass
51201fac6eSmycroftLEAF(bzero)
52ae1bfcddSglass	.set	noreorder
5322882071Smatt	blt		a1, 3*SZREG, smallclr # small amount to clear?
5422882071Smatt	PTR_SUBU	a3, zero, a0	# compute # bytes to word align address
5522882071Smatt	and		a3, a3, SZREG-1
56ae1bfcddSglass	beq		a3, zero, 1f	# skip if word aligned
5722882071Smatt#if SZREG == 4
5822882071Smatt	PTR_SUBU	a1, a1, a3	# subtract from remaining count
59d9af5eb2Sjonathan	SWHI		zero, 0(a0)	# clear 1, 2, or 3 bytes to align
6022882071Smatt	PTR_ADDU	a0, a0, a3
6122882071Smatt#endif
6222882071Smatt#if SZREG == 8
6322882071Smatt	PTR_SUBU	a1, a1, a3	# subtract from remaining count
6422882071Smatt	PTR_ADDU	a0, a0, a3	# align dst to next word
6522882071Smatt	sll		a3, a3, 3	# bits to bytes
6622882071Smatt	li		a2, -1		# make a mask
6722882071Smatt#if _BYTE_ORDER == _BIG_ENDIAN
6822882071Smatt	REG_SRLV	a2, a2, a3	# we want to keep the MSB bytes
6922882071Smatt#endif
7022882071Smatt#if _BYTE_ORDER == _LITTLE_ENDIAN
7122882071Smatt	REG_SLLV	a2, a2, a3	# we want to keep the LSB bytes
7222882071Smatt#endif
7322882071Smatt	nor		a2, zero, a2	# complement the mask
74*42b55ff4Smatt	REG_L		v0, -SZREG(a0)	# load the word to partially clear
7522882071Smatt	and		v0, v0, a2	# clear the bytes
7622882071Smatt	REG_S		v0, -SZREG(a0)	# store it back
7722882071Smatt#endif
78ae1bfcddSglass1:
7922882071Smatt	and		v0, a1, SZREG-1	# compute number of words left
8022882071Smatt	PTR_SUBU	a3, a1, v0
81ae1bfcddSglass	move		a1, v0
8222882071Smatt	PTR_ADDU	a3, a3, a0	# compute ending address
83ae1bfcddSglass2:
8422882071Smatt	PTR_ADDU	a0, a0, SZREG	# clear words
85ae1bfcddSglass	bne		a0, a3, 2b	#  unrolling loop doesnt help
8622882071Smatt	REG_S		zero, -SZREG(a0) # since we are limited by memory speed
87ae1bfcddSglasssmallclr:
88ae1bfcddSglass	ble		a1, zero, 2f
8922882071Smatt	PTR_ADDU	a3, a1, a0	# compute ending address
90ae1bfcddSglass1:
9122882071Smatt	PTR_ADDU	a0, a0, 1	# clear bytes
92ae1bfcddSglass	bne		a0, a3, 1b
93ae1bfcddSglass	sb		zero, -1(a0)
94ae1bfcddSglass2:
95ae1bfcddSglass	j		ra
96ae1bfcddSglass	nop
97201fac6eSmycroftEND(bzero)
98