1*9b9d2a55Sguenther/* $OpenBSD: bzero.S,v 1.6 2015/08/31 02:53:56 guenther Exp $ */ 20eea0d08Spefo/*- 30eea0d08Spefo * Copyright (c) 1991, 1993 40eea0d08Spefo * The Regents of the University of California. All rights reserved. 50eea0d08Spefo * 60eea0d08Spefo * This code is derived from software contributed to Berkeley by 70eea0d08Spefo * Ralph Campbell. 80eea0d08Spefo * 90eea0d08Spefo * Redistribution and use in source and binary forms, with or without 100eea0d08Spefo * modification, are permitted provided that the following conditions 110eea0d08Spefo * are met: 120eea0d08Spefo * 1. Redistributions of source code must retain the above copyright 130eea0d08Spefo * notice, this list of conditions and the following disclaimer. 140eea0d08Spefo * 2. Redistributions in binary form must reproduce the above copyright 150eea0d08Spefo * notice, this list of conditions and the following disclaimer in the 160eea0d08Spefo * documentation and/or other materials provided with the distribution. 170eea0d08Spefo * 3. Neither the name of the University nor the names of its contributors 180eea0d08Spefo * may be used to endorse or promote products derived from this software 190eea0d08Spefo * without specific prior written permission. 200eea0d08Spefo * 210eea0d08Spefo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 220eea0d08Spefo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 230eea0d08Spefo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 240eea0d08Spefo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 250eea0d08Spefo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 260eea0d08Spefo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 270eea0d08Spefo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 280eea0d08Spefo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 290eea0d08Spefo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 300eea0d08Spefo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 310eea0d08Spefo * SUCH DAMAGE. 320eea0d08Spefo */ 330eea0d08Spefo 34*9b9d2a55Sguenther#include "SYS.h" 350eea0d08Spefo 360eea0d08Spefo/* bzero(s1, n) */ 370eea0d08Spefo 385738bc62SpefoLEAF(bzero, 0) 390eea0d08Spefo .set noreorder 400eea0d08Spefo blt a1, 12, smallclr # small amount to clear? 4150027fe1Smiod dsubu a3, zero, a0 # compute # bytes to word align address 420eea0d08Spefo and a3, a3, 3 430eea0d08Spefo beq a3, zero, 1f # skip if word aligned 4450027fe1Smiod dsubu a1, a1, a3 # subtract from remaining count 450eea0d08Spefo SWHI zero, 0(a0) # clear 1, 2, or 3 bytes to align 4650027fe1Smiod daddu a0, a0, a3 470eea0d08Spefo1: 480eea0d08Spefo and v0, a1, 3 # compute number of words left 4950027fe1Smiod dsubu a3, a1, v0 500eea0d08Spefo move a1, v0 5150027fe1Smiod daddu a3, a3, a0 # compute ending address 520eea0d08Spefo2: 5350027fe1Smiod daddu a0, a0, 4 # clear words 544deeb878Spefo bne a0, a3, 2b # unrolling loop does not help 550eea0d08Spefo sw zero, -4(a0) # since we are limited by memory speed 560eea0d08Spefosmallclr: 570eea0d08Spefo ble a1, zero, 2f 5850027fe1Smiod daddu a3, a1, a0 # compute ending address 590eea0d08Spefo1: 6050027fe1Smiod daddu a0, a0, 1 # clear bytes 610eea0d08Spefo bne a0, a3, 1b 620eea0d08Spefo sb zero, -1(a0) 630eea0d08Spefo2: 640eea0d08Spefo j ra 650eea0d08Spefo nop 66*9b9d2a55SguentherEND_WEAK(bzero) 67