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.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED, URIBL_DBL_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1693538690; bh=lvnF0NOioC9hcEBmjIlB6eZdb2DagR47ohWj1HFUj7I=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=IuSjWtWzsN8PDqYm+quJR1KNOlhrCoHO/XB+ubKd+1mV6PDy4ZxfR6176TKztawxn IhEpEFiyORLVW7e5BNku4jWx0xW0h93lUuTKFyzUqcGbwu3CVOy87dYItgcreQHFDO oKctO3THuzBmoJVhWiNnhnQPkITLtKNc/rw9Df6lL0d9RqSTwieccDupZyEmSl6rh1 wkcb0SEiBIn39qo9jmN7CZNL4DBc9jm2nPU4iUVuGhTUyh0NIcga6sFjpNa5LzOsD8 iHIKBM8H20r+MYCjlBsUgFwU36o260C87vJO5zgyLebW19a51rOkxyCwInpDwnecUR A/lSi2oLl1Phg== Received: from biznet-home.integral.gnuweeb.org (unknown [182.253.126.208]) by gnuweeb.org (Postfix) with ESMTPSA id 872EC24B372; Fri, 1 Sep 2023 10:24:47 +0700 (WIB) Date: Fri, 1 Sep 2023 10:24:42 +0700 From: Ammar Faizi To: Willy Tarreau 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-Bpl: hUx9VaHkTWcLO7S8CQCslj6OzqBx2hfLChRz45nPESx5VSB/xuJQVOKOB1zSXE3yc9ntP27bV1M1 List-Id: 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. > 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. -- Ammar Faizi