]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
x86-64: Avoid rep movsb with short distance [BZ #27130]
[thirdparty/glibc.git] / sysdeps / x86_64 / multiarch / memmove-vec-unaligned-erms.S
index 9bab1147d57a520ab82d32f80728061945fa731d..5aaadc233f1ea8f4fe226e0b2096856879448ee9 100644 (file)
 # define REP_MOVSB_THRESHOLD   (2048 * (VEC_SIZE / 16))
 #endif
 
+/* Avoid short distance rep movsb only with non-SSE vector.  */
+#ifndef AVOID_SHORT_DISTANCE_REP_MOVSB
+# define AVOID_SHORT_DISTANCE_REP_MOVSB (VEC_SIZE > 16)
+#else
+# define AVOID_SHORT_DISTANCE_REP_MOVSB 0
+#endif
+
 #ifndef PREFETCH
 # define PREFETCH(addr) prefetcht0 addr
 #endif
@@ -257,7 +264,21 @@ L(movsb):
 #  error Unsupported REP_MOVSB_THRESHOLD and VEC_SIZE!
 # endif
        jb      L(more_8x_vec_backward)
+# if AVOID_SHORT_DISTANCE_REP_MOVSB
+       movq    %rdi, %rcx
+       subq    %rsi, %rcx
+       jmp     2f
+# endif
 1:
+# if AVOID_SHORT_DISTANCE_REP_MOVSB
+       movq    %rsi, %rcx
+       subq    %rdi, %rcx
+2:
+/* Avoid "rep movsb" if RCX, the distance between source and destination,
+   is N*4GB + [1..63] with N >= 0.  */
+       cmpl    $63, %ecx
+       jbe     L(more_2x_vec)  /* Avoid "rep movsb" if ECX <= 63.  */
+# endif
        mov     %RDX_LP, %RCX_LP
        rep movsb
 L(nop):