Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp832970rdb; Fri, 1 Sep 2023 05:45:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBFxOG3G09sD1/d/B6oKJyUc+cRoL4BViN1MPCaBHXSa5TOSAY4haRq0sZw0m22zXAwncZ X-Received: by 2002:a17:906:ef8f:b0:9a5:8eab:49da with SMTP id ze15-20020a170906ef8f00b009a58eab49damr1611783ejb.19.1693572302517; Fri, 01 Sep 2023 05:45:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693572302; cv=none; d=google.com; s=arc-20160816; b=uHrsKiMmyAKpL+5BbVaioXS7yrjttUKnSj5/Ek4rycIQ5LmWjU+arNhPzLYgz3Y9J4 s48htzw06Z1+GIw54fB+ysYtljOT3SbE75QaRVj8Zc4HUJuQpDaVALgNOg6+sjWza4Z9 xf1cJcTPnPsz/UvT1n5S448H0YFQsQE6wHDMn1ev9RNxg6bEUhsnZgdZwFSobcjbUsaM hLaKOYS+HfdT5Y6EnarrQmQq6S5SXeGpsE3Gq8zOW/UfOPiRxAkzLxTzx7yoAIBJQrA4 jVAd4Vlt0LzFsUp/Zv8k3mieQvdtKxSE2zmrsb6fd9SYR2Q/i2tq+E5HznXdla0sthlu 4iDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=CozY9Hp1EtIrtjYdi1rHj+tYP9xcSdnyNU+UT7K8qFQ=; fh=F4w2umFRHnFS4gCHrY2leGXavN+Ya3Xwf4sKQAdEscY=; b=uKwIvGEnX9eHPqodZjEfrJJoML1yZN2cLOkv/S2mhpkMFM1O2g3nigstWU2iIuvaFZ Bs2jgVrl1cuOauUHLOAGl57okpwxdus/oxYIjNy9gwTHQGGbb9esPJqDnJz/5xIyZcCt vT6NyhO7hht9ArbHsPQwKDqAd0g0buZn7z8z3G0ypxckPk6f/WRcY9lAFJUpQ4FXH7TW hfiCmAwvuLVBZvsVxJwW1ZIFih0ncGcxc4dV1msvYC1qDqI8+TFsyUHO8GqCsulldy04 8Zv0ihq/WaHrGtY9wqNwwDpN3YYhVenTTBLcBtsb/8kyJMD//0WFFqulmc1IHflYLP6P LxCA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y22-20020a170906449600b0099cad5caa77si2280796ejo.22.2023.09.01.05.44.35; Fri, 01 Sep 2023 05:45:02 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345138AbjIADfe (ORCPT + 99 others); Thu, 31 Aug 2023 23:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjIADfe (ORCPT ); Thu, 31 Aug 2023 23:35:34 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7571FCF for ; Thu, 31 Aug 2023 20:35:27 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 3813Z8tH015864; Fri, 1 Sep 2023 05:35:08 +0200 Date: Fri, 1 Sep 2023 05:35:08 +0200 From: Willy Tarreau To: Ammar Faizi Cc: Thomas =?iso-8859-1?Q?Wei=DFschuh?= , Nicholas Rosenberg , Alviro Iskandar Setiawan , Michael William Jonathan , GNU/Weeb Mailing List , Linux Kernel Mailing List Subject: Re: [RFC PATCH v1 3/5] tools/nolibc: x86-64: Use `rep cmpsb` for `memcmp()` Message-ID: References: <20230830135726.1939997-1-ammarfaizi2@gnuweeb.org> <20230830135726.1939997-4-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,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 On Fri, Sep 01, 2023 at 10:24:42AM +0700, Ammar Faizi wrote: > On Wed, Aug 30, 2023 at 11:26:57PM +0200, Willy Tarreau wrote: > > Out of curiosity, given that you implemented the 3 other ones directly > > in an asm statement, is there a particular reason this one mixes a bit > > of C and asm ? > > Because this one maybe unused. The other are explicitly exported. Makes sense, indeed. > > It would probably be something around this, in the same vein: > > > > memcmp: > > xchg %esi,%eax // source1 > > mov %rdx,%rcx // count > > rep cmpsb // source2 in rdi; sets ZF on equal, CF if src1 > seta %al // 0 if src2 <= src1, 1 if src2 > src1 > > sbb $0, %al // 0 if src2 == src1, -1 if src2 < src1, 1 if src2 > src1 > > movsx %al, %eax // sign extend to %eax > > ret > > > > Note that the output logic could have to be revisited, I'm not certain but > > at first glance it looks valid. > > After thinking about this more, I think I'll drop the memcmp() patch > because it will prevent optimization when comparing a small value. > > For example, without __asm__: > > memcmp(var, "abcd", 4); > > may compile to: > > cmpl $0x64636261, %reg > ...something... > > But with __asm__, the compiler can't do that. Thus, it's not worth > optimizing the memcmp() in this case. Ah you're totally right! Willy