1*670c0525Svisa/* $OpenBSD: bzero.S,v 1.7 2022/01/29 05:47:36 visa Exp $ */ 205388d10Spefo/*- 305388d10Spefo * Copyright (c) 1991, 1993 405388d10Spefo * The Regents of the University of California. All rights reserved. 505388d10Spefo * 605388d10Spefo * This code is derived from software contributed to Berkeley by 705388d10Spefo * Ralph Campbell. 805388d10Spefo * 905388d10Spefo * Redistribution and use in source and binary forms, with or without 1005388d10Spefo * modification, are permitted provided that the following conditions 1105388d10Spefo * are met: 1205388d10Spefo * 1. Redistributions of source code must retain the above copyright 1305388d10Spefo * notice, this list of conditions and the following disclaimer. 1405388d10Spefo * 2. Redistributions in binary form must reproduce the above copyright 1505388d10Spefo * notice, this list of conditions and the following disclaimer in the 1605388d10Spefo * documentation and/or other materials provided with the distribution. 1705388d10Spefo * 3. Neither the name of the University nor the names of its contributors 1805388d10Spefo * may be used to endorse or promote products derived from this software 1905388d10Spefo * without specific prior written permission. 2005388d10Spefo * 2105388d10Spefo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2205388d10Spefo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2305388d10Spefo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2405388d10Spefo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2505388d10Spefo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2605388d10Spefo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2705388d10Spefo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2805388d10Spefo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2905388d10Spefo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3005388d10Spefo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3105388d10Spefo * SUCH DAMAGE. 3205388d10Spefo */ 3305388d10Spefo 3465efb508Spefo 3565efb508Spefo#include "DEFS.h" 3665efb508Spefo 3765efb508Spefo/* 3833702074Spefo * bzero(void *p, size_t len) 3965efb508Spefo */ 403cec60d6SpefoLEAF(bzero, 0) 4165efb508SpefoALEAF(blkclr) 4265efb508Spefo .set noreorder 43a4a5d88fSmiod#ifdef _STANDALONE 44*670c0525Svisa blt a1, 12, .Lsmallclr # small amount to clear? 4580fb28ddSpefo PTR_SUBU a3, zero, a0 # compute # bytes to word align address 46a4a5d88fSmiod and a3, a3, 3 47a4a5d88fSmiod beq a3, zero, 1f # skip if word aligned 4880fb28ddSpefo PTR_SUBU a1, a1, a3 # subtract from remaining count 49a4a5d88fSmiod SWHI zero, 0(a0) # clear 1, 2, or 3 bytes to align 5080fb28ddSpefo PTR_ADDU a0, a0, a3 51a4a5d88fSmiod1: 52a4a5d88fSmiod and v0, a1, 3 # compute number of words left 5380fb28ddSpefo PTR_SUBU a3, a1, v0 54a4a5d88fSmiod move a1, v0 5580fb28ddSpefo PTR_ADDU a3, a3, a0 # compute ending address 56a4a5d88fSmiod2: 5780fb28ddSpefo PTR_ADDU a0, a0, 4 # clear words 58a4a5d88fSmiod bne a0, a3, 2b # unrolling loop does not help 59a4a5d88fSmiod sw zero, -4(a0) # since we are limited by memory speed 60a4a5d88fSmiod#else 61*670c0525Svisa blt a1, 24, .Lsmallclr # small amount to clear? 6280fb28ddSpefo PTR_SUBU a3, zero, a0 # compute # bytes to word align address 6333702074Spefo and a3, a3, 7 6465efb508Spefo beq a3, zero, 1f # skip if word aligned 6580fb28ddSpefo PTR_SUBU a1, a1, a3 # subtract from remaining count 6633702074Spefo SDHI zero, 0(a0) # clear 1, 2, or 3 bytes to align 6780fb28ddSpefo PTR_ADDU a0, a0, a3 6865efb508Spefo1: 6933702074Spefo and v0, a1, 7 # compute number of words left 7080fb28ddSpefo PTR_SUBU a3, a1, v0 7165efb508Spefo move a1, v0 7280fb28ddSpefo PTR_ADDU a3, a3, a0 # compute ending address 7365efb508Spefo2: 7480fb28ddSpefo PTR_ADDU a0, a0, 8 # clear words 7565efb508Spefo bne a0, a3, 2b # unrolling loop does not help 7633702074Spefo sd zero, -8(a0) # since we are limited by memory speed 77a4a5d88fSmiod#endif 78*670c0525Svisa.Lsmallclr: 7965efb508Spefo ble a1, zero, 2f 8080fb28ddSpefo PTR_ADDU a3, a1, a0 # compute ending address 8165efb508Spefo1: 8280fb28ddSpefo PTR_ADDU a0, a0, 1 # clear bytes 8365efb508Spefo bne a0, a3, 1b 8465efb508Spefo sb zero, -1(a0) 8565efb508Spefo2: 8665efb508Spefo j ra 8765efb508Spefo nop 8865efb508SpefoEND(bzero) 89