Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1206429rdb; Mon, 4 Sep 2023 06:27:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcVST/b5nEioIflpu/Vk4sbQyms/gYRwUZXec9s80Rr61VMUv8qw+7fMgTm0W5IEGTVIvQ X-Received: by 2002:a9d:4d84:0:b0:6bd:63b:4b21 with SMTP id u4-20020a9d4d84000000b006bd063b4b21mr9640401otk.15.1693834050250; Mon, 04 Sep 2023 06:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693834050; cv=none; d=google.com; s=arc-20160816; b=po9PD+EMf2+OUcrBtSRDfgyoBdcnQh9g1Psi4k+I7+7O9cy/qp7NJgpka4UrRigRJH yzFQyGaXpmb07+QL3LrilvSepRo2rYt4xQBTku4N2WXFZAtt9669HHkSokPrjaWQM6Au OFGLpAqGPjsOWRdqAw3D/giVAMd2G5LhiEOVTqpGCA1cMR65oRrstZgHhCCveBWMQCi/ eJKtU2CKuVfUT/c2PMgFft4+yWluiOQu4umeyxU++Y1MJdzGrzxV+8W4twtHCiz/zDrL aux/MxB0/n5dncY/5dODZQgevyMyJ3YzVMUPwqskPOlL2nXPHHY6qz2b1Uqx6w+kfeVw FBLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=iqVALH+CyAseGn8QlH3205BYOJT8eFMDcREhQ/Jx0ho=; fh=ByPhzHTiNZD6pFXRZ2Mg9vqJ0b+hMU9dk05U4pjfTBw=; b=NVWfcI85hASo1vQuR+KeBPbT6c5sJzua9bzlcpAjO3p/igDR4JvAu71jhVL9WPPghs Z2C7Q7BKko+oEStwwEecqWbddF9L5lKYirAIGIDp7LF+ueh2SGGmwcKt8GUAVGNOyQh1 xmpPf7EHhiy4cyBwS/sWCxw34X80oPQM9qC65qOZAscuBaU4SKX8EyzNiV6ppoID6CvO 9wRAkdVbTe+9nKFJULSmpLmZnWD6bavVWi8SutpgOMvS8hrOs2FYxMgutyeYMcV5s3Qd o+f0+jBKAbTqUYMhIpOMoSgKraJ4xjirTYqYlLtRlYzZgaeOQgmu0UcmtkRzVBiOKefK 0HRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a17090a348a00b002734f48cfd6si5950896pjb.155.2023.09.04.06.27.16; Mon, 04 Sep 2023 06:27:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349178AbjIALe2 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 1 Sep 2023 07:34:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbjIALe1 (ORCPT ); Fri, 1 Sep 2023 07:34:27 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C1BA91 for ; Fri, 1 Sep 2023 04:34:24 -0700 (PDT) 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: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ammar Faizi > Sent: 30 August 2023 14:57 > > This is an RFC patchset for nolibc x86-64 string functions. There are 5 > patches in this series. > > ## 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. > ... > 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 if (dst - src < len) backards_copy() else formwards_copy() David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)