Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* memcmp - compare memory
2
3 Copyright (C) 2013-2019 Free Software Foundation, Inc.
4
5 This file is part of the GNU C Library.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library. If not, see
19 <http://www.gnu.org/licenses/>. */
20
21#include <sysdep.h>
22
23/* Assumptions:
24 *
25 * ARMv8-a, AArch64, unaligned accesses.
26 */
27
28/* Parameters and result. */
29#define src1 x0
30#define src2 x1
31#define limit x2
32#define result w0
33
34/* Internal variables. */
35#define data1 x3
36#define data1w w3
37#define data1h x4
38#define data2 x5
39#define data2w w5
40#define data2h x6
41#define tmp1 x7
42#define tmp2 x8
43
44ENTRY_ALIGN (memcmp, 6)
45 DELOUSE (0)
46 DELOUSE (1)
47 DELOUSE (2)
48
49 subs limit, limit, 8
50 b.lo L(less8)
51
52 ldr data1, [src1], 8
53 ldr data2, [src2], 8
54 cmp data1, data2
55 b.ne L(return)
56
57 subs limit, limit, 8
58 b.gt L(more16)
59
60 ldr data1, [src1, limit]
61 ldr data2, [src2, limit]
62 b L(return)
63
64L(more16):
65 ldr data1, [src1], 8
66 ldr data2, [src2], 8
67 cmp data1, data2
68 bne L(return)
69
70 /* Jump directly to comparing the last 16 bytes for 32 byte (or less)
71 strings. */
72 subs limit, limit, 16
73 b.ls L(last_bytes)
74
75 /* We overlap loads between 0-32 bytes at either side of SRC1 when we
76 try to align, so limit it only to strings larger than 128 bytes. */
77 cmp limit, 96
78 b.ls L(loop16)
79
80 /* Align src1 and adjust src2 with bytes not yet done. */
81 and tmp1, src1, 15
82 add limit, limit, tmp1
83 sub src1, src1, tmp1
84 sub src2, src2, tmp1
85
86 /* Loop performing 16 bytes per iteration using aligned src1.
87 Limit is pre-decremented by 16 and must be larger than zero.
88 Exit if <= 16 bytes left to do or if the data is not equal. */
89 .p2align 4
90L(loop16):
91 ldp data1, data1h, [src1], 16
92 ldp data2, data2h, [src2], 16
93 subs limit, limit, 16
94 ccmp data1, data2, 0, hi
95 ccmp data1h, data2h, 0, eq
96 b.eq L(loop16)
97
98 cmp data1, data2
99 bne L(return)
100 mov data1, data1h
101 mov data2, data2h
102 cmp data1, data2
103 bne L(return)
104
105 /* Compare last 1-16 bytes using unaligned access. */
106L(last_bytes):
107 add src1, src1, limit
108 add src2, src2, limit
109 ldp data1, data1h, [src1]
110 ldp data2, data2h, [src2]
111 cmp data1, data2
112 bne L(return)
113 mov data1, data1h
114 mov data2, data2h
115 cmp data1, data2
116
117 /* Compare data bytes and set return value to 0, -1 or 1. */
118L(return):
119#ifndef __AARCH64EB__
120 rev data1, data1
121 rev data2, data2
122#endif
123 cmp data1, data2
124L(ret_eq):
125 cset result, ne
126 cneg result, result, lo
127 ret
128
129 .p2align 4
130 /* Compare up to 8 bytes. Limit is [-8..-1]. */
131L(less8):
132 adds limit, limit, 4
133 b.lo L(less4)
134 ldr data1w, [src1], 4
135 ldr data2w, [src2], 4
136 cmp data1w, data2w
137 b.ne L(return)
138 sub limit, limit, 4
139L(less4):
140 adds limit, limit, 4
141 beq L(ret_eq)
142L(byte_loop):
143 ldrb data1w, [src1], 1
144 ldrb data2w, [src2], 1
145 subs limit, limit, 1
146 ccmp data1w, data2w, 0, ne /* NZCV = 0b0000. */
147 b.eq L(byte_loop)
148 sub result, data1w, data2w
149 ret
150
151END (memcmp)
152#undef bcmp
153weak_alias (memcmp, bcmp)
154libc_hidden_builtin_def (memcmp)
155

Warning: That file was not part of the compilation database. It may have many parsing errors.