From patchwork Wed Dec 30 20:14:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 41601 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD6F83850409; Wed, 30 Dec 2020 20:14:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD6F83850409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609359259; bh=jFAKCabmXNXAMT7ufnAfxGEXmBM3sgIBZxMzdr0VNNQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=c+iCJjuXgFG3JE03W92i+xVoqXr7OBQJmRubFEdb+3ncDx+Gi5lBbLkrVuzrX7OA5 DHwYtWAKdYHTchBY6prWvrLswRwr9r4tmQYXlAiYNDIOkRy75X/ezxgIFR0FGnF9xc E9iulPwh7GRiOhd58zLv6MEWzyYhgwt3ve6ipH4o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 1D5233858038 for ; Wed, 30 Dec 2020 20:14:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D5233858038 Received: by mail-pl1-x633.google.com with SMTP id r4so9111253pls.11 for ; Wed, 30 Dec 2020 12:14:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=jFAKCabmXNXAMT7ufnAfxGEXmBM3sgIBZxMzdr0VNNQ=; b=g6Ahc73WXMZvC8vYE4QGHc/b/iBYxYFgM84d9NVCkz4QT2gOOsVKO9aTIOW1jViJ/3 D32OX7cgutPFskupMOgIH7yveGAkppYO/HrZ9JSCSZ7R5anFhKsRSI5onLBtUpSg5idx gu4fSPuoCbM9RdNXqfjLNthd+PJORb6+SRs4XheZe/C9njTkK9ULs5fVmIYOGi9oebbS U7+YTCWDljJCGoDJiQsgMkxxC6g3TonWl40P0WlubUYrd1zkJbwpgRjoc0W23aR/JhTB 6aIpxziWbFCp2TL+SSCFD7TIfF/voCnz1C9uHfC1LtWtfWqMpzCays2CIjfvCefzmFP9 ZgsA== X-Gm-Message-State: AOAM5325fSmqnT7PyVC1icHJIjCg5JcA9VfN1F/NnVX3+oraOiGIayWA ik1rrptx/bW2ioA9qnRShGnAlMiGXnE= X-Google-Smtp-Source: ABdhPJzzx+mCugOOBRWexZNsFPBGqL2dJMPsGUzO2RwfUW1R2+eETvbW8SVsc8c5dfkDJTVrS2E7aQ== X-Received: by 2002:a17:90a:f0ce:: with SMTP id fa14mr10170247pjb.156.1609359255883; Wed, 30 Dec 2020 12:14:15 -0800 (PST) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id b12sm42834383pft.114.2020.12.30.12.14.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 12:14:15 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 9241B1A0109 for ; Wed, 30 Dec 2020 12:14:13 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] x86-64: Avoid overlap of rep movsb in memmove [BZ #27130] Date: Wed, 30 Dec 2020 12:14:11 -0800 Message-Id: <20201230201411.2782134-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3039.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" When copying with "rep movsb", if the distance between source and destination is [1..63], performance may be very slow on some processors with AVX or AVX512. Update memmove-vec-unaligned-erms.S for AVX and AVX512 versions with the distance in RCX: cmpq $63, %rcx // Don't use "rep movsb" if RCX <= 63 jbe L(Don't use rep movsb") Use "rep movsb" Benchtests data with bench-memcpy, bench-memcpy-large, bench-memcpy-random and bench-memcpy-walk on Skylake, Ice Lake and Tiger Lake shows that its performance impact is within noise range since "rep movsb" is only used for data size >= 4KB. --- .../multiarch/memmove-vec-unaligned-erms.S | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S index bd5dc1a3f3..e796072855 100644 --- a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S +++ b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S @@ -56,6 +56,13 @@ # endif #endif +/* Avoid overlap of rep movsb only with non-SSE vector. */ +#ifndef AVOID_OVERLAP_REP_MOVSB +# define AVOID_OVERLAP_REP_MOVSB (VEC_SIZE > 16) +#else +# define AVOID_OVERLAP_REP_MOVSB 0 +#endif + #ifndef PREFETCH # define PREFETCH(addr) prefetcht0 addr #endif @@ -243,7 +250,21 @@ L(movsb): cmpq %r9, %rdi /* Avoid slow backward REP MOVSB. */ jb L(more_8x_vec_backward) +# if AVOID_OVERLAP_REP_MOVSB + movq %rdi, %rcx + subq %rsi, %rcx + jmp 2f +# endif 1: +# if AVOID_OVERLAP_REP_MOVSB + movq %rsi, %rcx + subq %rdi, %rcx +2: +/* Avoid "rep movsb" if RCX, the distance between source and destination, + is [1..63]. */ + cmpq $63, %rcx + jbe L(more_2x_vec) /* Avoid "rep movsb" if ECX <= 63. */ +# endif mov %RDX_LP, %RCX_LP rep movsb L(nop):