1/* $OpenBSD: bzero.S,v 1.3 1996/11/13 22:05:07 niklas 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 33#if defined(LIBC_SCCS) 34 .text 35 .asciz "$OpenBSD: bzero.S,v 1.3 1996/11/13 22:05:07 niklas Exp $" 36#endif 37 38LEAF(bzero,2) 39 ble a1,bzero_done 40 bic a1,63,t3 /* t3 is # bytes to do 64 bytes at a time */ 41 42 /* If nothing in first word, ignore it */ 43 subq zero,a0,t0 44 and t0,7,t0 /* t0 = (0-size)%8 */ 45 beq t0,bzero_nostart1 46 47 cmpult a1,t0,t1 /* if size > size%8 goto noshort */ 48 beq t1,bzero_noshort 49 50 /* 51 * The whole thing is less than a word. 52 * Mask off 1..7 bytes, and finish. 53 */ 54 ldq_u t2,0(a0) 55 lda t0,-1(zero) /* t0=-1 */ 56 mskql t0,a1,t0 /* Get ff in bytes (a0%8)..((a0+a1-1)%8) */ 57 insql t0,a0,t0 58 bic t2,t0,t2 /* zero those bytes in word */ 59 stq_u t2,0(a0) 60 RET 61 62bzero_noshort: 63 /* Handle the first partial word */ 64 ldq_u t2,0(a0) 65 subq a1,t0,a1 66 mskql t2,a0,t2 /* zero bytes (a0%8)..7 in word */ 67 stq_u t2,0(a0) 68 69 addq a0,t0,a0 /* round a0 up to next word */ 70 bic a1,63,t3 /* recalc t3 (# bytes to do 64 bytes at a 71 time) */ 72 73bzero_nostart1: 74 /* 75 * Loop, zeroing 64 bytes at a time 76 */ 77 beq t3,bzero_lp_done 78bzero_lp: 79 stq zero,0(a0) 80 stq zero,8(a0) 81 stq zero,16(a0) 82 stq zero,24(a0) 83 subq t3,64,t3 84 stq zero,32(a0) 85 stq zero,40(a0) 86 stq zero,48(a0) 87 stq zero,56(a0) 88 addq a0,64,a0 89 bne t3,bzero_lp 90 91bzero_lp_done: 92 /* 93 * Handle the last 0..7 words. 94 * We mask off the low bits, so we don't need an extra 95 * compare instruction for the loop (just a bne. heh-heh) 96 */ 97 and a1,0x38,t4 98 beq t4,bzero_finish_lp_done 99bzero_finish_lp: 100 stq zero,0(a0) 101 subq t4,8,t4 102 addq a0,8,a0 103 bne t4,bzero_finish_lp 104 105 /* Do the last partial word */ 106bzero_finish_lp_done: 107 and a1,7,t5 /* 0..7 bytes left */ 108 beq t5,bzero_done /* mskqh won't change t0 if t5==0, but I 109 don't want to touch, say, a new VM page */ 110 ldq t0,0(a0) 111 mskqh t0,t5,t0 112 stq t0,0(a0) 113bzero_done: 114 RET 115 116 END(bzero) 117