1 /* memcmp - compare memory
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 * ARMv8-a, AArch64, unaligned accesses.
13 #include "../asmdefs.h"
15 /* Parameters and result. */
21 /* Internal variables. */
31 ENTRY (__memcmp_aarch64)
43 ldr data1, [src1, limit]
44 ldr data2, [src2, limit]
53 /* Jump directly to comparing the last 16 bytes for 32 byte (or less)
58 /* We overlap loads between 0-32 bytes at either side of SRC1 when we
59 try to align, so limit it only to strings larger than 128 bytes. */
63 /* Align src1 and adjust src2 with bytes not yet done. */
65 add limit, limit, tmp1
69 /* Loop performing 16 bytes per iteration using aligned src1.
70 Limit is pre-decremented by 16 and must be larger than zero.
71 Exit if <= 16 bytes left to do or if the data is not equal. */
74 ldp data1, data1h, [src1], 16
75 ldp data2, data2h, [src2], 16
77 ccmp data1, data2, 0, hi
78 ccmp data1h, data2h, 0, eq
88 /* Compare last 1-16 bytes using unaligned access. */
92 ldp data1, data1h, [src1]
93 ldp data2, data2h, [src2]
100 /* Compare data bytes and set return value to 0, -1 or 1. */
102 #ifndef __AARCH64EB__
109 cneg result, result, lo
113 /* Compare up to 8 bytes. Limit is [-8..-1]. */
117 ldr data1w, [src1], 4
118 ldr data2w, [src2], 4
126 ldrb data1w, [src1], 1
127 ldrb data2w, [src2], 1
129 ccmp data1w, data2w, 0, ne /* NZCV = 0b0000. */
131 sub result, data1w, data2w
134 END (__memcmp_aarch64)