|
Packit |
6c4009 |
/* strrchr with SSE2 with bsf and bsr
|
|
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 |
#if IS_IN (libc)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# include <sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define CFI_PUSH(REG) \
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (4); \
|
|
Packit |
6c4009 |
cfi_rel_offset (REG, 0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define CFI_POP(REG) \
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (-4); \
|
|
Packit |
6c4009 |
cfi_restore (REG)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define PUSH(REG) pushl REG; CFI_PUSH (REG)
|
|
Packit |
6c4009 |
# define POP(REG) popl REG; CFI_POP (REG)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define PARMS 4
|
|
Packit |
6c4009 |
# define STR1 PARMS
|
|
Packit |
6c4009 |
# define STR2 STR1+4
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
ENTRY (__strrchr_sse2_bsf)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
mov STR1(%esp), %ecx
|
|
Packit |
6c4009 |
movd STR2(%esp), %xmm1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PUSH (%edi)
|
|
Packit |
6c4009 |
pxor %xmm2, %xmm2
|
|
Packit |
6c4009 |
mov %ecx, %edi
|
|
Packit |
6c4009 |
punpcklbw %xmm1, %xmm1
|
|
Packit |
6c4009 |
punpcklbw %xmm1, %xmm1
|
|
Packit |
6c4009 |
/* ECX has OFFSET. */
|
|
Packit |
6c4009 |
and $63, %ecx
|
|
Packit |
6c4009 |
cmp $48, %ecx
|
|
Packit |
6c4009 |
pshufd $0, %xmm1, %xmm1
|
|
Packit |
6c4009 |
ja L(crosscashe)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* unaligned string. */
|
|
Packit |
6c4009 |
movdqu (%edi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm0, %xmm2
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
/* Find where NULL is. */
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %edx
|
|
Packit |
6c4009 |
/* Check if there is a match. */
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(unaligned_match1)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test %edx, %edx
|
|
Packit |
6c4009 |
jnz L(return_null)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
and $-16, %edi
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PUSH (%esi)
|
|
Packit |
6c4009 |
PUSH (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
xor %ebx, %ebx
|
|
Packit |
6c4009 |
jmp L(loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CFI_POP (%esi)
|
|
Packit |
6c4009 |
CFI_POP (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(unaligned_return_value1):
|
|
Packit |
6c4009 |
bsf %edx, %ecx
|
|
Packit |
6c4009 |
mov $2, %edx
|
|
Packit |
6c4009 |
shl %cl, %edx
|
|
Packit |
6c4009 |
sub $1, %edx
|
|
Packit |
6c4009 |
and %edx, %eax
|
|
Packit |
6c4009 |
jz L(return_null)
|
|
Packit |
6c4009 |
bsr %eax, %eax
|
|
Packit |
6c4009 |
add %edi, %eax
|
|
Packit |
6c4009 |
POP (%edi)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
CFI_PUSH (%edi)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(unaligned_match1):
|
|
Packit |
6c4009 |
test %edx, %edx
|
|
Packit |
6c4009 |
jnz L(unaligned_return_value1)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PUSH (%esi)
|
|
Packit |
6c4009 |
PUSH (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
mov %eax, %ebx
|
|
Packit |
6c4009 |
lea 16(%edi), %esi
|
|
Packit |
6c4009 |
and $-16, %edi
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
jmp L(loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CFI_POP (%esi)
|
|
Packit |
6c4009 |
CFI_POP (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(crosscashe):
|
|
Packit |
6c4009 |
/* Hancle unaligned string. */
|
|
Packit |
6c4009 |
and $15, %ecx
|
|
Packit |
6c4009 |
and $-16, %edi
|
|
Packit |
6c4009 |
pxor %xmm3, %xmm3
|
|
Packit |
6c4009 |
movdqa (%edi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm0, %xmm3
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
/* Find where NULL is. */
|
|
Packit |
6c4009 |
pmovmskb %xmm3, %edx
|
|
Packit |
6c4009 |
/* Check if there is a match. */
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
/* Remove the leading bytes. */
|
|
Packit |
6c4009 |
shr %cl, %edx
|
|
Packit |
6c4009 |
shr %cl, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(unaligned_match)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test %edx, %edx
|
|
Packit |
6c4009 |
jnz L(return_null)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PUSH (%esi)
|
|
Packit |
6c4009 |
PUSH (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
xor %ebx, %ebx
|
|
Packit |
6c4009 |
jmp L(loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CFI_POP (%esi)
|
|
Packit |
6c4009 |
CFI_POP (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(unaligned_return_value):
|
|
Packit |
6c4009 |
add %ecx, %edi
|
|
Packit |
6c4009 |
bsf %edx, %ecx
|
|
Packit |
6c4009 |
mov $2, %edx
|
|
Packit |
6c4009 |
shl %cl, %edx
|
|
Packit |
6c4009 |
sub $1, %edx
|
|
Packit |
6c4009 |
and %edx, %eax
|
|
Packit |
6c4009 |
jz L(return_null)
|
|
Packit |
6c4009 |
bsr %eax, %eax
|
|
Packit |
6c4009 |
add %edi, %eax
|
|
Packit |
6c4009 |
POP (%edi)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
CFI_PUSH (%edi)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(unaligned_match):
|
|
Packit |
6c4009 |
test %edx, %edx
|
|
Packit |
6c4009 |
jnz L(unaligned_return_value)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PUSH (%esi)
|
|
Packit |
6c4009 |
PUSH (%ebx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
mov %eax, %ebx
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
lea (%edi, %ecx), %esi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Loop start on aligned string. */
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(loop):
|
|
Packit |
6c4009 |
movdqa (%edi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm0, %xmm2
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %ecx
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
or %eax, %ecx
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa (%edi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm0, %xmm2
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %ecx
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
or %eax, %ecx
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa (%edi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm0, %xmm2
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %ecx
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
or %eax, %ecx
|
|
Packit |
6c4009 |
jnz L(matches)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movdqa (%edi), %xmm0
|
|
Packit |
6c4009 |
pcmpeqb %xmm0, %xmm2
|
|
Packit |
6c4009 |
add $16, %edi
|
|
Packit |
6c4009 |
pcmpeqb %xmm1, %xmm0
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %ecx
|
|
Packit |
6c4009 |
pmovmskb %xmm0, %eax
|
|
Packit |
6c4009 |
or %eax, %ecx
|
|
Packit |
6c4009 |
jz L(loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
L(matches):
|
|
Packit |
6c4009 |
test %eax, %eax
|
|
Packit |
6c4009 |
jnz L(match)
|
|
Packit |
6c4009 |
L(return_value):
|
|
Packit |
6c4009 |
test %ebx, %ebx
|
|
Packit |
6c4009 |
jz L(return_null_1)
|
|
Packit |
6c4009 |
bsr %ebx, %eax
|
|
Packit |
6c4009 |
add %esi, %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
POP (%ebx)
|
|
Packit |
6c4009 |
POP (%esi)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
sub $16, %eax
|
|
Packit |
6c4009 |
POP (%edi)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CFI_PUSH (%edi)
|
|
Packit |
6c4009 |
CFI_PUSH (%ebx)
|
|
Packit |
6c4009 |
CFI_PUSH (%esi)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(match):
|
|
Packit |
6c4009 |
pmovmskb %xmm2, %ecx
|
|
Packit |
6c4009 |
test %ecx, %ecx
|
|
Packit |
6c4009 |
jnz L(return_value_1)
|
|
Packit |
6c4009 |
mov %eax, %ebx
|
|
Packit |
6c4009 |
mov %edi, %esi
|
|
Packit |
6c4009 |
jmp L(loop)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(return_value_1):
|
|
Packit |
6c4009 |
bsf %ecx, %ecx
|
|
Packit |
6c4009 |
mov $2, %edx
|
|
Packit |
6c4009 |
shl %cl, %edx
|
|
Packit |
6c4009 |
sub $1, %edx
|
|
Packit |
6c4009 |
and %edx, %eax
|
|
Packit |
6c4009 |
jz L(return_value)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
POP (%ebx)
|
|
Packit |
6c4009 |
POP (%esi)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
bsr %eax, %eax
|
|
Packit |
6c4009 |
add %edi, %eax
|
|
Packit |
6c4009 |
sub $16, %eax
|
|
Packit |
6c4009 |
POP (%edi)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CFI_PUSH (%edi)
|
|
Packit |
6c4009 |
/* Return NULL. */
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(return_null):
|
|
Packit |
6c4009 |
xor %eax, %eax
|
|
Packit |
6c4009 |
POP (%edi)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CFI_PUSH (%edi)
|
|
Packit |
6c4009 |
CFI_PUSH (%ebx)
|
|
Packit |
6c4009 |
CFI_PUSH (%esi)
|
|
Packit |
6c4009 |
/* Return NULL. */
|
|
Packit |
6c4009 |
.p2align 4
|
|
Packit |
6c4009 |
L(return_null_1):
|
|
Packit |
6c4009 |
POP (%ebx)
|
|
Packit |
6c4009 |
POP (%esi)
|
|
Packit |
6c4009 |
POP (%edi)
|
|
Packit |
6c4009 |
xor %eax, %eax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
END (__strrchr_sse2_bsf)
|
|
Packit |
6c4009 |
#endif
|