1*2fe8fb19SBen Gras/* $NetBSD: bzero.S,v 1.2 2003/10/06 05:30:21 matt Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/* $OpenBSD: bzero.S,v 1.3 2001/06/04 23:14:02 mickey Exp $ */ 4*2fe8fb19SBen Gras 5*2fe8fb19SBen Gras/* 6*2fe8fb19SBen Gras * (c) Copyright 1988 HEWLETT-PACKARD COMPANY 7*2fe8fb19SBen Gras * 8*2fe8fb19SBen Gras * To anyone who acknowledges that this file is provided "AS IS" 9*2fe8fb19SBen Gras * without any express or implied warranty: 10*2fe8fb19SBen Gras * permission to use, copy, modify, and distribute this file 11*2fe8fb19SBen Gras * for any purpose is hereby granted without fee, provided that 12*2fe8fb19SBen Gras * the above copyright notice and this notice appears in all 13*2fe8fb19SBen Gras * copies, and that the name of Hewlett-Packard Company not be 14*2fe8fb19SBen Gras * used in advertising or publicity pertaining to distribution 15*2fe8fb19SBen Gras * of the software without specific, written prior permission. 16*2fe8fb19SBen Gras * Hewlett-Packard Company makes no representations about the 17*2fe8fb19SBen Gras * suitability of this software for any purpose. 18*2fe8fb19SBen Gras */ 19*2fe8fb19SBen Gras/* 20*2fe8fb19SBen Gras * Copyright (c) 1990,1994 The University of Utah and 21*2fe8fb19SBen Gras * the Computer Systems Laboratory (CSL). All rights reserved. 22*2fe8fb19SBen Gras * 23*2fe8fb19SBen Gras * THE UNIVERSITY OF UTAH AND CSL PROVIDE THIS SOFTWARE IN ITS "AS IS" 24*2fe8fb19SBen Gras * CONDITION, AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES 25*2fe8fb19SBen Gras * WHATSOEVER RESULTING FROM ITS USE. 26*2fe8fb19SBen Gras * 27*2fe8fb19SBen Gras * CSL requests users of this software to return to csl-dist@cs.utah.edu any 28*2fe8fb19SBen Gras * improvements that they make and grant CSL redistribution rights. 29*2fe8fb19SBen Gras * 30*2fe8fb19SBen Gras * Utah $Hdr: bzero.s 1.9 94/12/14$ 31*2fe8fb19SBen Gras * Author: Bob Wheeler, University of Utah CSL 32*2fe8fb19SBen Gras */ 33*2fe8fb19SBen Gras 34*2fe8fb19SBen Gras#include <machine/asm.h> 35*2fe8fb19SBen Gras 36*2fe8fb19SBen Gras#ifdef SYSLIBC_SCCS 37*2fe8fb19SBen Gras .text 38*2fe8fb19SBen Gras .asciz "$OpenBSD: bzero.S,v 1.3 2001/06/04 23:14:02 mickey Exp $" 39*2fe8fb19SBen Gras .align 4 40*2fe8fb19SBen Gras#endif 41*2fe8fb19SBen Gras 42*2fe8fb19SBen Gras/* 43*2fe8fb19SBen Gras * void 44*2fe8fb19SBen Gras * bzero(dst, count) 45*2fe8fb19SBen Gras * void *dst; 46*2fe8fb19SBen Gras * size_t count; 47*2fe8fb19SBen Gras */ 48*2fe8fb19SBen GrasLEAF_ENTRY(bzero) 49*2fe8fb19SBen Gras comb,>=,n %r0,%arg1,$bzero_exit 50*2fe8fb19SBen Gras 51*2fe8fb19SBen Gras /* 52*2fe8fb19SBen Gras * If we need to clear less than a word do it a byte at a time 53*2fe8fb19SBen Gras */ 54*2fe8fb19SBen Gras 55*2fe8fb19SBen Gras comib,>>,n 4,%arg1,$bzero_bytes 56*2fe8fb19SBen Gras 57*2fe8fb19SBen Gras /* 58*2fe8fb19SBen Gras * Since we are only clearing memory the alignment restrictions 59*2fe8fb19SBen Gras * are simplified. Figure out how many "extra" bytes we need to 60*2fe8fb19SBen Gras * store with stbys. 61*2fe8fb19SBen Gras */ 62*2fe8fb19SBen Gras 63*2fe8fb19SBen Gras extru %arg0,31,2,%t1 64*2fe8fb19SBen Gras add %arg1,%t1,%arg1 65*2fe8fb19SBen Gras 66*2fe8fb19SBen Gras /* 67*2fe8fb19SBen Gras * We will zero the destination in blocks of 16 bytes as long as we 68*2fe8fb19SBen Gras * can and then we'll go to the 4 byte moves. 69*2fe8fb19SBen Gras */ 70*2fe8fb19SBen Gras 71*2fe8fb19SBen Gras comib,>>= 15, %arg1, $bzero_word 72*2fe8fb19SBen Gras addi -16, %arg1, %arg1 73*2fe8fb19SBen Gras 74*2fe8fb19SBen Gras$bzero_loop_16: 75*2fe8fb19SBen Gras stbys,b,m %r0,4(%arg0) 76*2fe8fb19SBen Gras stwm %r0,4(%arg0) 77*2fe8fb19SBen Gras stwm %r0,4(%arg0) 78*2fe8fb19SBen Gras stwm %r0,4(%arg0) 79*2fe8fb19SBen Gras comib,<< 15, %arg1, $bzero_loop_16 80*2fe8fb19SBen Gras addi -16, %arg1, %arg1 81*2fe8fb19SBen Gras 82*2fe8fb19SBen Gras /* 83*2fe8fb19SBen Gras * see if there is anything left that needs to be zeroed in a word 84*2fe8fb19SBen Gras * move. Since the count was decremented by 16, add 12 to test if 85*2fe8fb19SBen Gras * there are any full word moves left to do. 86*2fe8fb19SBen Gras */ 87*2fe8fb19SBen Gras 88*2fe8fb19SBen Gras$bzero_word: 89*2fe8fb19SBen Gras addib,<,n 12,%arg1,$bzero_cleanup 90*2fe8fb19SBen Gras 91*2fe8fb19SBen Gras$bzero_loop_4: 92*2fe8fb19SBen Gras addib,>= -4,%arg1,$bzero_loop_4 93*2fe8fb19SBen Gras stbys,b,m %r0,4(%arg0) 94*2fe8fb19SBen Gras 95*2fe8fb19SBen Gras /* 96*2fe8fb19SBen Gras * zero the last bytes that may be unaligned on a word boundary 97*2fe8fb19SBen Gras */ 98*2fe8fb19SBen Gras 99*2fe8fb19SBen Gras$bzero_cleanup: 100*2fe8fb19SBen Gras addib,=,n 4,%arg1,$bzero_exit 101*2fe8fb19SBen Gras add %arg0,%arg1,%arg0 102*2fe8fb19SBen Gras b $bzero_exit 103*2fe8fb19SBen Gras stbys,e %r0,0(%arg0) 104*2fe8fb19SBen Gras b,n $bzero_exit 105*2fe8fb19SBen Gras 106*2fe8fb19SBen Gras 107*2fe8fb19SBen Gras /* 108*2fe8fb19SBen Gras * zero by bytes 109*2fe8fb19SBen Gras */ 110*2fe8fb19SBen Gras 111*2fe8fb19SBen Gras$bzero_bytes: 112*2fe8fb19SBen Gras addib,> -1,%arg1,$bzero_bytes 113*2fe8fb19SBen Gras stbs,ma %r0,1(%arg0) 114*2fe8fb19SBen Gras 115*2fe8fb19SBen Gras$bzero_exit: 116*2fe8fb19SBen Gras bv,n %r0(%rp) 117*2fe8fb19SBen GrasEXIT(bzero) 118*2fe8fb19SBen Gras 119*2fe8fb19SBen Gras .end 120