Annotation of sys/lib/libkern/arch/sparc/bzero.S, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: bzero.S,v 1.3 2003/06/02 23:28:09 millert Exp $ */
! 2: /* $NetBSD: bzero.S,v 1.2 1994/10/26 06:39:54 cgd Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1992, 1993
! 6: * The Regents of the University of California. All rights reserved.
! 7: *
! 8: * This software was developed by the Computer Systems Engineering group
! 9: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
! 10: * contributed to Berkeley.
! 11: *
! 12: * Redistribution and use in source and binary forms, with or without
! 13: * modification, are permitted provided that the following conditions
! 14: * are met:
! 15: * 1. Redistributions of source code must retain the above copyright
! 16: * notice, this list of conditions and the following disclaimer.
! 17: * 2. Redistributions in binary form must reproduce the above copyright
! 18: * notice, this list of conditions and the following disclaimer in the
! 19: * documentation and/or other materials provided with the distribution.
! 20: * 3. Neither the name of the University nor the names of its contributors
! 21: * may be used to endorse or promote products derived from this software
! 22: * without specific prior written permission.
! 23: *
! 24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 34: * SUCH DAMAGE.
! 35: *
! 36: * Header: bzero.s,v 1.1 92/06/25 12:52:46 torek Exp
! 37: */
! 38:
! 39: #if defined(LIBC_SCCS) && !defined(lint)
! 40: #ifdef notdef
! 41: .asciz "@(#)bzero.s 8.1 (Berkeley) 6/4/93"
! 42: #endif
! 43: .asciz "$OpenBSD: bzero.S,v 1.3 2003/06/02 23:28:09 millert Exp $"
! 44: #endif /* LIBC_SCCS and not lint */
! 45:
! 46: #include "DEFS.h"
! 47:
! 48: /*
! 49: * bzero(addr, len)
! 50: *
! 51: * We should unroll the loop, but at the moment this would
! 52: * gain nothing since the `std' instructions are what limits us.
! 53: */
! 54: ENTRY(bzero)
! 55: ! %o0 = addr, %o1 = len
! 56:
! 57: ! Optimize a common case: addr and len are both multiples of 8.
! 58: or %o0, %o1, %o2
! 59: btst 7, %o2 ! ((addr | len) & 7) != 0?
! 60: bnz 1f ! if so, cannot optimize
! 61: clr %g1 ! in any case, we want g1=0
! 62:
! 63: /* `Good' operands, can just store doubles. */
! 64: 0:
! 65: deccc 8, %o1 ! while ((len -= 8) >= 0)
! 66: bge,a 0b
! 67: std %g0, [%o0 + %o1] ! *(quad *)(addr + len) = 0;
! 68: retl
! 69: nop
! 70:
! 71: /*
! 72: * Either the address is unaligned, or the count is not a
! 73: * multiple of 8, or both. We will have to align the address
! 74: * in order to use anything `better' than stb.
! 75: */
! 76: 1:
! 77: cmp %o1, 15 ! len >= 15?
! 78: bge,a Lstd ! yes, use std
! 79: btst 1, %o0 ! (but first check alignment)
! 80:
! 81: ! not enough to bother: do byte-at-a-time loop.
! 82: 2:
! 83: deccc %o1 ! while (--len >= 0)
! 84: bge,a 2b
! 85: stb %g0, [%o0 + %o1] ! addr[len] = 0;
! 86: retl
! 87: nop
! 88:
! 89: Lstd:
! 90: /*
! 91: * There are at least 15 bytes to zero.
! 92: * We may have to zero some initial stuff to align
! 93: * the address.
! 94: */
! 95: bz,a 1f ! if (addr & 1) {
! 96: btst 2, %o0
! 97: stb %g0, [%o0] ! *addr = 0;
! 98: inc %o0 ! addr++;
! 99: dec %o1 ! len--;
! 100: btst 2, %o0 ! }
! 101: 1:
! 102: bz,a 1f ! if (addr & 2) {
! 103: btst 4, %o0
! 104: sth %g0, [%o0] ! *(short *)addr = 0;
! 105: inc 2, %o0 ! addr += 2;
! 106: dec 2, %o1 ! len -= 2;
! 107: btst 4, %o0 ! }
! 108: 1:
! 109: bz 1f ! if (addr & 4) {
! 110: dec 8, %o1
! 111: st %g0, [%o0] ! *(int *)addr = 0;
! 112: inc 4, %o0 ! addr += 4;
! 113: dec 4, %o1 ! len -= 4;
! 114: ! }
! 115: /*
! 116: * Address is double word aligned; len is 8 less than
! 117: * the number of bytes remaining (i.e., len is 0 if
! 118: * the remaining count is 8, 1 if it is 9, etc.).
! 119: */
! 120: 1:
! 121: std %g0, [%o0] ! do {
! 122: 2: ! *(quad *)addr = 0;
! 123: inc 8, %o0 ! addr += 8;
! 124: deccc 8, %o1 ! } while ((len -= 8) >= 0);
! 125: bge,a 2b
! 126: std %g0, [%o0]
! 127:
! 128: /*
! 129: * Len is in [-8..-1] where -8 => done, -7 => 1 byte to zero,
! 130: * -6 => two bytes, etc. Mop up this remainder, if any.
! 131: */
! 132: btst 4, %o1
! 133: bz 1f ! if (len & 4) {
! 134: btst 2, %o1
! 135: st %g0, [%o0] ! *(int *)addr = 0;
! 136: inc 4, %o0 ! addr += 4;
! 137: 1:
! 138: bz 1f ! if (len & 2) {
! 139: btst 1, %o1
! 140: sth %g0, [%o0] ! *(short *)addr = 0;
! 141: inc 2, %o0 ! addr += 2;
! 142: 1:
! 143: bnz,a 1f ! if (len & 1)
! 144: stb %g0, [%o0] ! *addr = 0;
! 145: 1:
! 146: retl
! 147: nop
CVSweb