2013-01-16 12:58:40 +00:00
|
|
|
/* memcmp - compare memory
|
|
|
|
|
2024-01-01 18:12:26 +00:00
|
|
|
Copyright (C) 2013-2024 Free Software Foundation, Inc.
|
2013-01-16 12:58:40 +00:00
|
|
|
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library. If not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2013-01-16 12:58:40 +00:00
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
|
|
|
|
/* Assumptions:
|
|
|
|
*
|
2021-12-02 18:30:55 +00:00
|
|
|
* ARMv8-a, AArch64, Advanced SIMD, unaligned accesses.
|
2013-01-16 12:58:40 +00:00
|
|
|
*/
|
|
|
|
|
2021-12-02 18:30:55 +00:00
|
|
|
#define src1 x0
|
|
|
|
#define src2 x1
|
|
|
|
#define limit x2
|
|
|
|
#define result w0
|
|
|
|
|
|
|
|
#define data1 x3
|
|
|
|
#define data1w w3
|
|
|
|
#define data2 x4
|
|
|
|
#define data2w w4
|
|
|
|
#define data3 x5
|
|
|
|
#define data3w w5
|
|
|
|
#define data4 x6
|
|
|
|
#define data4w w6
|
|
|
|
#define tmp x6
|
|
|
|
#define src1end x7
|
|
|
|
#define src2end x8
|
|
|
|
|
|
|
|
|
|
|
|
ENTRY (memcmp)
|
2020-12-17 10:03:05 +00:00
|
|
|
PTR_ARG (0)
|
|
|
|
PTR_ARG (1)
|
|
|
|
SIZE_ARG (2)
|
2013-01-16 12:58:40 +00:00
|
|
|
|
2021-12-02 18:30:55 +00:00
|
|
|
cmp limit, 16
|
2019-12-19 12:31:59 +00:00
|
|
|
b.lo L(less16)
|
2021-12-02 18:30:55 +00:00
|
|
|
ldp data1, data3, [src1]
|
|
|
|
ldp data2, data4, [src2]
|
2019-12-19 12:31:59 +00:00
|
|
|
ccmp data1, data2, 0, ne
|
2021-12-02 18:30:55 +00:00
|
|
|
ccmp data3, data4, 0, eq
|
|
|
|
b.ne L(return2)
|
2017-08-10 16:00:38 +00:00
|
|
|
|
2021-12-02 18:30:55 +00:00
|
|
|
add src1end, src1, limit
|
|
|
|
add src2end, src2, limit
|
|
|
|
cmp limit, 32
|
2018-03-06 13:52:39 +00:00
|
|
|
b.ls L(last_bytes)
|
2021-12-02 18:30:55 +00:00
|
|
|
cmp limit, 160
|
|
|
|
b.hs L(loop_align)
|
|
|
|
sub limit, limit, 32
|
2017-08-10 16:00:38 +00:00
|
|
|
|
|
|
|
.p2align 4
|
2021-12-02 18:30:55 +00:00
|
|
|
L(loop32):
|
|
|
|
ldp data1, data3, [src1, 16]
|
|
|
|
ldp data2, data4, [src2, 16]
|
2018-03-06 13:52:39 +00:00
|
|
|
cmp data1, data2
|
2021-12-02 18:30:55 +00:00
|
|
|
ccmp data3, data4, 0, eq
|
|
|
|
b.ne L(return2)
|
|
|
|
cmp limit, 16
|
|
|
|
b.ls L(last_bytes)
|
2019-12-19 12:31:59 +00:00
|
|
|
|
2021-12-02 18:30:55 +00:00
|
|
|
ldp data1, data3, [src1, 32]
|
|
|
|
ldp data2, data4, [src2, 32]
|
2017-08-10 16:00:38 +00:00
|
|
|
cmp data1, data2
|
2021-12-02 18:30:55 +00:00
|
|
|
ccmp data3, data4, 0, eq
|
|
|
|
b.ne L(return2)
|
|
|
|
add src1, src1, 32
|
|
|
|
add src2, src2, 32
|
|
|
|
L(last64):
|
|
|
|
subs limit, limit, 32
|
|
|
|
b.hi L(loop32)
|
2017-08-10 16:00:38 +00:00
|
|
|
|
2018-03-06 13:52:39 +00:00
|
|
|
/* Compare last 1-16 bytes using unaligned access. */
|
2018-02-02 04:45:20 +00:00
|
|
|
L(last_bytes):
|
2021-12-02 18:30:55 +00:00
|
|
|
ldp data1, data3, [src1end, -16]
|
|
|
|
ldp data2, data4, [src2end, -16]
|
|
|
|
L(return2):
|
|
|
|
cmp data1, data2
|
|
|
|
csel data1, data1, data3, ne
|
|
|
|
csel data2, data2, data4, ne
|
2017-08-10 16:00:38 +00:00
|
|
|
|
|
|
|
/* Compare data bytes and set return value to 0, -1 or 1. */
|
2018-02-02 04:45:20 +00:00
|
|
|
L(return):
|
2017-08-10 16:00:38 +00:00
|
|
|
#ifndef __AARCH64EB__
|
2013-01-16 12:58:40 +00:00
|
|
|
rev data1, data1
|
|
|
|
rev data2, data2
|
|
|
|
#endif
|
2019-12-19 12:31:59 +00:00
|
|
|
cmp data1, data2
|
2017-08-10 16:00:38 +00:00
|
|
|
cset result, ne
|
|
|
|
cneg result, result, lo
|
|
|
|
ret
|
|
|
|
|
|
|
|
.p2align 4
|
2019-12-19 12:31:59 +00:00
|
|
|
L(less16):
|
2021-12-02 18:30:55 +00:00
|
|
|
add src1end, src1, limit
|
|
|
|
add src2end, src2, limit
|
|
|
|
tbz limit, 3, L(less8)
|
2019-12-19 12:31:59 +00:00
|
|
|
ldr data1, [src1]
|
|
|
|
ldr data2, [src2]
|
2021-12-02 18:30:55 +00:00
|
|
|
ldr data3, [src1end, -8]
|
|
|
|
ldr data4, [src2end, -8]
|
|
|
|
b L(return2)
|
2019-12-19 12:31:59 +00:00
|
|
|
|
|
|
|
.p2align 4
|
2018-02-02 04:45:20 +00:00
|
|
|
L(less8):
|
2021-12-02 18:30:55 +00:00
|
|
|
tbz limit, 2, L(less4)
|
2019-12-19 12:31:59 +00:00
|
|
|
ldr data1w, [src1]
|
|
|
|
ldr data2w, [src2]
|
2021-12-02 18:30:55 +00:00
|
|
|
ldr data3w, [src1end, -4]
|
|
|
|
ldr data4w, [src2end, -4]
|
|
|
|
b L(return2)
|
2019-12-19 12:31:59 +00:00
|
|
|
|
2018-02-02 04:45:20 +00:00
|
|
|
L(less4):
|
2021-12-02 18:30:55 +00:00
|
|
|
tbz limit, 1, L(less2)
|
|
|
|
ldrh data1w, [src1]
|
|
|
|
ldrh data2w, [src2]
|
|
|
|
cmp data1w, data2w
|
|
|
|
b.ne L(return)
|
|
|
|
L(less2):
|
|
|
|
mov result, 0
|
|
|
|
tbz limit, 0, L(return_zero)
|
|
|
|
ldrb data1w, [src1end, -1]
|
|
|
|
ldrb data2w, [src2end, -1]
|
2017-08-10 16:00:38 +00:00
|
|
|
sub result, data1w, data2w
|
2021-12-02 18:30:55 +00:00
|
|
|
L(return_zero):
|
2017-08-10 16:00:38 +00:00
|
|
|
ret
|
2021-12-02 18:30:55 +00:00
|
|
|
|
|
|
|
L(loop_align):
|
|
|
|
ldp data1, data3, [src1, 16]
|
|
|
|
ldp data2, data4, [src2, 16]
|
|
|
|
cmp data1, data2
|
|
|
|
ccmp data3, data4, 0, eq
|
|
|
|
b.ne L(return2)
|
|
|
|
|
|
|
|
/* Align src2 and adjust src1, src2 and limit. */
|
|
|
|
and tmp, src2, 15
|
|
|
|
sub tmp, tmp, 16
|
|
|
|
sub src2, src2, tmp
|
|
|
|
add limit, limit, tmp
|
|
|
|
sub src1, src1, tmp
|
|
|
|
sub limit, limit, 64 + 16
|
|
|
|
|
|
|
|
.p2align 4
|
|
|
|
L(loop64):
|
|
|
|
ldr q0, [src1, 16]
|
|
|
|
ldr q1, [src2, 16]
|
|
|
|
subs limit, limit, 64
|
|
|
|
ldr q2, [src1, 32]
|
|
|
|
ldr q3, [src2, 32]
|
|
|
|
eor v0.16b, v0.16b, v1.16b
|
|
|
|
eor v1.16b, v2.16b, v3.16b
|
|
|
|
ldr q2, [src1, 48]
|
|
|
|
ldr q3, [src2, 48]
|
|
|
|
umaxp v0.16b, v0.16b, v1.16b
|
|
|
|
ldr q4, [src1, 64]!
|
|
|
|
ldr q5, [src2, 64]!
|
|
|
|
eor v1.16b, v2.16b, v3.16b
|
|
|
|
eor v2.16b, v4.16b, v5.16b
|
|
|
|
umaxp v1.16b, v1.16b, v2.16b
|
|
|
|
umaxp v0.16b, v0.16b, v1.16b
|
|
|
|
umaxp v0.16b, v0.16b, v0.16b
|
|
|
|
fmov tmp, d0
|
|
|
|
ccmp tmp, 0, 0, hi
|
|
|
|
b.eq L(loop64)
|
|
|
|
|
|
|
|
/* If equal, process last 1-64 bytes using scalar loop. */
|
|
|
|
add limit, limit, 64 + 16
|
|
|
|
cbz tmp, L(last64)
|
|
|
|
|
|
|
|
/* Determine the 8-byte aligned offset of the first difference. */
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev16 tmp, tmp
|
|
|
|
#endif
|
|
|
|
rev tmp, tmp
|
|
|
|
clz tmp, tmp
|
|
|
|
bic tmp, tmp, 7
|
|
|
|
sub tmp, tmp, 48
|
|
|
|
ldr data1, [src1, tmp]
|
|
|
|
ldr data2, [src2, tmp]
|
|
|
|
#ifndef __AARCH64EB__
|
|
|
|
rev data1, data1
|
|
|
|
rev data2, data2
|
|
|
|
#endif
|
|
|
|
mov result, 1
|
|
|
|
cmp data1, data2
|
|
|
|
cneg result, result, lo
|
2019-12-19 12:31:59 +00:00
|
|
|
ret
|
2017-08-10 16:00:38 +00:00
|
|
|
|
2013-01-16 12:58:40 +00:00
|
|
|
END (memcmp)
|
|
|
|
#undef bcmp
|
|
|
|
weak_alias (memcmp, bcmp)
|
2021-10-21 20:54:57 +00:00
|
|
|
#undef __memcmpeq
|
|
|
|
strong_alias (memcmp, __memcmpeq)
|
2013-01-16 12:58:40 +00:00
|
|
|
libc_hidden_builtin_def (memcmp)
|
2021-10-21 20:53:58 +00:00
|
|
|
libc_hidden_def (__memcmpeq)
|