Blame sysdeps/x86_64/rawmemchr.S
|
Packit |
6c4009 |
/* fast SSE2 memchr with 64 byte loop and pmaxub instruction using
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Copyright (C) 2011-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
Contributed by Intel Corporation.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
ENTRY (__rawmemchr)
|
|
Packit |
6c4009 |
movd %rsi, %xmm1
|
|
Packit |
6c4009 |
mov %rdi, %rcx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
punpcklbw %xmm1, %xmm1
|
|
Packit |
6c4009 |
punpcklbw %xmm1, %xmm1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
and $63, %rcx
|
|
Packit |
6c4009 |
pshufd $0, %xmm1, %xmm1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cmp $48, %rcx
|
|
Packit |
6c4009 |
ja L(crosscache)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqu (%rdi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
/* Check if there is a match. */
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
add $16, %rdi
|
|
Packit |
6c4009 |
and $-16, %rdi
|
|
Packit |
6c4009 |
jmp L(loop_prolog)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(crosscache):
|
|
Packit |
6c4009 |
and $15, %rcx
|
|
Packit |
6c4009 |
and $-16, %rdi
|
|
Packit |
6c4009 |
movdqa (%rdi), %xmm0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
/* Check if there is a match. */
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
/* Remove the leading bytes. */
|
|
Packit |
6c4009 |
sar %cl, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
je L(unaligned_no_match)
|
|
Packit |
6c4009 |
/* Check which byte is a match. */
|
|
Packit |
6c4009 |
bsf %eax, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
add %rdi, %rax
|
|
Packit |
6c4009 |
add %rcx, %rax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(unaligned_no_match):
|
|
Packit |
6c4009 |
add $16, %rdi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(loop_prolog):
|
|
Packit |
6c4009 |
movdqa (%rdi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 16(%rdi), %xmm2
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm2
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches16)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 32(%rdi), %xmm3
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm3
|
|
Packit |
6c4009 |
pmovmskb %xmm3, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches32)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 48(%rdi), %xmm4
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm4
|
|
Packit |
6c4009 |
add $64, %rdi
|
|
Packit |
6c4009 |
pmovmskb %xmm4, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test $0x3f, %rdi
|
|
Packit |
6c4009 |
jz L(align64_loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa (%rdi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 16(%rdi), %xmm2
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm2
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches16)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 32(%rdi), %xmm3
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm3
|
|
Packit |
6c4009 |
pmovmskb %xmm3, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches32)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 48(%rdi), %xmm3
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm3
|
|
Packit |
6c4009 |
pmovmskb %xmm3, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
add $64, %rdi
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
and $-64, %rdi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(align64_loop):
|
|
Packit |
6c4009 |
movdqa (%rdi), %xmm0
|
|
Packit |
6c4009 |
movdqa 16(%rdi), %xmm2
|
|
Packit |
6c4009 |
movdqa 32(%rdi), %xmm3
|
|
Packit |
6c4009 |
movdqa 48(%rdi), %xmm4
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm2
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm3
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm4
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pmaxub %xmm0, %xmm3
|
|
Packit |
6c4009 |
pmaxub %xmm2, %xmm4
|
|
Packit |
6c4009 |
pmaxub %xmm3, %xmm4
|
|
Packit |
6c4009 |
pmovmskb %xmm4, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
add $64, %rdi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jz L(align64_loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
sub $64, %rdi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches16)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa 32(%rdi), %xmm3
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm3
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pcmpeqb 48(%rdi), %xmm1
|
|
Packit |
6c4009 |
pmovmskb %xmm3, %eax
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(matches32)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pmovmskb %xmm1, %eax
|
|
Packit |
6c4009 |
bsf %eax, %eax
|
|
Packit |
6c4009 |
lea 48(%rdi, %rax), %rax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(matches0):
|
|
Packit |
6c4009 |
bsf %eax, %eax
|
|
Packit |
6c4009 |
lea -16(%rax, %rdi), %rax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(matches):
|
|
Packit |
6c4009 |
bsf %eax, %eax
|
|
Packit |
6c4009 |
add %rdi, %rax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(matches16):
|
|
Packit |
6c4009 |
bsf %eax, %eax
|
|
Packit |
6c4009 |
lea 16(%rax, %rdi), %rax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(matches32):
|
|
Packit |
6c4009 |
bsf %eax, %eax
|
|
Packit |
6c4009 |
lea 32(%rax, %rdi), %rax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
END (__rawmemchr)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
weak_alias (__rawmemchr, rawmemchr)
|
|
Packit |
6c4009 |
libc_hidden_builtin_def (__rawmemchr)
|