2 * strncmp - compare two strings with limit
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-exception
19 .globl __strncmp_aarch64_sve
20 .type __strncmp_aarch64_sve, %function
22 __strncmp_aarch64_sve:
23 setffr /* initialize FFR */
24 mov x3, 0 /* initialize off */
26 0: whilelo p0.b, x3, x2 /* while off < max */
29 ldff1b z0.b, p0/z, [x0, x3]
30 ldff1b z1.b, p0/z, [x1, x3]
34 /* First fault did not fail: the vector up to max is valid.
35 Avoid depending on the contents of FFR beyond the branch.
36 Increment for a whole vector, even if we've only read a partial.
37 This is significantly cheaper than INCP, and since OFF is not
38 used after the loop it is ok to increment OFF past MAX. */
40 cmpeq p1.b, p0/z, z0.b, z1.b /* compare strings */
41 cmpne p2.b, p0/z, z0.b, 0 /* search for ~zero */
42 nands p2.b, p0/z, p1.b, p2.b /* ~(eq & ~zero) -> ne | zero */
45 /* Found end-of-string or inequality. */
46 1: brkb p2.b, p0/z, p2.b /* find first such */
47 lasta w0, p2, z0.b /* extract each char */
49 sub x0, x0, x1 /* return comparison */
52 /* First fault failed: only some of the vector is valid.
53 Perform the comparison only on the valid bytes. */
54 2: cmpeq p2.b, p1/z, z0.b, z1.b /* compare strings, as above */
55 cmpne p3.b, p1/z, z0.b, 0
56 nands p2.b, p1/z, p2.b, p3.b
59 /* No inequality or zero found. Re-init FFR, incr and loop. */
64 /* Found end-of-count. */
65 9: mov x0, 0 /* return equal */
68 .size __strncmp_aarch64_sve, . - __strncmp_aarch64_sve