786673
commit 75870237ff3bb363447b03f4b0af100227570910
786673
Author: Sunil K Pandey <skpgkp1@gmail.com>
786673
Date:   Fri Jun 12 08:57:16 2020 -0700
786673
786673
    Fix avx2 strncmp offset compare condition check [BZ #25933]
786673
    
786673
    strcmp-avx2.S: In avx2 strncmp function, strings are compared in
786673
    chunks of 4 vector size(i.e. 32x4=128 byte for avx2). After first 4
786673
    vector size comparison, code must check whether it already passed
786673
    the given offset. This patch implement avx2 offset check condition
786673
    for strncmp function, if both string compare same for first 4 vector
786673
    size.
786673
786673
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
786673
index 5f88a68262..d42b04b54f 100644
786673
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
786673
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
786673
@@ -591,7 +591,14 @@ L(loop_cross_page_2_vec):
786673
 	movl	$(PAGE_SIZE / (VEC_SIZE * 4) - 1), %esi
786673
 
786673
 	testq	%rdi, %rdi
786673
+# ifdef USE_AS_STRNCMP
786673
+	/* At this point, if %rdi value is 0, it already tested
786673
+	   VEC_SIZE*4+%r10 byte starting from %rax. This label
786673
+	   checks whether strncmp maximum offset reached or not.  */
786673
+	je	L(string_nbyte_offset_check)
786673
+# else
786673
 	je	L(back_to_loop)
786673
+# endif
786673
 	tzcntq	%rdi, %rcx
786673
 	addq	%r10, %rcx
786673
 	/* Adjust for number of bytes skipped.  */
786673
@@ -627,6 +634,14 @@ L(loop_cross_page_2_vec):
786673
 	VZEROUPPER
786673
 	ret
786673
 
786673
+# ifdef USE_AS_STRNCMP
786673
+L(string_nbyte_offset_check):
786673
+	leaq	(VEC_SIZE * 4)(%r10), %r10
786673
+	cmpq	%r10, %r11
786673
+	jbe	L(zero)
786673
+	jmp	L(back_to_loop)
786673
+# endif
786673
+
786673
 	.p2align 4
786673
 L(cross_page_loop):
786673
 	/* Check one byte/dword at a time.  */