From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C34DFCA0FFC for ; Sat, 2 Sep 2023 06:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351655AbjIBGW4 (ORCPT ); Sat, 2 Sep 2023 02:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbjIBGW4 (ORCPT ); Sat, 2 Sep 2023 02:22:56 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8948B10F9 for ; Fri, 1 Sep 2023 23:22:52 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3826MbQZ023182; Sat, 2 Sep 2023 08:22:37 +0200 Date: Sat, 2 Sep 2023 08:22:37 +0200 From: Willy Tarreau To: Ammar Faizi Cc: Alviro Iskandar Setiawan , Thomas =?iso-8859-1?Q?Wei=DFschuh?= , David Laight , Nicholas Rosenberg , Michael William Jonathan , GNU/Weeb Mailing List , Linux Kernel Mailing List Subject: Re: [RFC PATCH v2 1/4] tools/nolibc: x86-64: Use `rep movsb` for `memcpy()` and `memmove()` Message-ID: <20230902062237.GA23141@1wt.eu> References: <20230902055045.2138405-1-ammarfaizi2@gnuweeb.org> <20230902055045.2138405-2-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 02, 2023 at 01:11:06PM +0700, Ammar Faizi wrote: > On Sat, Sep 02, 2023 at 01:07:50PM +0700, Alviro Iskandar Setiawan wrote: > > Btw, sir, this can be simplified more by merging the forward copy > > path, only using two "rep movsb" for both memmove() and memcpy() > > should be enough? > > ``` > > __asm__ ( > > ".section .text.nolibc_memmove_memcpy\n" > > ".weak memmove\n" > > ".weak memcpy\n" > > "memmove:\n" > > "movq %rdx, %rcx\n" > > "movq %rdi, %rdx\n" > > "movq %rdi, %rax\n" > > "subq %rsi, %rdx\n" > > "cmpq %rcx, %rdx\n" > > "jnb __nolibc_forward_copy\n" > > "leaq -1(%rdi, %rcx, 1), %rdi\n" > > "leaq -1(%rsi, %rcx, 1), %rsi\n" > > "std\n" > > "rep movsb\n" > > "cld\n" > > "retq\n" > > > > "memcpy:\n" > > "movq %rdi, %rax\n" > > "movq %rdx, %rcx\n" > > "__nolibc_forward_copy:\n" > > "rep movsb\n" > > "retq\n" > > ); > > ``` > > Looks good. I'll apply that change. Note that in this case we simply don't need a special version of memcpy(), memmove() is always OK for this, so you can simplify this further by starting with: memcpy: memmove: ... Willy