/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2021 Arm Ltd.3*/45#include <linux/linkage.h>6#include <asm/assembler.h>78/*9* Find a character in an area of memory.10*11* Parameters:12* x0 - buf13* x1 - c14* x2 - n15* Returns:16* x0 - address of first occurrence of 'c' or 017*/1819#define L(label) .L ## label2021#define REP8_01 0x010101010101010122#define REP8_7f 0x7f7f7f7f7f7f7f7f2324#define srcin x025#define chrin w126#define cntin x22728#define result x02930#define wordcnt x331#define rep01 x432#define repchr x533#define cur_word x634#define cur_byte w635#define tmp x736#define tmp2 x83738.p2align 439nop40SYM_FUNC_START(__pi_memchr)41and chrin, chrin, #0xff42lsr wordcnt, cntin, #343cbz wordcnt, L(byte_loop)44mov rep01, #REP8_0145mul repchr, x1, rep0146and cntin, cntin, #747L(word_loop):48ldr cur_word, [srcin], #849sub wordcnt, wordcnt, #150eor cur_word, cur_word, repchr51sub tmp, cur_word, rep0152orr tmp2, cur_word, #REP8_7f53bics tmp, tmp, tmp254b.ne L(found_word)55cbnz wordcnt, L(word_loop)56L(byte_loop):57cbz cntin, L(not_found)58ldrb cur_byte, [srcin], #159sub cntin, cntin, #160cmp cur_byte, chrin61b.ne L(byte_loop)62sub srcin, srcin, #163ret64L(found_word):65CPU_LE( rev tmp, tmp)66clz tmp, tmp67sub tmp, tmp, #6468add result, srcin, tmp, asr #369ret70L(not_found):71mov result, #072ret73SYM_FUNC_END(__pi_memchr)74SYM_FUNC_ALIAS_WEAK(memchr, __pi_memchr)75EXPORT_SYMBOL_NOKASAN(memchr)767778