76 lines · plain
1/*2 * strnlen - calculate the length of a string with limit.3 *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-exception7 */8 9#if __ARM_FEATURE_SVE10/* Assumptions:11 *12 * ARMv8-a, AArch6413 * SVE Available.14 */15 16 .arch armv8-a+sve17 .text18 19 .globl __strnlen_aarch64_sve20 .type __strnlen_aarch64_sve, %function21 .p2align 422__strnlen_aarch64_sve:23 setffr /* initialize FFR */24 mov x2, 0 /* initialize len */25 b 1f26 27 .p2align 428 /* We have off + vl <= max, and so may read the whole vector. */290: ldff1b z0.b, p0/z, [x0, x2]30 rdffrs p1.b, p0/z31 b.nlast 2f32 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, 036 b.any 8f37 incb x238 391: whilelo p0.b, x2, x140 b.last 0b41 42 /* We have off + vl < max. Test for off == max before proceeding. */43 b.none 9f44 45 ldff1b z0.b, p0/z, [x0, x2]46 rdffrs p1.b, p0/z47 b.nlast 2f48 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, 053 54 /* Found end-of-string or zero. */558: brkb p2.b, p0/z, p2.b56 mov x0, x257 incp x0, p2.b58 ret59 60 /* First fault failed: only some of the vector is valid.61 Perform the comparison only on the valid bytes. */622: cmpeq p2.b, p1/z, z0.b, 063 b.any 8b64 65 /* No inequality or zero found. Re-init FFR, incr and loop. */66 setffr67 incp x2, p1.b68 b 1b69 70 /* End of count. Return max. */719: mov x0, x272 ret73 74 .size __strnlen_aarch64_sve, . - __strnlen_aarch64_sve75#endif76