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