Path: blob/main/contrib/arm-optimized-routines/string/aarch64/experimental/strnlen-sve.S
39536 views
/*1* strnlen - calculate the length of a string with limit.2*3* Copyright (c) 2019-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 (__strnlen_aarch64_sve)18setffr /* initialize FFR */19mov x2, 0 /* initialize len */20b 1f2122.p2align 423/* We have off + vl <= max, and so may read the whole vector. */240: ldff1b z0.b, p0/z, [x0, x2]25rdffrs p1.b, p0/z26b.nlast 2f2728/* First fault did not fail: the whole vector is valid.29Avoid depending on the contents of FFR beyond the branch. */30cmpeq p2.b, p0/z, z0.b, 031b.any 8f32incb x233341: whilelo p0.b, x2, x135b.last 0b3637/* We have off + vl < max. Test for off == max before proceeding. */38b.none 9f3940ldff1b z0.b, p0/z, [x0, x2]41rdffrs p1.b, p0/z42b.nlast 2f4344/* First fault did not fail: the vector up to max is valid.45Avoid depending on the contents of FFR beyond the branch.46Compare for end-of-string, but there are no more bytes. */47cmpeq p2.b, p0/z, z0.b, 04849/* Found end-of-string or zero. */508: brkb p2.b, p0/z, p2.b51mov x0, x252incp x0, p2.b53ret5455/* First fault failed: only some of the vector is valid.56Perform the comparison only on the valid bytes. */572: cmpeq p2.b, p1/z, z0.b, 058b.any 8b5960/* No inequality or zero found. Re-init FFR, incr and loop. */61setffr62incp x2, p1.b63b 1b6465/* End of count. Return max. */669: mov x0, x167ret6869END (__strnlen_aarch64_sve)707172