131914882SAlex Richardson/* 231914882SAlex Richardson * __strlen_aarch64_sve - compute the length of a string 331914882SAlex Richardson * 4*072a4ba8SAndrew Turner * Copyright (c) 2018-2022, Arm Limited. 5*072a4ba8SAndrew Turner * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 631914882SAlex Richardson */ 731914882SAlex Richardson 8*072a4ba8SAndrew Turner#include "asmdefs.h" 931914882SAlex Richardson 1031914882SAlex Richardson#if __ARM_FEATURE_SVE 1131914882SAlex Richardson/* Assumptions: 1231914882SAlex Richardson * 1331914882SAlex Richardson * ARMv8-a, AArch64 1431914882SAlex Richardson * SVE Available. 1531914882SAlex Richardson */ 1631914882SAlex Richardson 1731914882SAlex RichardsonENTRY (__strlen_aarch64_sve) 1831914882SAlex Richardson PTR_ARG (0) 1931914882SAlex Richardson setffr /* initialize FFR */ 2031914882SAlex Richardson ptrue p2.b /* all ones; loop invariant */ 2131914882SAlex Richardson mov x1, 0 /* initialize length */ 2231914882SAlex Richardson 2331914882SAlex Richardson /* Read a vector's worth of bytes, stopping on first fault. */ 2431914882SAlex Richardson .p2align 4 2531914882SAlex Richardson0: ldff1b z0.b, p2/z, [x0, x1] 2631914882SAlex Richardson rdffrs p0.b, p2/z 2731914882SAlex Richardson b.nlast 2f 2831914882SAlex Richardson 2931914882SAlex Richardson /* First fault did not fail: the whole vector is valid. 3031914882SAlex Richardson Avoid depending on the contents of FFR beyond the branch. */ 3131914882SAlex Richardson incb x1, all /* speculate increment */ 3231914882SAlex Richardson cmpeq p1.b, p2/z, z0.b, 0 /* loop if no zeros */ 3331914882SAlex Richardson b.none 0b 3431914882SAlex Richardson decb x1, all /* undo speculate */ 3531914882SAlex Richardson 3631914882SAlex Richardson /* Zero found. Select the bytes before the first and count them. */ 3731914882SAlex Richardson1: brkb p0.b, p2/z, p1.b 3831914882SAlex Richardson incp x1, p0.b 3931914882SAlex Richardson mov x0, x1 4031914882SAlex Richardson ret 4131914882SAlex Richardson 4231914882SAlex Richardson /* First fault failed: only some of the vector is valid. 4331914882SAlex Richardson Perform the comparison only on the valid bytes. */ 4431914882SAlex Richardson2: cmpeq p1.b, p0/z, z0.b, 0 4531914882SAlex Richardson b.any 1b 4631914882SAlex Richardson 4731914882SAlex Richardson /* No zero found. Re-init FFR, increment, and loop. */ 4831914882SAlex Richardson setffr 4931914882SAlex Richardson incp x1, p0.b 5031914882SAlex Richardson b 0b 5131914882SAlex Richardson 5231914882SAlex RichardsonEND (__strlen_aarch64_sve) 5331914882SAlex Richardson 5431914882SAlex Richardson#endif 5531914882SAlex Richardson 56