Path: blob/main/contrib/arm-optimized-routines/string/aarch64/experimental/strcpy-sve.S
39507 views
/*1* strcpy/stpcpy - copy a string returning pointer to start/end.2*3* Copyright (c) 2018-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*/1617/* To build as stpcpy, define BUILD_STPCPY before compiling this file. */18#ifdef BUILD_STPCPY19#define FUNC __stpcpy_aarch64_sve20#else21#define FUNC __strcpy_aarch64_sve22#endif2324ENTRY (FUNC)25setffr /* initialize FFR */26ptrue p2.b, all /* all ones; loop invariant */27mov x2, 0 /* initialize offset */2829.p2align 430/* Read a vector's worth of bytes, stopping on first fault. */310: ldff1b z0.b, p2/z, [x1, x2]32rdffrs p0.b, p2/z33b.nlast 1f3435/* First fault did not fail: the whole vector is valid.36Avoid depending on the contexts of FFR beyond the branch. */37cmpeq p1.b, p2/z, z0.b, 0 /* search for zeros */38b.any 2f3940/* No zero found. Store the whole vector and loop. */41st1b z0.b, p2, [x0, x2]42incb x2, all43b 0b4445/* First fault failed: only some of the vector is valid.46Perform the comparison only on the valid bytes. */471: cmpeq p1.b, p0/z, z0.b, 0 /* search for zeros */48b.any 2f4950/* No zero found. Store the valid portion of the vector and loop. */51setffr /* re-init FFR */52st1b z0.b, p0, [x0, x2]53incp x2, p0.b54b 0b5556/* Zero found. Crop the vector to the found zero and finish. */572: brka p0.b, p2/z, p1.b58st1b z0.b, p0, [x0, x2]59#ifdef BUILD_STPCPY60add x0, x0, x261sub x0, x0, 162incp x0, p0.b63#endif64ret6566END (FUNC)676869