2009-07-16 14:00:34 +00:00
|
|
|
/* memcmp with SSE2
|
2021-01-02 19:32:25 +00:00
|
|
|
Copyright (C) 2009-2021 Free Software Foundation, Inc.
|
2009-07-16 14:00:34 +00:00
|
|
|
Contributed by Intel Corporation.
|
|
|
|
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
|
2012-02-09 23:18:22 +00:00
|
|
|
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/>. */
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
|
|
|
|
.text
|
|
|
|
ENTRY (memcmp)
|
2019-02-04 14:31:01 +00:00
|
|
|
#ifdef __ILP32__
|
|
|
|
/* Clear the upper 32 bits. */
|
|
|
|
movl %edx, %edx
|
|
|
|
#endif
|
|
|
|
test %RDX_LP, %RDX_LP
|
2009-07-16 14:00:34 +00:00
|
|
|
jz L(finz)
|
|
|
|
cmpq $1, %rdx
|
2019-02-04 14:31:01 +00:00
|
|
|
jbe L(finr1b)
|
2009-07-16 14:02:27 +00:00
|
|
|
subq %rdi, %rsi
|
2009-07-16 14:00:34 +00:00
|
|
|
movq %rdx, %r10
|
|
|
|
cmpq $32, %r10
|
2019-02-04 14:31:01 +00:00
|
|
|
jae L(gt32)
|
2009-07-16 14:00:34 +00:00
|
|
|
/* Handle small chunks and last block of less than 32 bytes. */
|
|
|
|
L(small):
|
|
|
|
testq $1, %r10
|
|
|
|
jz L(s2b)
|
|
|
|
movzbl (%rdi), %eax
|
|
|
|
movzbl (%rdi, %rsi), %edx
|
|
|
|
subq $1, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
je L(finz1)
|
2009-07-16 14:00:34 +00:00
|
|
|
addq $1, %rdi
|
|
|
|
subl %edx, %eax
|
|
|
|
jnz L(exit)
|
|
|
|
L(s2b):
|
|
|
|
testq $2, %r10
|
|
|
|
jz L(s4b)
|
|
|
|
movzwl (%rdi), %eax
|
|
|
|
movzwl (%rdi, %rsi), %edx
|
|
|
|
subq $2, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
je L(fin2_7)
|
2009-07-16 14:00:34 +00:00
|
|
|
addq $2, %rdi
|
|
|
|
cmpl %edx, %eax
|
|
|
|
jnz L(fin2_7)
|
|
|
|
L(s4b):
|
|
|
|
testq $4, %r10
|
|
|
|
jz L(s8b)
|
|
|
|
movl (%rdi), %eax
|
|
|
|
movl (%rdi, %rsi), %edx
|
|
|
|
subq $4, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
je L(fin2_7)
|
2009-07-16 14:00:34 +00:00
|
|
|
addq $4, %rdi
|
|
|
|
cmpl %edx, %eax
|
|
|
|
jnz L(fin2_7)
|
|
|
|
L(s8b):
|
|
|
|
testq $8, %r10
|
|
|
|
jz L(s16b)
|
|
|
|
movq (%rdi), %rax
|
|
|
|
movq (%rdi, %rsi), %rdx
|
|
|
|
subq $8, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
je L(fin2_7)
|
2009-07-16 14:00:34 +00:00
|
|
|
addq $8, %rdi
|
|
|
|
cmpq %rdx, %rax
|
|
|
|
jnz L(fin2_7)
|
|
|
|
L(s16b):
|
|
|
|
movdqu (%rdi), %xmm1
|
|
|
|
movdqu (%rdi, %rsi), %xmm0
|
|
|
|
pcmpeqb %xmm0, %xmm1
|
|
|
|
pmovmskb %xmm1, %edx
|
2009-07-16 14:02:27 +00:00
|
|
|
xorl %eax, %eax
|
2009-07-16 14:00:34 +00:00
|
|
|
subl $0xffff, %edx
|
|
|
|
jz L(finz)
|
2009-07-16 14:02:27 +00:00
|
|
|
bsfl %edx, %ecx
|
|
|
|
leaq (%rdi, %rcx), %rcx
|
2009-07-16 14:00:34 +00:00
|
|
|
movzbl (%rcx), %eax
|
|
|
|
movzbl (%rsi, %rcx), %edx
|
|
|
|
jmp L(finz1)
|
|
|
|
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(finr1b):
|
|
|
|
movzbl (%rdi), %eax
|
2009-07-16 14:02:27 +00:00
|
|
|
movzbl (%rsi), %edx
|
2009-07-16 14:00:34 +00:00
|
|
|
L(finz1):
|
|
|
|
subl %edx, %eax
|
|
|
|
L(exit):
|
|
|
|
ret
|
|
|
|
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(fin2_7):
|
|
|
|
cmpq %rdx, %rax
|
|
|
|
jz L(finz)
|
2009-07-16 14:02:27 +00:00
|
|
|
movq %rax, %r11
|
|
|
|
subq %rdx, %r11
|
2009-07-16 14:00:34 +00:00
|
|
|
bsfq %r11, %rcx
|
2009-07-16 14:02:27 +00:00
|
|
|
sarq $3, %rcx
|
2009-07-16 14:00:34 +00:00
|
|
|
salq $3, %rcx
|
2009-07-16 14:02:27 +00:00
|
|
|
sarq %cl, %rax
|
2009-07-16 14:00:34 +00:00
|
|
|
movzbl %al, %eax
|
2009-07-16 14:02:27 +00:00
|
|
|
sarq %cl, %rdx
|
2009-07-16 14:00:34 +00:00
|
|
|
movzbl %dl, %edx
|
|
|
|
subl %edx, %eax
|
2009-07-16 14:02:27 +00:00
|
|
|
ret
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(finz):
|
|
|
|
xorl %eax, %eax
|
|
|
|
ret
|
|
|
|
|
2009-07-16 14:02:27 +00:00
|
|
|
/* For blocks bigger than 32 bytes
|
2009-07-16 14:00:34 +00:00
|
|
|
1. Advance one of the addr pointer to be 16B aligned.
|
|
|
|
2. Treat the case of both addr pointers aligned to 16B
|
|
|
|
separately to avoid movdqu.
|
|
|
|
3. Handle any blocks of greater than 64 consecutive bytes with
|
|
|
|
unrolling to reduce branches.
|
|
|
|
4. At least one addr pointer is 16B aligned, use memory version
|
|
|
|
of pcmbeqb.
|
|
|
|
*/
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(gt32):
|
|
|
|
movq %rdx, %r11
|
|
|
|
addq %rdi, %r11
|
2009-07-16 14:02:27 +00:00
|
|
|
movq %rdi, %r8
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
andq $15, %r8
|
2009-07-16 14:02:27 +00:00
|
|
|
jz L(16am)
|
2009-07-16 14:00:34 +00:00
|
|
|
/* Both pointers may be misaligned. */
|
|
|
|
movdqu (%rdi), %xmm1
|
|
|
|
movdqu (%rdi, %rsi), %xmm0
|
|
|
|
pcmpeqb %xmm0, %xmm1
|
|
|
|
pmovmskb %xmm1, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
neg %r8
|
|
|
|
leaq 16(%rdi, %r8), %rdi
|
|
|
|
L(16am):
|
|
|
|
/* Handle two 16B aligned pointers separately. */
|
|
|
|
testq $15, %rsi
|
|
|
|
jz L(ATR)
|
|
|
|
testq $16, %rdi
|
|
|
|
jz L(A32)
|
|
|
|
movdqu (%rdi, %rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
L(A32):
|
|
|
|
movq %r11, %r10
|
|
|
|
andq $-32, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
cmpq %r10, %rdi
|
2019-02-04 14:31:01 +00:00
|
|
|
jae L(mt16)
|
2009-07-16 14:00:34 +00:00
|
|
|
/* Pre-unroll to be ready for unrolled 64B loop. */
|
|
|
|
testq $32, %rdi
|
|
|
|
jz L(A64)
|
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
2009-07-16 14:02:27 +00:00
|
|
|
|
2009-07-16 14:00:34 +00:00
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
L(A64):
|
|
|
|
movq %r11, %r10
|
|
|
|
andq $-64, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
cmpq %r10, %rdi
|
2019-02-04 14:31:01 +00:00
|
|
|
jae L(mt32)
|
2009-07-16 14:02:27 +00:00
|
|
|
|
2009-07-16 14:00:34 +00:00
|
|
|
L(A64main):
|
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
2009-07-16 14:02:27 +00:00
|
|
|
|
2009-07-16 14:00:34 +00:00
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
cmpq %rdi, %r10
|
|
|
|
jne L(A64main)
|
|
|
|
|
|
|
|
L(mt32):
|
|
|
|
movq %r11, %r10
|
|
|
|
andq $-32, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
cmpq %r10, %rdi
|
2019-02-04 14:31:01 +00:00
|
|
|
jae L(mt16)
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
L(A32main):
|
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
2009-07-16 14:02:27 +00:00
|
|
|
|
2009-07-16 14:00:34 +00:00
|
|
|
movdqu (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
cmpq %rdi, %r10
|
|
|
|
jne L(A32main)
|
|
|
|
L(mt16):
|
|
|
|
subq %rdi, %r11
|
|
|
|
je L(finz)
|
2009-07-16 14:02:27 +00:00
|
|
|
movq %r11, %r10
|
|
|
|
jmp L(small)
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(neq):
|
2009-07-16 14:02:27 +00:00
|
|
|
bsfl %edx, %ecx
|
2009-07-16 14:00:34 +00:00
|
|
|
movzbl (%rdi, %rcx), %eax
|
2009-07-16 14:02:27 +00:00
|
|
|
addq %rdi, %rsi
|
2009-07-16 14:00:34 +00:00
|
|
|
movzbl (%rsi,%rcx), %edx
|
|
|
|
jmp L(finz1)
|
|
|
|
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(ATR):
|
|
|
|
movq %r11, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
andq $-32, %r10
|
|
|
|
cmpq %r10, %rdi
|
2019-02-04 14:31:01 +00:00
|
|
|
jae L(mt16)
|
2009-07-16 14:00:34 +00:00
|
|
|
testq $16, %rdi
|
|
|
|
jz L(ATR32)
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
cmpq %rdi, %r10
|
|
|
|
je L(mt16)
|
|
|
|
|
|
|
|
L(ATR32):
|
|
|
|
movq %r11, %r10
|
|
|
|
andq $-64, %r10
|
|
|
|
testq $32, %rdi
|
|
|
|
jz L(ATR64)
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
L(ATR64):
|
|
|
|
cmpq %rdi, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
je L(mt32)
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
L(ATR64main):
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
cmpq %rdi, %r10
|
|
|
|
jne L(ATR64main)
|
|
|
|
|
|
|
|
movq %r11, %r10
|
2009-07-16 14:02:27 +00:00
|
|
|
andq $-32, %r10
|
|
|
|
cmpq %r10, %rdi
|
2019-02-04 14:31:01 +00:00
|
|
|
jae L(mt16)
|
2009-07-16 14:00:34 +00:00
|
|
|
|
|
|
|
L(ATR32res):
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
|
|
|
movdqa (%rdi,%rsi), %xmm0
|
|
|
|
pcmpeqb (%rdi), %xmm0
|
|
|
|
pmovmskb %xmm0, %edx
|
|
|
|
subl $0xffff, %edx
|
|
|
|
jnz L(neq)
|
|
|
|
addq $16, %rdi
|
|
|
|
|
2009-07-16 14:02:27 +00:00
|
|
|
cmpq %r10, %rdi
|
2009-07-16 14:00:34 +00:00
|
|
|
jne L(ATR32res)
|
|
|
|
|
|
|
|
subq %rdi, %r11
|
|
|
|
je L(finz)
|
2009-07-16 14:02:27 +00:00
|
|
|
movq %r11, %r10
|
|
|
|
jmp L(small)
|
2009-07-16 14:00:34 +00:00
|
|
|
/* Align to 16byte to improve instruction fetch. */
|
|
|
|
.p2align 4,, 4
|
|
|
|
END(memcmp)
|
|
|
|
|
|
|
|
#undef bcmp
|
|
|
|
weak_alias (memcmp, bcmp)
|
|
|
|
libc_hidden_builtin_def (memcmp)
|