131914882SAlex Richardson/* 231914882SAlex Richardson * memchr - find a character in a memory zone 331914882SAlex Richardson * 4*072a4ba8SAndrew Turner * Copyright (c) 2018-2022, Arm Limited. 5*072a4ba8SAndrew Turner * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 631914882SAlex Richardson */ 731914882SAlex Richardson 8*072a4ba8SAndrew Turner#include "asmdefs.h" 931914882SAlex Richardson 1031914882SAlex Richardson#if __ARM_FEATURE_SVE 1131914882SAlex Richardson/* Assumptions: 1231914882SAlex Richardson * 1331914882SAlex Richardson * ARMv8-a, AArch64 1431914882SAlex Richardson * SVE Available. 1531914882SAlex Richardson */ 1631914882SAlex Richardson 1731914882SAlex RichardsonENTRY (__memchr_aarch64_sve) 1831914882SAlex Richardson PTR_ARG (0) 1931914882SAlex Richardson SIZE_ARG (2) 2031914882SAlex Richardson dup z1.b, w1 /* duplicate c to a vector */ 2131914882SAlex Richardson setffr /* initialize FFR */ 2231914882SAlex Richardson mov x3, 0 /* initialize off */ 2331914882SAlex Richardson 2431914882SAlex Richardson .p2align 4 2531914882SAlex Richardson0: whilelo p1.b, x3, x2 /* make sure off < max */ 2631914882SAlex Richardson b.none 9f 2731914882SAlex Richardson 2831914882SAlex Richardson /* Read a vector's worth of bytes, bounded by max, 2931914882SAlex Richardson stopping on first fault. */ 3031914882SAlex Richardson ldff1b z0.b, p1/z, [x0, x3] 3131914882SAlex Richardson rdffrs p0.b, p1/z 3231914882SAlex Richardson b.nlast 2f 3331914882SAlex Richardson 3431914882SAlex Richardson /* First fault did not fail: the vector bounded by max is valid. 3531914882SAlex Richardson Avoid depending on the contents of FFR beyond the branch. */ 3631914882SAlex Richardson incb x3 /* speculate increment */ 3731914882SAlex Richardson cmpeq p2.b, p1/z, z0.b, z1.b /* search for c */ 3831914882SAlex Richardson b.none 0b 3931914882SAlex Richardson decb x3 /* undo speculate */ 4031914882SAlex Richardson 4131914882SAlex Richardson /* Found C. */ 4231914882SAlex Richardson1: brkb p2.b, p1/z, p2.b /* find the first c */ 4331914882SAlex Richardson add x0, x0, x3 /* form partial pointer */ 4431914882SAlex Richardson incp x0, p2.b /* form final pointer to c */ 4531914882SAlex Richardson ret 4631914882SAlex Richardson 4731914882SAlex Richardson /* First fault failed: only some of the vector is valid. 4831914882SAlex Richardson Perform the comparision only on the valid bytes. */ 4931914882SAlex Richardson2: cmpeq p2.b, p0/z, z0.b, z1.b 5031914882SAlex Richardson b.any 1b 5131914882SAlex Richardson 5231914882SAlex Richardson /* No C found. Re-init FFR, increment, and loop. */ 5331914882SAlex Richardson setffr 5431914882SAlex Richardson incp x3, p0.b 5531914882SAlex Richardson b 0b 5631914882SAlex Richardson 5731914882SAlex Richardson /* Found end of count. */ 5831914882SAlex Richardson9: mov x0, 0 /* return null */ 5931914882SAlex Richardson ret 6031914882SAlex Richardson 6131914882SAlex RichardsonEND (__memchr_aarch64_sve) 6231914882SAlex Richardson 6331914882SAlex Richardson#endif 6431914882SAlex Richardson 65