2021-03-05 14:24:52 +00:00
|
|
|
/* strrchr/wcsrchr optimized with 256-bit EVEX instructions.
|
2022-01-01 18:54:23 +00:00
|
|
|
Copyright (C) 2021-2022 Free Software Foundation, Inc.
|
2021-03-05 14:24:52 +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
|
|
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
|
2022-07-13 23:32:59 +00:00
|
|
|
#include <isa-level.h>
|
|
|
|
|
|
|
|
#if ISA_SHOULD_BUILD (4)
|
2021-03-05 14:24:52 +00:00
|
|
|
|
|
|
|
# include <sysdep.h>
|
|
|
|
|
|
|
|
# ifndef STRRCHR
|
|
|
|
# define STRRCHR __strrchr_evex
|
|
|
|
# endif
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
# include "x86-evex256-vecs.h"
|
2021-03-05 14:24:52 +00:00
|
|
|
|
|
|
|
# ifdef USE_AS_WCSRCHR
|
2022-10-20 17:26:46 +00:00
|
|
|
# define SHIFT_REG rsi
|
2022-10-19 00:44:07 +00:00
|
|
|
# define kunpck_2x kunpckbw
|
2022-04-22 01:52:30 +00:00
|
|
|
# define kmov_2x kmovd
|
|
|
|
# define maskz_2x ecx
|
|
|
|
# define maskm_2x eax
|
|
|
|
# define CHAR_SIZE 4
|
|
|
|
# define VPMIN vpminud
|
|
|
|
# define VPTESTN vptestnmd
|
2022-10-19 00:44:07 +00:00
|
|
|
# define VPTEST vptestmd
|
2021-03-05 14:24:52 +00:00
|
|
|
# define VPBROADCAST vpbroadcastd
|
2022-10-19 00:44:07 +00:00
|
|
|
# define VPCMPEQ vpcmpeqd
|
2022-04-22 01:52:30 +00:00
|
|
|
# define VPCMP vpcmpd
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
# define USE_WIDE_CHAR
|
|
|
|
# else
|
|
|
|
# define SHIFT_REG rdi
|
|
|
|
# define kunpck_2x kunpckdq
|
2022-04-22 01:52:30 +00:00
|
|
|
# define kmov_2x kmovq
|
|
|
|
# define maskz_2x rcx
|
|
|
|
# define maskm_2x rax
|
|
|
|
|
|
|
|
# define CHAR_SIZE 1
|
|
|
|
# define VPMIN vpminub
|
|
|
|
# define VPTESTN vptestnmb
|
2022-10-19 00:44:07 +00:00
|
|
|
# define VPTEST vptestmb
|
2021-03-05 14:24:52 +00:00
|
|
|
# define VPBROADCAST vpbroadcastb
|
2022-10-19 00:44:07 +00:00
|
|
|
# define VPCMPEQ vpcmpeqb
|
2022-04-22 01:52:30 +00:00
|
|
|
# define VPCMP vpcmpb
|
2021-03-05 14:24:52 +00:00
|
|
|
# endif
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
# include "reg-macros.h"
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
# define VMATCH VMM(0)
|
|
|
|
# define CHAR_PER_VEC (VEC_SIZE / CHAR_SIZE)
|
2022-04-22 01:52:30 +00:00
|
|
|
# define PAGE_SIZE 4096
|
2022-10-19 00:44:07 +00:00
|
|
|
|
|
|
|
.section SECTION(.text), "ax", @progbits
|
|
|
|
ENTRY_P2ALIGN(STRRCHR, 6)
|
2022-04-22 01:52:30 +00:00
|
|
|
movl %edi, %eax
|
2022-10-19 00:44:07 +00:00
|
|
|
/* Broadcast CHAR to VMATCH. */
|
|
|
|
VPBROADCAST %esi, %VMATCH
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
andl $(PAGE_SIZE - 1), %eax
|
|
|
|
cmpl $(PAGE_SIZE - VEC_SIZE), %eax
|
|
|
|
jg L(cross_page_boundary)
|
2022-10-20 17:26:46 +00:00
|
|
|
L(page_cross_continue):
|
2022-10-19 00:44:07 +00:00
|
|
|
VMOVU (%rdi), %VMM(1)
|
|
|
|
/* k0 has a 1 for each zero CHAR in VEC(1). */
|
|
|
|
VPTESTN %VMM(1), %VMM(1), %k0
|
|
|
|
KMOV %k0, %VRSI
|
|
|
|
test %VRSI, %VRSI
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(aligned_more)
|
|
|
|
/* fallthrough: zero CHAR in first VEC. */
|
2022-10-19 00:44:07 +00:00
|
|
|
/* K1 has a 1 for each search CHAR match in VEC(1). */
|
|
|
|
VPCMPEQ %VMATCH, %VMM(1), %k1
|
|
|
|
KMOV %k1, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
/* Build mask up until first zero CHAR (used to mask of
|
|
|
|
potential search CHAR matches past the end of the string).
|
|
|
|
*/
|
2022-10-19 00:44:07 +00:00
|
|
|
blsmsk %VRSI, %VRSI
|
|
|
|
and %VRSI, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(ret0)
|
2022-10-19 00:44:07 +00:00
|
|
|
/* Get last match (the `and` removed any out of bounds matches).
|
|
|
|
*/
|
|
|
|
bsr %VRAX, %VRAX
|
2021-03-05 14:24:52 +00:00
|
|
|
# ifdef USE_AS_WCSRCHR
|
2022-04-22 01:52:30 +00:00
|
|
|
leaq (%rdi, %rax, CHAR_SIZE), %rax
|
|
|
|
# else
|
|
|
|
addq %rdi, %rax
|
2021-03-05 14:24:52 +00:00
|
|
|
# endif
|
2022-04-22 01:52:30 +00:00
|
|
|
L(ret0):
|
|
|
|
ret
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
/* Returns for first vec x1/x2/x3 have hard coded backward
|
|
|
|
search path for earlier matches. */
|
|
|
|
.p2align 4,, 6
|
|
|
|
L(first_vec_x1):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMATCH, %VMM(2), %k1
|
|
|
|
KMOV %k1, %VRAX
|
|
|
|
blsmsk %VRCX, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
/* eax non-zero if search CHAR in range. */
|
2022-10-19 00:44:07 +00:00
|
|
|
and %VRCX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jnz L(first_vec_x1_return)
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
/* fallthrough: no match in VEC(2) then need to check for
|
|
|
|
earlier matches (in VEC(1)). */
|
2022-04-22 01:52:30 +00:00
|
|
|
.p2align 4,, 4
|
|
|
|
L(first_vec_x0_test):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMATCH, %VMM(1), %k1
|
|
|
|
KMOV %k1, %VRAX
|
|
|
|
test %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(ret1)
|
2022-10-19 00:44:07 +00:00
|
|
|
bsr %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
# ifdef USE_AS_WCSRCHR
|
|
|
|
leaq (%rsi, %rax, CHAR_SIZE), %rax
|
|
|
|
# else
|
|
|
|
addq %rsi, %rax
|
|
|
|
# endif
|
|
|
|
L(ret1):
|
|
|
|
ret
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
.p2align 4,, 10
|
|
|
|
L(first_vec_x1_or_x2):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMM(3), %VMATCH, %k3
|
|
|
|
VPCMPEQ %VMM(2), %VMATCH, %k2
|
2022-04-22 01:52:30 +00:00
|
|
|
/* K2 and K3 have 1 for any search CHAR match. Test if any
|
2022-10-19 00:44:07 +00:00
|
|
|
matches between either of them. Otherwise check VEC(1). */
|
|
|
|
KORTEST %k2, %k3
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(first_vec_x0_test)
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
/* Guranteed that VEC(2) and VEC(3) are within range so merge
|
|
|
|
the two bitmasks then get last result. */
|
|
|
|
kunpck_2x %k2, %k3, %k3
|
|
|
|
kmov_2x %k3, %maskm_2x
|
|
|
|
bsr %maskm_2x, %maskm_2x
|
|
|
|
leaq (VEC_SIZE * 1)(%r8, %rax, CHAR_SIZE), %rax
|
2022-04-22 01:52:30 +00:00
|
|
|
ret
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
.p2align 4,, 7
|
2022-04-22 01:52:30 +00:00
|
|
|
L(first_vec_x3):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMATCH, %VMM(4), %k1
|
|
|
|
KMOV %k1, %VRAX
|
|
|
|
blsmsk %VRCX, %VRCX
|
|
|
|
/* If no search CHAR match in range check VEC(1)/VEC(2)/VEC(3).
|
|
|
|
*/
|
|
|
|
and %VRCX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(first_vec_x1_or_x2)
|
2022-10-19 00:44:07 +00:00
|
|
|
bsr %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
leaq (VEC_SIZE * 3)(%rdi, %rax, CHAR_SIZE), %rax
|
|
|
|
ret
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
.p2align 4,, 6
|
|
|
|
L(first_vec_x0_x1_test):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMATCH, %VMM(2), %k1
|
|
|
|
KMOV %k1, %VRAX
|
|
|
|
/* Check VEC(2) for last match first. If no match try VEC(1).
|
|
|
|
*/
|
|
|
|
test %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(first_vec_x0_test)
|
|
|
|
.p2align 4,, 4
|
|
|
|
L(first_vec_x1_return):
|
2022-10-19 00:44:07 +00:00
|
|
|
bsr %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
leaq (VEC_SIZE)(%rdi, %rax, CHAR_SIZE), %rax
|
|
|
|
ret
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
.p2align 4,, 10
|
|
|
|
L(first_vec_x2):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMATCH, %VMM(3), %k1
|
|
|
|
KMOV %k1, %VRAX
|
|
|
|
blsmsk %VRCX, %VRCX
|
|
|
|
/* Check VEC(3) for last match first. If no match try
|
|
|
|
VEC(2)/VEC(1). */
|
|
|
|
and %VRCX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(first_vec_x0_x1_test)
|
2022-10-19 00:44:07 +00:00
|
|
|
bsr %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
leaq (VEC_SIZE * 2)(%rdi, %rax, CHAR_SIZE), %rax
|
|
|
|
ret
|
2021-03-05 14:24:52 +00:00
|
|
|
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
.p2align 4,, 12
|
2022-04-22 01:52:30 +00:00
|
|
|
L(aligned_more):
|
2022-10-19 00:44:07 +00:00
|
|
|
/* Need to keep original pointer incase VEC(1) has last match.
|
|
|
|
*/
|
2022-04-22 01:52:30 +00:00
|
|
|
movq %rdi, %rsi
|
|
|
|
andq $-VEC_SIZE, %rdi
|
2022-10-19 00:44:07 +00:00
|
|
|
|
|
|
|
VMOVU VEC_SIZE(%rdi), %VMM(2)
|
|
|
|
VPTESTN %VMM(2), %VMM(2), %k0
|
|
|
|
KMOV %k0, %VRCX
|
|
|
|
|
|
|
|
test %VRCX, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
jnz L(first_vec_x1)
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VMOVU (VEC_SIZE * 2)(%rdi), %VMM(3)
|
|
|
|
VPTESTN %VMM(3), %VMM(3), %k0
|
|
|
|
KMOV %k0, %VRCX
|
|
|
|
|
|
|
|
test %VRCX, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
jnz L(first_vec_x2)
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VMOVU (VEC_SIZE * 3)(%rdi), %VMM(4)
|
|
|
|
VPTESTN %VMM(4), %VMM(4), %k0
|
|
|
|
KMOV %k0, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
movq %rdi, %r8
|
2022-10-19 00:44:07 +00:00
|
|
|
test %VRCX, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
jnz L(first_vec_x3)
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
andq $-(VEC_SIZE * 2), %rdi
|
2022-10-19 00:44:07 +00:00
|
|
|
.p2align 4,, 10
|
2022-04-22 01:52:30 +00:00
|
|
|
L(first_aligned_loop):
|
2022-10-19 00:44:07 +00:00
|
|
|
/* Preserve VEC(1), VEC(2), VEC(3), and VEC(4) until we can
|
|
|
|
gurantee they don't store a match. */
|
|
|
|
VMOVA (VEC_SIZE * 4)(%rdi), %VMM(5)
|
|
|
|
VMOVA (VEC_SIZE * 5)(%rdi), %VMM(6)
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMM(5), %VMATCH, %k2
|
|
|
|
vpxord %VMM(6), %VMATCH, %VMM(7)
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VPMIN %VMM(5), %VMM(6), %VMM(8)
|
|
|
|
VPMIN %VMM(8), %VMM(7), %VMM(7)
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VPTESTN %VMM(7), %VMM(7), %k1
|
2022-04-22 01:52:30 +00:00
|
|
|
subq $(VEC_SIZE * -2), %rdi
|
2022-10-19 00:44:07 +00:00
|
|
|
KORTEST %k1, %k2
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(first_aligned_loop)
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMM(6), %VMATCH, %k3
|
|
|
|
VPTESTN %VMM(8), %VMM(8), %k1
|
|
|
|
|
|
|
|
/* If k1 is zero, then we found a CHAR match but no null-term.
|
|
|
|
We can now safely throw out VEC1-4. */
|
|
|
|
KTEST %k1, %k1
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(second_aligned_loop_prep)
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
KORTEST %k2, %k3
|
2022-04-22 01:52:30 +00:00
|
|
|
jnz L(return_first_aligned_loop)
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
.p2align 4,, 6
|
|
|
|
L(first_vec_x1_or_x2_or_x3):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMM(4), %VMATCH, %k4
|
|
|
|
KMOV %k4, %VRAX
|
|
|
|
bsr %VRAX, %VRAX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(first_vec_x1_or_x2)
|
|
|
|
leaq (VEC_SIZE * 3)(%r8, %rax, CHAR_SIZE), %rax
|
2021-03-05 14:24:52 +00:00
|
|
|
ret
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
.p2align 4,, 8
|
|
|
|
L(return_first_aligned_loop):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPTESTN %VMM(5), %VMM(5), %k0
|
|
|
|
|
|
|
|
/* Combined results from VEC5/6. */
|
|
|
|
kunpck_2x %k0, %k1, %k0
|
2022-04-22 01:52:30 +00:00
|
|
|
kmov_2x %k0, %maskz_2x
|
|
|
|
|
|
|
|
blsmsk %maskz_2x, %maskz_2x
|
2022-10-19 00:44:07 +00:00
|
|
|
kunpck_2x %k2, %k3, %k3
|
2022-04-22 01:52:30 +00:00
|
|
|
kmov_2x %k3, %maskm_2x
|
|
|
|
and %maskz_2x, %maskm_2x
|
|
|
|
jz L(first_vec_x1_or_x2_or_x3)
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
bsr %maskm_2x, %maskm_2x
|
|
|
|
leaq (VEC_SIZE * 2)(%rdi, %rax, CHAR_SIZE), %rax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.p2align 4
|
|
|
|
/* We can throw away the work done for the first 4x checks here
|
|
|
|
as we have a later match. This is the 'fast' path persay.
|
|
|
|
*/
|
|
|
|
L(second_aligned_loop_prep):
|
|
|
|
L(second_aligned_loop_set_furthest_match):
|
2021-03-05 14:24:52 +00:00
|
|
|
movq %rdi, %rsi
|
2022-10-19 00:44:07 +00:00
|
|
|
/* Ideally we would safe k2/k3 but `kmov/kunpck` take uops on
|
|
|
|
port0 and have noticable overhead in the loop. */
|
|
|
|
VMOVA %VMM(5), %VMM(7)
|
|
|
|
VMOVA %VMM(6), %VMM(8)
|
2021-03-05 14:24:52 +00:00
|
|
|
.p2align 4
|
2022-04-22 01:52:30 +00:00
|
|
|
L(second_aligned_loop):
|
2022-10-19 00:44:07 +00:00
|
|
|
VMOVU (VEC_SIZE * 4)(%rdi), %VMM(5)
|
|
|
|
VMOVU (VEC_SIZE * 5)(%rdi), %VMM(6)
|
|
|
|
VPCMPEQ %VMM(5), %VMATCH, %k2
|
|
|
|
vpxord %VMM(6), %VMATCH, %VMM(3)
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VPMIN %VMM(5), %VMM(6), %VMM(4)
|
|
|
|
VPMIN %VMM(3), %VMM(4), %VMM(3)
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
VPTESTN %VMM(3), %VMM(3), %k1
|
2022-04-22 01:52:30 +00:00
|
|
|
subq $(VEC_SIZE * -2), %rdi
|
2022-10-19 00:44:07 +00:00
|
|
|
KORTEST %k1, %k2
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(second_aligned_loop)
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMM(6), %VMATCH, %k3
|
|
|
|
VPTESTN %VMM(4), %VMM(4), %k1
|
|
|
|
KTEST %k1, %k1
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(second_aligned_loop_set_furthest_match)
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
/* branch here because we know we have a match in VEC7/8 but
|
|
|
|
might not in VEC5/6 so the latter is expected to be less
|
|
|
|
likely. */
|
|
|
|
KORTEST %k2, %k3
|
2022-04-22 01:52:30 +00:00
|
|
|
jnz L(return_new_match)
|
2022-10-19 00:44:07 +00:00
|
|
|
|
2022-04-22 01:52:30 +00:00
|
|
|
L(return_old_match):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPCMPEQ %VMM(8), %VMATCH, %k0
|
|
|
|
KMOV %k0, %VRCX
|
|
|
|
bsr %VRCX, %VRCX
|
|
|
|
jnz L(return_old_match_ret)
|
|
|
|
|
|
|
|
VPCMPEQ %VMM(7), %VMATCH, %k0
|
|
|
|
KMOV %k0, %VRCX
|
|
|
|
bsr %VRCX, %VRCX
|
|
|
|
subq $VEC_SIZE, %rsi
|
|
|
|
L(return_old_match_ret):
|
|
|
|
leaq (VEC_SIZE * 3)(%rsi, %rcx, CHAR_SIZE), %rax
|
2022-04-22 01:52:30 +00:00
|
|
|
ret
|
|
|
|
|
2022-10-19 00:44:07 +00:00
|
|
|
.p2align 4,, 10
|
2022-04-22 01:52:30 +00:00
|
|
|
L(return_new_match):
|
2022-10-19 00:44:07 +00:00
|
|
|
VPTESTN %VMM(5), %VMM(5), %k0
|
|
|
|
|
|
|
|
/* Combined results from VEC5/6. */
|
|
|
|
kunpck_2x %k0, %k1, %k0
|
2022-04-22 01:52:30 +00:00
|
|
|
kmov_2x %k0, %maskz_2x
|
|
|
|
|
|
|
|
blsmsk %maskz_2x, %maskz_2x
|
2022-10-19 00:44:07 +00:00
|
|
|
kunpck_2x %k2, %k3, %k3
|
2022-04-22 01:52:30 +00:00
|
|
|
kmov_2x %k3, %maskm_2x
|
2022-10-19 00:44:07 +00:00
|
|
|
|
|
|
|
/* Match at end was out-of-bounds so use last known match. */
|
2022-04-22 01:52:30 +00:00
|
|
|
and %maskz_2x, %maskm_2x
|
|
|
|
jz L(return_old_match)
|
|
|
|
|
|
|
|
bsr %maskm_2x, %maskm_2x
|
|
|
|
leaq (VEC_SIZE * 2)(%rdi, %rax, CHAR_SIZE), %rax
|
|
|
|
ret
|
|
|
|
|
|
|
|
L(cross_page_boundary):
|
2022-10-20 17:26:46 +00:00
|
|
|
/* eax contains all the page offset bits of src (rdi). `xor rdi,
|
|
|
|
rax` sets pointer will all page offset bits cleared so
|
|
|
|
offset of (PAGE_SIZE - VEC_SIZE) will get last aligned VEC
|
|
|
|
before page cross (guranteed to be safe to read). Doing this
|
|
|
|
as opposed to `movq %rdi, %rax; andq $-VEC_SIZE, %rax` saves
|
|
|
|
a bit of code size. */
|
2022-04-22 01:52:30 +00:00
|
|
|
xorq %rdi, %rax
|
2022-10-20 17:26:46 +00:00
|
|
|
VMOVU (PAGE_SIZE - VEC_SIZE)(%rax), %VMM(1)
|
|
|
|
VPTESTN %VMM(1), %VMM(1), %k0
|
|
|
|
KMOV %k0, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
|
2022-10-20 17:26:46 +00:00
|
|
|
/* Shift out zero CHAR matches that are before the begining of
|
|
|
|
src (rdi). */
|
2021-03-05 14:24:52 +00:00
|
|
|
# ifdef USE_AS_WCSRCHR
|
2022-10-20 17:26:46 +00:00
|
|
|
movl %edi, %esi
|
|
|
|
andl $(VEC_SIZE - 1), %esi
|
|
|
|
shrl $2, %esi
|
2021-03-05 14:24:52 +00:00
|
|
|
# endif
|
2022-10-20 17:26:46 +00:00
|
|
|
shrx %VGPR(SHIFT_REG), %VRCX, %VRCX
|
2021-03-05 14:24:52 +00:00
|
|
|
|
2022-10-20 17:26:46 +00:00
|
|
|
test %VRCX, %VRCX
|
2022-04-22 01:52:30 +00:00
|
|
|
jz L(page_cross_continue)
|
|
|
|
|
2022-10-20 17:26:46 +00:00
|
|
|
/* Found zero CHAR so need to test for search CHAR. */
|
|
|
|
VPCMP $0, %VMATCH, %VMM(1), %k1
|
2022-10-19 00:44:07 +00:00
|
|
|
KMOV %k1, %VRAX
|
2022-10-20 17:26:46 +00:00
|
|
|
/* Shift out search CHAR matches that are before the begining of
|
|
|
|
src (rdi). */
|
|
|
|
shrx %VGPR(SHIFT_REG), %VRAX, %VRAX
|
|
|
|
|
|
|
|
/* Check if any search CHAR match in range. */
|
|
|
|
blsmsk %VRCX, %VRCX
|
|
|
|
and %VRCX, %VRAX
|
|
|
|
jz L(ret3)
|
2022-10-19 00:44:07 +00:00
|
|
|
bsr %VRAX, %VRAX
|
2021-03-05 14:24:52 +00:00
|
|
|
# ifdef USE_AS_WCSRCHR
|
2022-04-22 01:52:30 +00:00
|
|
|
leaq (%rdi, %rax, CHAR_SIZE), %rax
|
2021-03-05 14:24:52 +00:00
|
|
|
# else
|
2022-04-22 01:52:30 +00:00
|
|
|
addq %rdi, %rax
|
2021-03-05 14:24:52 +00:00
|
|
|
# endif
|
2022-10-20 17:26:46 +00:00
|
|
|
L(ret3):
|
2021-03-05 14:24:52 +00:00
|
|
|
ret
|
2022-04-22 01:52:30 +00:00
|
|
|
END(STRRCHR)
|
2021-03-05 14:24:52 +00:00
|
|
|
#endif
|