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