2 * strnlen - calculate the length of a string with limit.
4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 * See https://llvm.org/LICENSE.txt for license information.
6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
19 .globl __strnlen_aarch64_sve
20 .type __strnlen_aarch64_sve, %function
22 __strnlen_aarch64_sve:
23 setffr /* initialize FFR */
24 mov x2, 0 /* initialize len */
28 /* We have off + vl <= max, and so may read the whole vector. */
29 0: ldff1b z0.b, p0/z, [x0, x2]
33 /* First fault did not fail: the whole vector is valid.
34 Avoid depending on the contents of FFR beyond the branch. */
35 cmpeq p2.b, p0/z, z0.b, 0
39 1: whilelo p0.b, x2, x1
42 /* We have off + vl < max. Test for off == max before proceeding. */
45 ldff1b z0.b, p0/z, [x0, x2]
49 /* First fault did not fail: the vector up to max is valid.
50 Avoid depending on the contents of FFR beyond the branch.
51 Compare for end-of-string, but there are no more bytes. */
52 cmpeq p2.b, p0/z, z0.b, 0
54 /* Found end-of-string or zero. */
55 8: brkb p2.b, p0/z, p2.b
60 /* First fault failed: only some of the vector is valid.
61 Perform the comparison only on the valid bytes. */
62 2: cmpeq p2.b, p1/z, z0.b, 0
65 /* No inequality or zero found. Re-init FFR, incr and loop. */
70 /* End of count. Return max. */
74 .size __strnlen_aarch64_sve, . - __strnlen_aarch64_sve