Path: blob/main/contrib/arm-optimized-routines/string/aarch64/experimental/strlen-sve.S
39536 views
/*1* __strlen_aarch64_sve - compute the length of 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*/1617ENTRY (__strlen_aarch64_sve)18setffr /* initialize FFR */19ptrue p2.b /* all ones; loop invariant */20mov x1, 0 /* initialize length */2122/* Read a vector's worth of bytes, stopping on first fault. */23.p2align 4240: ldff1b z0.b, p2/z, [x0, x1]25rdffrs p0.b, p2/z26b.nlast 2f2728/* First fault did not fail: the whole vector is valid.29Avoid depending on the contents of FFR beyond the branch. */30incb x1, all /* speculate increment */31cmpeq p1.b, p2/z, z0.b, 0 /* loop if no zeros */32b.none 0b33decb x1, all /* undo speculate */3435/* Zero found. Select the bytes before the first and count them. */361: brkb p0.b, p2/z, p1.b37incp x1, p0.b38mov x0, x139ret4041/* First fault failed: only some of the vector is valid.42Perform the comparison only on the valid bytes. */432: cmpeq p1.b, p0/z, z0.b, 044b.any 1b4546/* No zero found. Re-init FFR, increment, and loop. */47setffr48incp x1, p0.b49b 0b5051END (__strlen_aarch64_sve)525354