61 lines · plain
1/*2 * __strcmp_aarch64_sve - compare two strings3 *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 __strcmp_aarch64_sve20 .type __strcmp_aarch64_sve, %function21 .p2align 422__strcmp_aarch64_sve:23 setffr /* initialize FFR */24 ptrue p1.b, all /* all ones; loop invariant */25 mov x2, 0 /* initialize offset */26 nop27 28 /* Read a vector's worth of bytes, stopping on first fault. */290: ldff1b z0.b, p1/z, [x0, x2]30 ldff1b z1.b, p1/z, [x1, x2]31 rdffrs p0.b, p1/z32 b.nlast 2f33 34 /* First fault did not fail: the whole vector is valid.35 Avoid depending on the contents of FFR beyond the branch. */36 incb x2, all /* skip bytes for next round */37 cmpeq p2.b, p1/z, z0.b, z1.b /* compare strings */38 cmpne p3.b, p1/z, z0.b, 0 /* search for ~zero */39 nands p2.b, p1/z, p2.b, p3.b /* ~(eq & ~zero) -> ne | zero */40 b.none 0b41 42 /* Found end-of-string or inequality. */431: brkb p2.b, p1/z, p2.b /* find first such */44 lasta w0, p2, z0.b /* extract each char */45 lasta w1, p2, z1.b46 sub x0, x0, x1 /* return comparison */47 ret48 49 /* First fault failed: only some of the vector is valid.50 Perform the comparison only on the valid bytes. */512: incp x2, p0.b /* skip bytes for next round */52 setffr /* re-init FFR for next round */53 cmpeq p2.b, p0/z, z0.b, z1.b /* compare strings, as above */54 cmpne p3.b, p0/z, z0.b, 055 nands p2.b, p0/z, p2.b, p3.b56 b.none 0b57 b 1b58 59 .size __strcmp_aarch64_sve, . - __strcmp_aarch64_sve60#endif61