2021-01-03 03:32:25 +08:00
|
|
|
/* Copyright (C) 2012-2021 Free Software Foundation, Inc.
|
2013-01-16 21:29:29 +08: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 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2013-01-16 21:29:29 +08:00
|
|
|
|
|
|
|
/* Assumptions:
|
|
|
|
*
|
2020-06-16 20:42:38 +08:00
|
|
|
* ARMv8-a, AArch64.
|
|
|
|
* MTE compatible.
|
2013-01-16 21:29:29 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
|
|
|
|
#define REP8_01 0x0101010101010101
|
|
|
|
#define REP8_7f 0x7f7f7f7f7f7f7f7f
|
|
|
|
|
|
|
|
/* Parameters and result. */
|
|
|
|
#define src1 x0
|
|
|
|
#define src2 x1
|
|
|
|
#define result x0
|
|
|
|
|
|
|
|
/* Internal variables. */
|
|
|
|
#define data1 x2
|
|
|
|
#define data1w w2
|
|
|
|
#define data2 x3
|
|
|
|
#define data2w w3
|
|
|
|
#define has_nul x4
|
|
|
|
#define diff x5
|
2020-06-16 20:42:38 +08:00
|
|
|
#define off1 x5
|
2013-01-16 21:29:29 +08:00
|
|
|
#define syndrome x6
|
2020-06-16 20:42:38 +08:00
|
|
|
#define tmp x6
|
|
|
|
#define data3 x7
|
|
|
|
#define zeroones x8
|
|
|
|
#define shift x9
|
|
|
|
#define off2 x10
|
|
|
|
|
|
|
|
/* On big-endian early bytes are at MSB and on little-endian LSB.
|
|
|
|
LS_FW means shifting towards early bytes. */
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
# define LS_FW lsl
|
|
|
|
#else
|
|
|
|
# define LS_FW lsr
|
|
|
|
#endif
|
2013-01-16 21:29:29 +08:00
|
|
|
|
2020-06-16 20:42:38 +08:00
|
|
|
/* NUL detection works on the principle that (X - 1) & (~X) & 0x80
|
|
|
|
(=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
|
|
|
|
can be done in parallel across the entire word.
|
|
|
|
Since carry propagation makes 0x1 bytes before a NUL byte appear
|
|
|
|
NUL too in big-endian, byte-reverse the data before the NUL check. */
|
2013-01-16 21:29:29 +08:00
|
|
|
|
2020-06-16 20:42:38 +08:00
|
|
|
ENTRY(strcmp)
|
2020-12-17 18:03:05 +08:00
|
|
|
PTR_ARG (0)
|
|
|
|
PTR_ARG (1)
|
2020-06-16 20:42:38 +08:00
|
|
|
sub off2, src2, src1
|
|
|
|
mov zeroones, REP8_01
|
|
|
|
and tmp, src1, 7
|
|
|
|
tst off2, 7
|
2013-01-16 21:29:29 +08:00
|
|
|
b.ne L(misaligned8)
|
2020-06-16 20:42:38 +08:00
|
|
|
cbnz tmp, L(mutual_align)
|
|
|
|
|
|
|
|
.p2align 4
|
|
|
|
|
2013-01-16 21:29:29 +08:00
|
|
|
L(loop_aligned):
|
2020-06-16 20:42:38 +08:00
|
|
|
ldr data2, [src1, off2]
|
|
|
|
ldr data1, [src1], 8
|
2013-01-16 21:29:29 +08:00
|
|
|
L(start_realigned):
|
2020-06-16 20:42:38 +08:00
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev tmp, data1
|
|
|
|
sub has_nul, tmp, zeroones
|
|
|
|
orr tmp, tmp, REP8_7f
|
|
|
|
#else
|
|
|
|
sub has_nul, data1, zeroones
|
|
|
|
orr tmp, data1, REP8_7f
|
|
|
|
#endif
|
|
|
|
bics has_nul, has_nul, tmp /* Non-zero if NUL terminator. */
|
|
|
|
ccmp data1, data2, 0, eq
|
|
|
|
b.eq L(loop_aligned)
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev has_nul, has_nul
|
|
|
|
#endif
|
|
|
|
eor diff, data1, data2
|
2013-01-16 21:29:29 +08:00
|
|
|
orr syndrome, diff, has_nul
|
2017-12-13 21:20:27 +08:00
|
|
|
L(end):
|
2020-06-16 20:42:38 +08:00
|
|
|
#ifndef __AARCH64EB__
|
2013-01-16 21:29:29 +08:00
|
|
|
rev syndrome, syndrome
|
|
|
|
rev data1, data1
|
|
|
|
rev data2, data2
|
2020-06-16 20:42:38 +08:00
|
|
|
#endif
|
|
|
|
clz shift, syndrome
|
|
|
|
/* The most-significant-non-zero bit of the syndrome marks either the
|
|
|
|
first bit that is different, or the top bit of the first zero byte.
|
2013-01-16 21:29:29 +08:00
|
|
|
Shifting left now will bring the critical information into the
|
|
|
|
top bits. */
|
2020-06-16 20:42:38 +08:00
|
|
|
lsl data1, data1, shift
|
|
|
|
lsl data2, data2, shift
|
2013-01-16 21:29:29 +08:00
|
|
|
/* But we need to zero-extend (char is unsigned) the value and then
|
|
|
|
perform a signed 32-bit subtraction. */
|
2020-06-16 20:42:38 +08:00
|
|
|
lsr data1, data1, 56
|
|
|
|
sub result, data1, data2, lsr 56
|
|
|
|
ret
|
|
|
|
|
|
|
|
.p2align 4
|
2013-01-16 21:29:29 +08:00
|
|
|
|
|
|
|
L(mutual_align):
|
|
|
|
/* Sources are mutually aligned, but are not currently at an
|
|
|
|
alignment boundary. Round down the addresses and then mask off
|
2020-06-16 20:42:38 +08:00
|
|
|
the bytes that precede the start point. */
|
|
|
|
bic src1, src1, 7
|
|
|
|
ldr data2, [src1, off2]
|
|
|
|
ldr data1, [src1], 8
|
|
|
|
neg shift, src2, lsl 3 /* Bits to alignment -64. */
|
|
|
|
mov tmp, -1
|
|
|
|
LS_FW tmp, tmp, shift
|
|
|
|
orr data1, data1, tmp
|
|
|
|
orr data2, data2, tmp
|
2013-01-16 21:29:29 +08:00
|
|
|
b L(start_realigned)
|
|
|
|
|
|
|
|
L(misaligned8):
|
2017-12-13 21:20:27 +08:00
|
|
|
/* Align SRC1 to 8 bytes and then compare 8 bytes at a time, always
|
2020-06-16 20:42:38 +08:00
|
|
|
checking to make sure that we don't access beyond the end of SRC2. */
|
|
|
|
cbz tmp, L(src1_aligned)
|
2017-12-13 21:20:27 +08:00
|
|
|
L(do_misaligned):
|
2020-06-16 20:42:38 +08:00
|
|
|
ldrb data1w, [src1], 1
|
|
|
|
ldrb data2w, [src2], 1
|
|
|
|
cmp data1w, 0
|
|
|
|
ccmp data1w, data2w, 0, ne /* NZCV = 0b0000. */
|
2017-12-13 21:20:27 +08:00
|
|
|
b.ne L(done)
|
2020-06-16 20:42:38 +08:00
|
|
|
tst src1, 7
|
2018-02-23 02:18:13 +08:00
|
|
|
b.ne L(do_misaligned)
|
2017-12-13 21:20:27 +08:00
|
|
|
|
2020-06-16 20:42:38 +08:00
|
|
|
L(src1_aligned):
|
|
|
|
neg shift, src2, lsl 3
|
|
|
|
bic src2, src2, 7
|
|
|
|
ldr data3, [src2], 8
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev data3, data3
|
|
|
|
#endif
|
|
|
|
lsr tmp, zeroones, shift
|
|
|
|
orr data3, data3, tmp
|
|
|
|
sub has_nul, data3, zeroones
|
|
|
|
orr tmp, data3, REP8_7f
|
|
|
|
bics has_nul, has_nul, tmp
|
|
|
|
b.ne L(tail)
|
|
|
|
|
|
|
|
sub off1, src2, src1
|
|
|
|
|
|
|
|
.p2align 4
|
|
|
|
|
|
|
|
L(loop_unaligned):
|
|
|
|
ldr data3, [src1, off1]
|
|
|
|
ldr data2, [src1, off2]
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev data3, data3
|
|
|
|
#endif
|
|
|
|
sub has_nul, data3, zeroones
|
|
|
|
orr tmp, data3, REP8_7f
|
|
|
|
ldr data1, [src1], 8
|
|
|
|
bics has_nul, has_nul, tmp
|
|
|
|
ccmp data1, data2, 0, eq
|
|
|
|
b.eq L(loop_unaligned)
|
|
|
|
|
|
|
|
lsl tmp, has_nul, shift
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev tmp, tmp
|
|
|
|
#endif
|
|
|
|
eor diff, data1, data2
|
|
|
|
orr syndrome, diff, tmp
|
|
|
|
cbnz syndrome, L(end)
|
|
|
|
L(tail):
|
|
|
|
ldr data1, [src1]
|
|
|
|
neg shift, shift
|
|
|
|
lsr data2, data3, shift
|
|
|
|
lsr has_nul, has_nul, shift
|
|
|
|
#ifdef __AARCH64EB__
|
|
|
|
rev data2, data2
|
|
|
|
rev has_nul, has_nul
|
|
|
|
#endif
|
|
|
|
eor diff, data1, data2
|
2017-12-13 21:20:27 +08:00
|
|
|
orr syndrome, diff, has_nul
|
|
|
|
b L(end)
|
|
|
|
|
|
|
|
L(done):
|
2013-01-16 21:29:29 +08:00
|
|
|
sub result, data1, data2
|
2020-06-16 20:42:38 +08:00
|
|
|
ret
|
|
|
|
|
2013-01-16 21:29:29 +08:00
|
|
|
END(strcmp)
|
|
|
|
libc_hidden_builtin_def (strcmp)
|