From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=1.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, PDS_BAD_THREAD_QP_64,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Authentication-Results: gnuweeb.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.58.86.151; helo=eu-smtp-delivery-151.mimecast.com; envelope-from=david.laight@aculab.com; receiver= Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by gnuweeb.org (Postfix) with ESMTPS id 288FB24B384 for ; Fri, 1 Sep 2023 18:34:24 +0700 (WIB) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-91-Ii1bV-p4PeKtO_W6zNK67Q-1; Fri, 01 Sep 2023 12:34:21 +0100 X-MC-Unique: Ii1bV-p4PeKtO_W6zNK67Q-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 1 Sep 2023 12:34:18 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 1 Sep 2023 12:34:18 +0100 From: David Laight To: 'Ammar Faizi' , Willy Tarreau , =?iso-8859-1?Q?Thomas_Wei=DFschuh?= CC: Nicholas Rosenberg , Alviro Iskandar Setiawan , Michael William Jonathan , GNU/Weeb Mailing List , Linux Kernel Mailing List Subject: RE: [RFC PATCH v1 0/5] nolibc x86-64 string functions Thread-Topic: [RFC PATCH v1 0/5] nolibc x86-64 string functions Thread-Index: AQHZ23UUaWogkrxxpUapKlllYL+KVbAF2IcQ Date: Fri, 1 Sep 2023 11:34:18 +0000 Message-ID: <5a821292d96a4dbc84c96ccdc6b5b666@AcuMS.aculab.com> References: <20230830135726.1939997-1-ammarfaizi2@gnuweeb.org> In-Reply-To: <20230830135726.1939997-1-ammarfaizi2@gnuweeb.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: From: Ammar Faizi > Sent: 30 August 2023 14:57 >=20 > This is an RFC patchset for nolibc x86-64 string functions. There are 5 > patches in this series. >=20 > ## Patch 1-3: Use `rep movsb`, `rep stosb`, and `rep cmpsb` for: > - memcpy() and memmove() > - memset() > - memcmp() > respectively. They can simplify the generated ASM code. >=20 ... > After this series: > ``` > 000000000000140a : > 140a: 48 89 f8 mov %rdi,%rax > 140d: 48 89 d1 mov %rdx,%rcx > 1410: 48 8d 7c 0f ff lea -0x1(%rdi,%rcx,1),%rdi > 1415: 48 8d 74 0e ff lea -0x1(%rsi,%rcx,1),%rsi > 141a: fd std > 141b: f3 a4 rep movsb %ds:(%rsi),%es:(%rdi) > 141d: fc cld > 141e: c3 ret Isn't that completely broken? You need to select between forwards and backwards moves. Since forwards moves are preferred it is best to do =09if (dst - src < len) =09=09backards_copy() =09else =09=09formwards_copy() =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)