1*d719c1c9Smatt/*-
2*d719c1c9Smatt * Copyright (c) 2013 The NetBSD Foundation, Inc.
3*d719c1c9Smatt * All rights reserved.
4*d719c1c9Smatt *
5*d719c1c9Smatt * This code is derived from software contributed to The NetBSD Foundation
6*d719c1c9Smatt * by Matt Thomas of 3am Software Foundry.
7*d719c1c9Smatt *
8*d719c1c9Smatt * Redistribution and use in source and binary forms, with or without
9*d719c1c9Smatt * modification, are permitted provided that the following conditions
10*d719c1c9Smatt * are met:
11*d719c1c9Smatt * 1. Redistributions of source code must retain the above copyright
12*d719c1c9Smatt *    notice, this list of conditions and the following disclaimer.
13*d719c1c9Smatt * 2. Redistributions in binary form must reproduce the above copyright
14*d719c1c9Smatt *    notice, this list of conditions and the following disclaimer in the
15*d719c1c9Smatt *    documentation and/or other materials provided with the distribution.
16*d719c1c9Smatt *
17*d719c1c9Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18*d719c1c9Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*d719c1c9Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20*d719c1c9Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21*d719c1c9Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*d719c1c9Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*d719c1c9Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*d719c1c9Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*d719c1c9Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*d719c1c9Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*d719c1c9Smatt * POSSIBILITY OF SUCH DAMAGE.
28*d719c1c9Smatt */
29*d719c1c9Smatt#include <machine/asm.h>
30*d719c1c9Smatt
31*d719c1c9SmattRCSID("$NetBSD: strrchr_naive.S,v 1.1 2013/01/15 02:03:30 matt Exp $")
32*d719c1c9Smatt
33*d719c1c9Smatt/* LINTSTUB: char * strrchr(const char *, int) */
34*d719c1c9SmattENTRY(strrchr)
35*d719c1c9Smatt	mov	ip, r0		/* using r0 as return value */
36*d719c1c9Smatt	mov	r0, #0		/* default to no match */
37*d719c1c9Smatt	and	r1, r1, #0xff	/* restrict to a byte value */
38*d719c1c9Smatt1:	ldrb	r3, [ip], #1	/* read a byte */
39*d719c1c9Smatt	cmp	r3, r1		/* does it match? */
40*d719c1c9Smatt	subeq	r0, ip, #1	/*   yes, set return value to point to it */
41*d719c1c9Smatt	teq	r3, #0		/* was it a NUL? */
42*d719c1c9Smatt	bne	1b		/*   no, get next byte */
43*d719c1c9Smatt	RET
44*d719c1c9SmattEND(strrchr)
45