xref: /original-bsd/lib/libc/mips/string/bzero.s (revision 5dc4a890)
1c32c7ac7Sbostic/*-
2*5dc4a890Sbostic * Copyright (c) 1991, 1993
3*5dc4a890Sbostic *	The Regents of the University of California.  All rights reserved.
4c32c7ac7Sbostic *
5c32c7ac7Sbostic * This code is derived from software contributed to Berkeley by
6c32c7ac7Sbostic * Ralph Campbell.
7c32c7ac7Sbostic *
8c32c7ac7Sbostic * %sccs.include.redist.c%
9c32c7ac7Sbostic */
10c32c7ac7Sbostic
11a839bd66Sralph#include <machine/machAsmDefs.h>
12c32c7ac7Sbostic
13c821a74bSbostic#if defined(LIBC_SCCS) && !defined(lint)
14*5dc4a890Sbostic	ASMSTR("@(#)bzero.s	8.1 (Berkeley) 06/04/93")
15c821a74bSbostic#endif /* LIBC_SCCS and not lint */
16c821a74bSbostic
17c32c7ac7Sbostic/* bzero(s1, n) */
18c32c7ac7Sbostic
19c32c7ac7SbosticLEAF(bzero)
20c32c7ac7Sbostic	.set	noreorder
21c32c7ac7Sbostic	blt	a1, 12, smallclr	# small amount to clear?
22c32c7ac7Sbostic	subu	a3, zero, a0		# compute # bytes to word align address
23c32c7ac7Sbostic	and	a3, a3, 3
24c32c7ac7Sbostic	beq	a3, zero, 1f		# skip if word aligned
25c32c7ac7Sbostic	subu	a1, a1, a3		# subtract from remaining count
26c32c7ac7Sbostic	swr	zero, 0(a0)		# clear 1, 2, or 3 bytes to align
27c32c7ac7Sbostic	addu	a0, a0, a3
28c32c7ac7Sbostic1:
29c32c7ac7Sbostic	and	v0, a1, 3		# compute number of words left
30c32c7ac7Sbostic	subu	a3, a1, v0
31c32c7ac7Sbostic	move	a1, v0
32c32c7ac7Sbostic	addu	a3, a3, a0		# compute ending address
33c32c7ac7Sbostic2:
34c32c7ac7Sbostic	addu	a0, a0, 4		# clear words
35d0798fd2Sralph	bne	a0, a3, 2b		#   unrolling loop doesnt help
36d0798fd2Sralph	sw	zero, -4(a0)		#   since we are limited by memory speed
37c32c7ac7Sbosticsmallclr:
38c32c7ac7Sbostic	ble	a1, zero, 2f
39c32c7ac7Sbostic	addu	a3, a1, a0		# compute ending address
40c32c7ac7Sbostic1:
41c32c7ac7Sbostic	addu	a0, a0, 1		# clear bytes
42c32c7ac7Sbostic	bne	a0, a3, 1b
43c32c7ac7Sbostic	sb	zero, -1(a0)
44c32c7ac7Sbostic2:
45c32c7ac7Sbostic	j	ra
46c32c7ac7Sbostic	nop
47c32c7ac7SbosticEND(bzero)
48