1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2021 Arm Ltd.
6 #include <linux/linkage.h>
7 #include <asm/assembler.h>
10 * Find a character in an area of memory.
17 * x0 - address of first occurrence of 'c' or 0
20 #define L(label) .L ## label
22 #define REP8_01 0x0101010101010101
23 #define REP8_7f 0x7f7f7f7f7f7f7f7f
41 SYM_FUNC_START(__pi_memchr)
42 and chrin, chrin, #0xff
43 lsr wordcnt, cntin, #3
44 cbz wordcnt, L(byte_loop)
49 ldr cur_word, [srcin], #8
50 sub wordcnt, wordcnt, #1
51 eor cur_word, cur_word, repchr
52 sub tmp, cur_word, rep01
53 orr tmp2, cur_word, #REP8_7f
56 cbnz wordcnt, L(word_loop)
58 cbz cntin, L(not_found)
59 ldrb cur_byte, [srcin], #1
69 add result, srcin, tmp, asr #3
74 SYM_FUNC_END(__pi_memchr)
75 SYM_FUNC_ALIAS_WEAK(memchr, __pi_memchr)
76 EXPORT_SYMBOL_NOKASAN(memchr)