2 * __strlen_aarch64_sve - compute the length of a string
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 __strlen_aarch64_sve
20 .type __strlen_aarch64_sve, %function
23 setffr /* initialize FFR */
24 ptrue p2.b /* all ones; loop invariant */
25 mov x1, 0 /* initialize length */
28 /* Read a vector's worth of bytes, stopping on first fault. */
29 0: ldff1b z0.b, p2/z, [x0, x1]
34 /* First fault did not fail: the whole vector is valid.
35 Avoid depending on the contents of FFR beyond the branch. */
36 incb x1, all /* speculate increment */
37 cmpeq p1.b, p2/z, z0.b, 0 /* loop if no zeros */
39 decb x1, all /* undo speculate */
41 /* Zero found. Select the bytes before the first and count them. */
42 1: brkb p0.b, p2/z, p1.b
47 /* First fault failed: only some of the vector is valid.
48 Perform the comparison only on the valid bytes. */
49 2: cmpeq p1.b, p0/z, z0.b, 0
52 /* No zero found. Re-init FFR, increment, and loop. */
57 .size __strlen_aarch64_sve, . - __strlen_aarch64_sve