xref: /linux/arch/riscv/lib/strchr.S (revision feff82eb5f4075d541990d0ba60dad14ea83ea9b)
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3/*
4 * Copyright (C) 2025 Feng Jiang <jiangfeng@kylinos.cn>
5 */
6
7#include <linux/linkage.h>
8#include <asm/asm.h>
9
10/* char *strchr(const char *s, int c) */
11SYM_FUNC_START(strchr)
12	/*
13	 * Parameters
14	 *   a0 - The string to be searched
15	 *   a1 - The character to search for
16	 *
17	 * Returns
18	 *   a0 - Address of first occurrence of 'c' or 0
19	 *
20	 * Clobbers
21	 *   t0
22	 */
23	andi	a1, a1, 0xff
241:
25	lbu	t0, 0(a0)
26	beq	t0, a1, 2f
27	addi	a0, a0, 1
28	bnez	t0, 1b
29	li	a0, 0
302:
31	ret
32SYM_FUNC_END(strchr)
33
34SYM_FUNC_ALIAS_WEAK(__pi_strchr, strchr)
35EXPORT_SYMBOL(strchr)
36