brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · f5d4f95 Raw
70 lines · plain
1/*2 * strncmp - compare two strings with limit3 *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	__strncmp_aarch64_sve20	.type	__strncmp_aarch64_sve, %function21	.p2align 422__strncmp_aarch64_sve:23	setffr				/* initialize FFR */24	mov	x3, 0			/* initialize off */25 260:	whilelo	p0.b, x3, x2		/* while off < max */27	b.none	9f28 29	ldff1b	z0.b, p0/z, [x0, x3]30	ldff1b	z1.b, p0/z, [x1, x3]31	rdffrs	p1.b, p0/z32	b.nlast	2f33 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 not38	   used after the loop it is ok to increment OFF past MAX.  */39	incb	x340	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 */43	b.none	0b44 45	/* Found end-of-string or inequality.  */461:	brkb	p2.b, p0/z, p2.b	/* find first such */47	lasta	w0, p2, z0.b		/* extract each char */48	lasta	w1, p2, z1.b49	sub	x0, x0, x1		/* return comparison */50	ret51 52	/* First fault failed: only some of the vector is valid.53	   Perform the comparison only on the valid bytes.  */542:	cmpeq	p2.b, p1/z, z0.b, z1.b	/* compare strings, as above */55	cmpne	p3.b, p1/z, z0.b, 056	nands	p2.b, p1/z, p2.b, p3.b57	b.any	1b58 59	/* No inequality or zero found.  Re-init FFR, incr and loop.  */60	setffr61	incp	x3, p1.b62	b	0b63 64	/* Found end-of-count.  */659:	mov	x0, 0			/* return equal */66	ret67 68	.size	__strncmp_aarch64_sve, . - __strncmp_aarch64_sve69#endif70