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