Path: blob/main/contrib/arm-optimized-routines/string/aarch64/experimental/memchr-sve.S
39507 views
/*1* memchr - find a character in a memory zone2*3* Copyright (c) 2018-2022, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "asmdefs.h"89.arch armv8-a+sve1011/* Assumptions:12*13* ARMv8-a, AArch6414* SVE Available.15*/1617ENTRY (__memchr_aarch64_sve)18dup z1.b, w1 /* duplicate c to a vector */19setffr /* initialize FFR */20mov x3, 0 /* initialize off */2122.p2align 4230: whilelo p1.b, x3, x2 /* make sure off < max */24b.none 9f2526/* Read a vector's worth of bytes, bounded by max,27stopping on first fault. */28ldff1b z0.b, p1/z, [x0, x3]29rdffrs p0.b, p1/z30b.nlast 2f3132/* First fault did not fail: the vector bounded by max is valid.33Avoid depending on the contents of FFR beyond the branch. */34incb x3 /* speculate increment */35cmpeq p2.b, p1/z, z0.b, z1.b /* search for c */36b.none 0b37decb x3 /* undo speculate */3839/* Found C. */401: brkb p2.b, p1/z, p2.b /* find the first c */41add x0, x0, x3 /* form partial pointer */42incp x0, p2.b /* form final pointer to c */43ret4445/* First fault failed: only some of the vector is valid.46Perform the comparision only on the valid bytes. */472: cmpeq p2.b, p0/z, z0.b, z1.b48b.any 1b4950/* No C found. Re-init FFR, increment, and loop. */51setffr52incp x3, p0.b53b 0b5455/* Found end of count. */569: mov x0, 0 /* return null */57ret5859END (__memchr_aarch64_sve)606162