xref: /netbsd-src/common/lib/libc/arch/mips/string/strrchr.S (revision 6fbd2a0be4247b73a9060753554dc908b22a3ef5)
1*6fbd2a0bSjoerg/*	$NetBSD: strrchr.S,v 1.4 2017/02/25 21:16:50 joerg Exp $	*/
2487c31f5Sdsl
3487c31f5Sdsl/*-
4487c31f5Sdsl * Copyright (c) 1991, 1993
5487c31f5Sdsl *	The Regents of the University of California.  All rights reserved.
6487c31f5Sdsl *
7487c31f5Sdsl * This code is derived from software contributed to Berkeley by
8487c31f5Sdsl * Ralph Campbell.
9487c31f5Sdsl *
10487c31f5Sdsl * Redistribution and use in source and binary forms, with or without
11487c31f5Sdsl * modification, are permitted provided that the following conditions
12487c31f5Sdsl * are met:
13487c31f5Sdsl * 1. Redistributions of source code must retain the above copyright
14487c31f5Sdsl *    notice, this list of conditions and the following disclaimer.
15487c31f5Sdsl * 2. Redistributions in binary form must reproduce the above copyright
16487c31f5Sdsl *    notice, this list of conditions and the following disclaimer in the
17487c31f5Sdsl *    documentation and/or other materials provided with the distribution.
18487c31f5Sdsl * 3. Neither the name of the University nor the names of its contributors
19487c31f5Sdsl *    may be used to endorse or promote products derived from this software
20487c31f5Sdsl *    without specific prior written permission.
21487c31f5Sdsl *
22487c31f5Sdsl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23487c31f5Sdsl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24487c31f5Sdsl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25487c31f5Sdsl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26487c31f5Sdsl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27487c31f5Sdsl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28487c31f5Sdsl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29487c31f5Sdsl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30487c31f5Sdsl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31487c31f5Sdsl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32487c31f5Sdsl * SUCH DAMAGE.
33487c31f5Sdsl */
34487c31f5Sdsl
35487c31f5Sdsl#include <mips/asm.h>
36487c31f5Sdsl
37487c31f5Sdsl#if defined(LIBC_SCCS) && !defined(lint)
38487c31f5Sdsl	ASMSTR("from: @(#)rindex.s	8.1 (Berkeley) 6/4/93")
39*6fbd2a0bSjoerg	ASMSTR("$NetBSD: strrchr.S,v 1.4 2017/02/25 21:16:50 joerg Exp $")
40487c31f5Sdsl#endif /* LIBC_SCCS and not lint */
41487c31f5Sdsl
42*6fbd2a0bSjoerg#ifdef __mips_abicalls
43487c31f5Sdsl	.abicalls
44487c31f5Sdsl#endif
45487c31f5Sdsl
46487c31f5SdslLEAF(strrchr)
47487c31f5SdslXLEAF(rindex)
481d43c969Smatt	and	a1, 0xff		# limit to byte value
49487c31f5Sdsl	move	v0, zero		# default if not found
50487c31f5Sdsl1:
51487c31f5Sdsl	lbu	a3, 0(a0)		# get a byte
521b9f1d30Smatt	PTR_ADDU a0, a0, 1
53487c31f5Sdsl	bne	a3, a1, 2f
541b9f1d30Smatt	PTR_SUBU v0, a0, 1		# save address of last match
55487c31f5Sdsl2:
56487c31f5Sdsl	bne	a3, zero, 1b		# continue if not end
57487c31f5Sdsl	j	ra
58487c31f5SdslEND(strrchr)
59