1bbbf1280Sopenharmony_ci/*
2bbbf1280Sopenharmony_ci * memcmp - compare memory
3bbbf1280Sopenharmony_ci *
4bbbf1280Sopenharmony_ci * Copyright (c) 2018-2021, Arm Limited.
5bbbf1280Sopenharmony_ci * SPDX-License-Identifier: MIT
6bbbf1280Sopenharmony_ci */
7bbbf1280Sopenharmony_ci
8bbbf1280Sopenharmony_ci#include "../asmdefs.h"
9bbbf1280Sopenharmony_ci
10bbbf1280Sopenharmony_ci#if __ARM_FEATURE_SVE
11bbbf1280Sopenharmony_ci/* Assumptions:
12bbbf1280Sopenharmony_ci *
13bbbf1280Sopenharmony_ci * ARMv8-a, AArch64
14bbbf1280Sopenharmony_ci * SVE Available.
15bbbf1280Sopenharmony_ci */
16bbbf1280Sopenharmony_ci
17bbbf1280Sopenharmony_ciENTRY (__memcmp_aarch64_sve)
18bbbf1280Sopenharmony_ci	PTR_ARG (0)
19bbbf1280Sopenharmony_ci	PTR_ARG (1)
20bbbf1280Sopenharmony_ci	SIZE_ARG (2)
21bbbf1280Sopenharmony_ci	mov	x3, 0			/* initialize off */
22bbbf1280Sopenharmony_ci
23bbbf1280Sopenharmony_ci0:	whilelo	p0.b, x3, x2		/* while off < max */
24bbbf1280Sopenharmony_ci	b.none	9f
25bbbf1280Sopenharmony_ci
26bbbf1280Sopenharmony_ci	ld1b	z0.b, p0/z, [x0, x3]	/* read vectors bounded by max.  */
27bbbf1280Sopenharmony_ci	ld1b	z1.b, p0/z, [x1, x3]
28bbbf1280Sopenharmony_ci
29bbbf1280Sopenharmony_ci	/* Increment for a whole vector, even if we've only read a partial.
30bbbf1280Sopenharmony_ci	   This is significantly cheaper than INCP, and since OFF is not
31bbbf1280Sopenharmony_ci	   used after the loop it is ok to increment OFF past MAX.  */
32bbbf1280Sopenharmony_ci	incb	x3
33bbbf1280Sopenharmony_ci
34bbbf1280Sopenharmony_ci	cmpne	p1.b, p0/z, z0.b, z1.b	/* while no inequalities */
35bbbf1280Sopenharmony_ci	b.none	0b
36bbbf1280Sopenharmony_ci
37bbbf1280Sopenharmony_ci	/* Found inequality.  */
38bbbf1280Sopenharmony_ci1:	brkb	p1.b, p0/z, p1.b	/* find first such */
39bbbf1280Sopenharmony_ci	lasta	w0, p1, z0.b		/* extract each byte */
40bbbf1280Sopenharmony_ci	lasta	w1, p1, z1.b
41bbbf1280Sopenharmony_ci	sub	x0, x0, x1		/* return comparison */
42bbbf1280Sopenharmony_ci	ret
43bbbf1280Sopenharmony_ci
44bbbf1280Sopenharmony_ci	/* Found end-of-count.  */
45bbbf1280Sopenharmony_ci9:	mov	x0, 0			/* return equality */
46bbbf1280Sopenharmony_ci	ret
47bbbf1280Sopenharmony_ci
48bbbf1280Sopenharmony_ciEND (__memcmp_aarch64_sve)
49bbbf1280Sopenharmony_ci
50bbbf1280Sopenharmony_ci#endif
51bbbf1280Sopenharmony_ci
52