Path: blob/main/contrib/arm-optimized-routines/string/aarch64/experimental/strcmp-sve.S
39507 views
/*1* __strcmp_aarch64_sve - compare two strings2*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*/1617ENTRY (__strcmp_aarch64_sve)18setffr /* initialize FFR */19ptrue p1.b, all /* all ones; loop invariant */20mov x2, 0 /* initialize offset */2122/* Read a vector's worth of bytes, stopping on first fault. */23.p2align 4240: ldff1b z0.b, p1/z, [x0, x2]25ldff1b z1.b, p1/z, [x1, x2]26rdffrs p0.b, p1/z27b.nlast 2f2829/* First fault did not fail: the whole vector is valid.30Avoid depending on the contents of FFR beyond the branch. */31incb x2, all /* skip bytes for next round */32cmpeq p2.b, p1/z, z0.b, z1.b /* compare strings */33cmpne p3.b, p1/z, z0.b, 0 /* search for ~zero */34nands p2.b, p1/z, p2.b, p3.b /* ~(eq & ~zero) -> ne | zero */35b.none 0b3637/* Found end-of-string or inequality. */381: brkb p2.b, p1/z, p2.b /* find first such */39lasta w0, p2, z0.b /* extract each char */40lasta w1, p2, z1.b41sub x0, x0, x1 /* return comparison */42ret4344/* First fault failed: only some of the vector is valid.45Perform the comparison only on the valid bytes. */462: incp x2, p0.b /* skip bytes for next round */47setffr /* re-init FFR for next round */48cmpeq p2.b, p0/z, z0.b, z1.b /* compare strings, as above */49cmpne p3.b, p0/z, z0.b, 050nands p2.b, p0/z, p2.b, p3.b51b.none 0b52b 1b5354END (__strcmp_aarch64_sve)555657