]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix avx2 strncmp offset compare condition check [BZ #25933]
authorSunil K Pandey <skpgkp1@gmail.com>
Fri, 12 Jun 2020 15:57:16 +0000 (08:57 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 17 Jun 2020 14:07:38 +0000 (07:07 -0700)
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

index 5f88a68262ebfb54856fe026e22cda5f42aeb607..d42b04b54fa8b44aabb676e08e90fcaceb406b71 100644 (file)
@@ -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.  */