1/*	$NetBSD: bzero.S,v 1.2 1996/10/17 03:08:12 cgd Exp $	*/
2
3/*
4 * Copyright (c) 1995 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Trevor Blackwell
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22 *  School of Computer Science
23 *  Carnegie Mellon University
24 *  Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30#include <machine/asm.h>
31
32LEAF(bzero,2)
33	ble	a1,bzero_done
34	bic	a1,63,t3	/* t3 is # bytes to do 64 bytes at a time */
35
36	/* If nothing in first word, ignore it */
37	subq	zero,a0,t0
38	and	t0,7,t0		/* t0 = (0-size)%8 */
39	beq	t0,bzero_nostart1
40
41	cmpult	a1,t0,t1	/* if size > size%8 goto noshort */
42	beq	t1,bzero_noshort
43
44	/*
45	 * The whole thing is less than a word.
46	 * Mask off 1..7 bytes, and finish.
47	 */
48	ldq_u	t2,0(a0)
49	lda	t0,-1(zero)	/* t0=-1 */
50	mskql	t0,a1,t0	/* Get ff in bytes (a0%8)..((a0+a1-1)%8) */
51	insql	t0,a0,t0
52	bic	t2,t0,t2	/* zero those bytes in word */
53	stq_u	t2,0(a0)
54	RET
55
56bzero_noshort:
57	/* Handle the first partial word */
58	ldq_u	t2,0(a0)
59	subq	a1,t0,a1
60	mskql	t2,a0,t2	/* zero bytes (a0%8)..7 in word */
61	stq_u	t2,0(a0)
62
63	addq	a0,t0,a0	/* round a0 up to next word */
64	bic	a1,63,t3	/* recalc t3 (# bytes to do 64 bytes at a
65				   time) */
66
67bzero_nostart1:
68	/*
69	 * Loop, zeroing 64 bytes at a time
70	 */
71	beq	t3,bzero_lp_done
72bzero_lp:
73	stq	zero,0(a0)
74	stq	zero,8(a0)
75	stq	zero,16(a0)
76	stq	zero,24(a0)
77	subq	t3,64,t3
78	stq	zero,32(a0)
79	stq	zero,40(a0)
80	stq	zero,48(a0)
81	stq	zero,56(a0)
82	addq	a0,64,a0
83	bne	t3,bzero_lp
84
85bzero_lp_done:
86	/*
87	 * Handle the last 0..7 words.
88	 * We mask off the low bits, so we don't need an extra
89	 * compare instruction for the loop (just a bne. heh-heh)
90	 */
91	and	a1,0x38,t4
92	beq	t4,bzero_finish_lp_done
93bzero_finish_lp:
94	stq	zero,0(a0)
95	subq	t4,8,t4
96	addq	a0,8,a0
97	bne	t4,bzero_finish_lp
98
99	/* Do the last partial word */
100bzero_finish_lp_done:
101	and	a1,7,t5		/* 0..7 bytes left */
102	beq	t5,bzero_done	/* mskqh won't change t0 if t5==0, but I
103				   don't want to touch, say, a new VM page */
104	ldq	t0,0(a0)
105	mskqh	t0,t5,t0
106	stq	t0,0(a0)
107bzero_done:
108	RET
109
110	END(bzero)
111