Path: blob/main/contrib/arm-optimized-routines/string/aarch64/experimental/strchr-sve.S
39507 views
/*1* strchr/strchrnul - find a character in a string2*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*/1617/* To build as strchrnul, define BUILD_STRCHRNUL before compiling this file. */18#ifdef BUILD_STRCHRNUL19#define FUNC __strchrnul_aarch64_sve20#else21#define FUNC __strchr_aarch64_sve22#endif2324ENTRY (FUNC)25dup z1.b, w1 /* replicate byte across vector */26setffr /* initialize FFR */27ptrue p1.b /* all ones; loop invariant */2829.p2align 430/* Read a vector's worth of bytes, stopping on first fault. */310: ldff1b z0.b, p1/z, [x0, xzr]32rdffrs p0.b, p1/z33b.nlast 2f3435/* First fault did not fail: the whole vector is valid.36Avoid depending on the contents of FFR beyond the branch. */37incb x0 /* speculate increment */38cmpeq p2.b, p1/z, z0.b, z1.b /* search for c */39cmpeq p3.b, p1/z, z0.b, 0 /* search for 0 */40orrs p4.b, p1/z, p2.b, p3.b /* c | 0 */41b.none 0b42decb x0 /* undo speculate */4344/* Found C or 0. */451: brka p4.b, p1/z, p4.b /* find first such */46sub x0, x0, 1 /* adjust pointer for that byte */47incp x0, p4.b48#ifndef BUILD_STRCHRNUL49ptest p4, p2.b /* was first in c? */50csel x0, xzr, x0, none /* if there was no c, return null */51#endif52ret5354/* First fault failed: only some of the vector is valid.55Perform the comparision only on the valid bytes. */562: cmpeq p2.b, p0/z, z0.b, z1.b /* search for c */57cmpeq p3.b, p0/z, z0.b, 0 /* search for 0 */58orrs p4.b, p0/z, p2.b, p3.b /* c | 0 */59b.any 1b6061/* No C or 0 found. Re-init FFR, increment, and loop. */62setffr63incp x0, p0.b64b 0b6566END (FUNC)676869