public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix avx2 strncmp offset compare condition check [BZ #25933]
@ 2020-06-13 11:23 H.J. Lu
  2020-06-17 13:49 ` H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2020-06-13 11:23 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sunil K Pandey

From: Sunil K Pandey <skpgkp1@gmail.com>

strcmp-avx2.S: In avx2 strncmp function, strings are compared in
chunks of 4 vector size(i.e. 32x4=128 byte for avx2). After first 4
vector size comparison, code must check whether it already passed
the given offset. This patch implement avx2 offset check condition
for strncmp function, if both string compare same for first 4 vector
size.
---
 sysdeps/x86_64/multiarch/strcmp-avx2.S | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 48d03a9f46..ee82fa3e19 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -591,7 +591,14 @@ L(loop_cross_page_2_vec):
 	movl	$(PAGE_SIZE / (VEC_SIZE * 4) - 1), %esi
 
 	testq	%rdi, %rdi
+# ifdef USE_AS_STRNCMP
+	/* At this point, if %rdi value is 0, it already tested
+	   VEC_SIZE*4+%r10 byte starting from %rax. This label
+	   checks whether strncmp maximum offset reached or not.  */
+	je	L(string_nbyte_offset_check)
+# else
 	je	L(back_to_loop)
+# endif
 	tzcntq	%rdi, %rcx
 	addq	%r10, %rcx
 	/* Adjust for number of bytes skipped.  */
@@ -627,6 +634,14 @@ L(loop_cross_page_2_vec):
 	VZEROUPPER
 	ret
 
+# ifdef USE_AS_STRNCMP
+L(string_nbyte_offset_check):
+	leaq	(VEC_SIZE * 4)(%r10), %r10
+	cmpq	%r10, %r11
+	jbe	L(zero)
+	jmp	L(back_to_loop)
+# endif
+
 	.p2align 4
 L(cross_page_loop):
 	/* Check one byte/dword at a time.  */
-- 
2.26.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix avx2 strncmp offset compare condition check [BZ #25933]
  2020-06-13 11:23 [PATCH] Fix avx2 strncmp offset compare condition check [BZ #25933] H.J. Lu
@ 2020-06-17 13:49 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2020-06-17 13:49 UTC (permalink / raw)
  To: GNU C Library; +Cc: Sunil K Pandey

On Sat, Jun 13, 2020 at 4:23 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> From: Sunil K Pandey <skpgkp1@gmail.com>
>
> strcmp-avx2.S: In avx2 strncmp function, strings are compared in
> chunks of 4 vector size(i.e. 32x4=128 byte for avx2). After first 4
> vector size comparison, code must check whether it already passed
> the given offset. This patch implement avx2 offset check condition
> for strncmp function, if both string compare same for first 4 vector
> size.
> ---
>  sysdeps/x86_64/multiarch/strcmp-avx2.S | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> index 48d03a9f46..ee82fa3e19 100644
> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> @@ -591,7 +591,14 @@ L(loop_cross_page_2_vec):
>         movl    $(PAGE_SIZE / (VEC_SIZE * 4) - 1), %esi
>
>         testq   %rdi, %rdi
> +# ifdef USE_AS_STRNCMP
> +       /* At this point, if %rdi value is 0, it already tested
> +          VEC_SIZE*4+%r10 byte starting from %rax. This label
> +          checks whether strncmp maximum offset reached or not.  */
> +       je      L(string_nbyte_offset_check)
> +# else
>         je      L(back_to_loop)
> +# endif
>         tzcntq  %rdi, %rcx
>         addq    %r10, %rcx
>         /* Adjust for number of bytes skipped.  */
> @@ -627,6 +634,14 @@ L(loop_cross_page_2_vec):
>         VZEROUPPER
>         ret
>
> +# ifdef USE_AS_STRNCMP
> +L(string_nbyte_offset_check):
> +       leaq    (VEC_SIZE * 4)(%r10), %r10
> +       cmpq    %r10, %r11
> +       jbe     L(zero)
> +       jmp     L(back_to_loop)
> +# endif
> +
>         .p2align 4
>  L(cross_page_loop):
>         /* Check one byte/dword at a time.  */
> --
> 2.26.2
>

I am checking it in and backport it to the active branches.

-- 
H.J.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-17 13:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-13 11:23 [PATCH] Fix avx2 strncmp offset compare condition check [BZ #25933] H.J. Lu
2020-06-17 13:49 ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).