1/*
2 * Based on arch/arm/lib/strrchr.S
3 *
4 * Copyright (C) 1995-2000 Russell King
5 * Copyright (C) 2013 ARM Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * Find the last occurrence of a character in a string.
22 *
23 * Parameters:
24 *	x0 - str
25 *	x1 - c
26 * Returns:
27 *	x0 - address of last occurrence of 'c' or 0
28 */
29ENTRY(strrchr)
30	mov	x3, #0
31	and	w1, w1, #0xff
321:	ldrb	w2, [x0], #1
33	cbz	w2, 2f
34	cmp	w2, w1
35	b.ne	1b
36	sub	x3, x0, #1
37	b	1b
382:	mov	x0, x3
39	ret
40ENDPROC(strrchr)
41