1*24bb5fceSvisa/* $OpenBSD: strrchr.S,v 1.4 2021/07/24 05:35:56 visa Exp $ */ 25b859c19Sderaadt/*- 35b859c19Sderaadt * Copyright (c) 1991, 1993 45b859c19Sderaadt * The Regents of the University of California. All rights reserved. 55b859c19Sderaadt * 65b859c19Sderaadt * This code is derived from software contributed to Berkeley by 75b859c19Sderaadt * Ralph Campbell. 85b859c19Sderaadt * 95b859c19Sderaadt * Redistribution and use in source and binary forms, with or without 105b859c19Sderaadt * modification, are permitted provided that the following conditions 115b859c19Sderaadt * are met: 125b859c19Sderaadt * 1. Redistributions of source code must retain the above copyright 135b859c19Sderaadt * notice, this list of conditions and the following disclaimer. 145b859c19Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 155b859c19Sderaadt * notice, this list of conditions and the following disclaimer in the 165b859c19Sderaadt * documentation and/or other materials provided with the distribution. 175b859c19Sderaadt * 3. Neither the name of the University nor the names of its contributors 185b859c19Sderaadt * may be used to endorse or promote products derived from this software 195b859c19Sderaadt * without specific prior written permission. 205b859c19Sderaadt * 215b859c19Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 225b859c19Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 235b859c19Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 245b859c19Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 255b859c19Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 265b859c19Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 275b859c19Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 285b859c19Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 295b859c19Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 305b859c19Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 315b859c19Sderaadt * SUCH DAMAGE. 325b859c19Sderaadt */ 335b859c19Sderaadt 349b9d2a55Sguenther#include "SYS.h" 355b859c19Sderaadt 36cb39b413SmillertWEAK_ALIAS(rindex, strrchr) 37cb39b413Smillert 385b859c19SderaadtLEAF(strrchr, 0) 395b859c19Sderaadt .set reorder 405b859c19Sderaadt move v0, zero # default if not found 41*24bb5fceSvisa andi a1, 0xff 425b859c19Sderaadt1: 435b859c19Sderaadt lbu a3, 0(a0) # get a byte 445b859c19Sderaadt daddu a0, a0, 1 455b859c19Sderaadt bne a3, a1, 2f 465b859c19Sderaadt dsubu v0, a0, 1 # save address of last match 475b859c19Sderaadt2: 485b859c19Sderaadt bne a3, zero, 1b # continue if not end 495b859c19Sderaadt j ra 509b9d2a55SguentherEND_STRONG(strrchr) 51