1 /* memcmp - compare memory
3 Copyright (C) 2013-2017 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
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.
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.
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/>. */
25 * ARMv8-a, AArch64, unaligned accesses.
28 /* Parameters and result. */
34 /* Internal variables. */
41 ENTRY_ALIGN (memcmp, 6)
49 /* Limit >= 8, so check first 8 bytes using unaligned loads. */
53 add limit, limit, tmp1
57 /* Align src1 and adjust src2 with bytes not yet done. */
64 /* Loop performing 8 bytes per iteration using aligned src1.
65 Limit is pre-decremented by 8 and must be larger than zero.
66 Exit if <= 8 bytes left to do or if the data is not equal. */
72 ccmp data1, data2, 0, hi /* NZCV = 0b0000. */
78 /* Compare last 1-8 bytes using unaligned access. */
80 ldr data1, [src1, limit]
81 ldr data2, [src2, limit]
83 /* Compare data bytes and set return value to 0, -1 or 1. */
92 cneg result, result, lo
96 /* Compare up to 8 bytes. Limit is [-8..-1]. */
100 ldr data1w, [src1], 4
101 ldr data2w, [src2], 4
109 ldrb data1w, [src1], 1
110 ldrb data2w, [src2], 1
112 ccmp data1w, data2w, 0, ne /* NZCV = 0b0000. */
114 sub result, data1w, data2w
119 weak_alias (memcmp, bcmp)
120 libc_hidden_builtin_def (memcmp)