xref: /OK3568_Linux_fs/kernel/arch/arm64/lib/memchr.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun/* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun/*
3*4882a593Smuzhiyun * Based on arch/arm/lib/memchr.S
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 1995-2000 Russell King
6*4882a593Smuzhiyun * Copyright (C) 2013 ARM Ltd.
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun#include <linux/linkage.h>
10*4882a593Smuzhiyun#include <asm/assembler.h>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun/*
13*4882a593Smuzhiyun * Find a character in an area of memory.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * Parameters:
16*4882a593Smuzhiyun *	x0 - buf
17*4882a593Smuzhiyun *	x1 - c
18*4882a593Smuzhiyun *	x2 - n
19*4882a593Smuzhiyun * Returns:
20*4882a593Smuzhiyun *	x0 - address of first occurrence of 'c' or 0
21*4882a593Smuzhiyun */
22*4882a593SmuzhiyunSYM_FUNC_START_WEAK_PI(memchr)
23*4882a593Smuzhiyun	and	w1, w1, #0xff
24*4882a593Smuzhiyun1:	subs	x2, x2, #1
25*4882a593Smuzhiyun	b.mi	2f
26*4882a593Smuzhiyun	ldrb	w3, [x0], #1
27*4882a593Smuzhiyun	cmp	w3, w1
28*4882a593Smuzhiyun	b.ne	1b
29*4882a593Smuzhiyun	sub	x0, x0, #1
30*4882a593Smuzhiyun	ret
31*4882a593Smuzhiyun2:	mov	x0, #0
32*4882a593Smuzhiyun	ret
33*4882a593SmuzhiyunSYM_FUNC_END_PI(memchr)
34*4882a593SmuzhiyunEXPORT_SYMBOL_NOKASAN(memchr)
35