1202719Sgabor/* $OpenBSD: bzero.S,v 1.5 2015/08/31 02:53:56 guenther Exp $ */ 2264573Sdelphij/* $NetBSD: bzero.S,v 1.2 1996/10/17 03:08:12 cgd Exp $ */ 3202719Sgabor 4202719Sgabor/* 5202719Sgabor * Copyright (c) 1995 Carnegie-Mellon University. 6202719Sgabor * All rights reserved. 7202719Sgabor * 8202719Sgabor * Author: Trevor Blackwell 9202719Sgabor * 10202719Sgabor * Permission to use, copy, modify and distribute this software and 11202719Sgabor * its documentation is hereby granted, provided that both the copyright 12202719Sgabor * notice and this permission notice appear in all copies of the 13202719Sgabor * software, derivative works or modified versions, and any portions 14202719Sgabor * thereof, and that both notices appear in supporting documentation. 15202719Sgabor * 16202719Sgabor * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17202719Sgabor * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18202719Sgabor * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19202719Sgabor * 20202719Sgabor * Carnegie Mellon requests users of this software to return to 21202719Sgabor * 22202719Sgabor * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23202719Sgabor * School of Computer Science 24202719Sgabor * Carnegie Mellon University 25202719Sgabor * Pittsburgh PA 15213-3890 26202719Sgabor * 27202719Sgabor * any improvements or extensions that they make and grant Carnegie the 28202719Sgabor * rights to redistribute these changes. 29202719Sgabor */ 30202719Sgabor 31202719Sgabor#include "SYS.h" 32202719Sgabor 33202719SgaborLEAF(bzero,2) 34202719Sgabor ble a1,bzero_done 35202719Sgabor bic a1,63,t3 /* t3 is # bytes to do 64 bytes at a time */ 36202719Sgabor 37202719Sgabor /* If nothing in first word, ignore it */ 38202719Sgabor subq zero,a0,t0 39202719Sgabor and t0,7,t0 /* t0 = (0-size)%8 */ 40202719Sgabor beq t0,bzero_nostart1 41202719Sgabor 42202719Sgabor cmpult a1,t0,t1 /* if size > size%8 goto noshort */ 43203498Sdelphij beq t1,bzero_noshort 44202719Sgabor 45202719Sgabor /* 46202719Sgabor * The whole thing is less than a word. 47202719Sgabor * Mask off 1..7 bytes, and finish. 48202719Sgabor */ 49202719Sgabor ldq_u t2,0(a0) 50232994Skevlo lda t0,-1(zero) /* t0=-1 */ 51202719Sgabor mskql t0,a1,t0 /* Get ff in bytes (a0%8)..((a0+a1-1)%8) */ 52202719Sgabor insql t0,a0,t0 53202719Sgabor bic t2,t0,t2 /* zero those bytes in word */ 54202719Sgabor stq_u t2,0(a0) 55264573Sdelphij RET 56202719Sgabor 57202719Sgaborbzero_noshort: 58202719Sgabor /* Handle the first partial word */ 59202719Sgabor ldq_u t2,0(a0) 60202719Sgabor subq a1,t0,a1 61202719Sgabor mskql t2,a0,t2 /* zero bytes (a0%8)..7 in word */ 62202719Sgabor stq_u t2,0(a0) 63202719Sgabor 64202719Sgabor addq a0,t0,a0 /* round a0 up to next word */ 65202719Sgabor bic a1,63,t3 /* recalc t3 (# bytes to do 64 bytes at a 66202719Sgabor time) */ 67202719Sgabor 68203443Sgaborbzero_nostart1: 69202719Sgabor /* 70202719Sgabor * Loop, zeroing 64 bytes at a time 71202719Sgabor */ 72202719Sgabor beq t3,bzero_lp_done 73202719Sgaborbzero_lp: 74202719Sgabor stq zero,0(a0) 75202719Sgabor stq zero,8(a0) 76202719Sgabor stq zero,16(a0) 77202719Sgabor stq zero,24(a0) 78202719Sgabor subq t3,64,t3 79202719Sgabor stq zero,32(a0) 80202719Sgabor stq zero,40(a0) 81202719Sgabor stq zero,48(a0) 82202719Sgabor stq zero,56(a0) 83291234Spfg addq a0,64,a0 84202719Sgabor bne t3,bzero_lp 85202719Sgabor 86202719Sgaborbzero_lp_done: 87202719Sgabor /* 88202719Sgabor * Handle the last 0..7 words. 89202719Sgabor * We mask off the low bits, so we don't need an extra 90202719Sgabor * compare instruction for the loop (just a bne. heh-heh) 91202719Sgabor */ 92202719Sgabor and a1,0x38,t4 93202719Sgabor beq t4,bzero_finish_lp_done 94202719Sgaborbzero_finish_lp: 95202719Sgabor stq zero,0(a0) 96202719Sgabor subq t4,8,t4 97202719Sgabor addq a0,8,a0 98202719Sgabor bne t4,bzero_finish_lp 99202719Sgabor 100202719Sgabor /* Do the last partial word */ 101202719Sgaborbzero_finish_lp_done: 102202719Sgabor and a1,7,t5 /* 0..7 bytes left */ 103202719Sgabor beq t5,bzero_done /* mskqh won't change t0 if t5==0, but I 104202719Sgabor don't want to touch, say, a new VM page */ 105202719Sgabor ldq t0,0(a0) 106202719Sgabor mskqh t0,t5,t0 107202719Sgabor stq t0,0(a0) 108202719Sgaborbzero_done: 109202719Sgabor RET 110202719Sgabor 111202719Sgabor END_WEAK(bzero) 112202719Sgabor