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 DD8D1C83F22 for ; Wed, 30 Aug 2023 18:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234136AbjH3SgN (ORCPT ); Wed, 30 Aug 2023 14:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245507AbjH3PXq (ORCPT ); Wed, 30 Aug 2023 11:23:46 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E92783 for ; Wed, 30 Aug 2023 08:23:40 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 37UFNMms027896; Wed, 30 Aug 2023 17:23:22 +0200 Date: Wed, 30 Aug 2023 17:23:22 +0200 From: Willy Tarreau To: Ammar Faizi Cc: Alviro Iskandar Setiawan , Thomas =?iso-8859-1?Q?Wei=DFschuh?= , Nicholas Rosenberg , Michael William Jonathan , GNU/Weeb Mailing List , Linux Kernel Mailing List Subject: Re: [RFC PATCH v1 2/5] tools/nolibc: x86-64: Use `rep stosb` for `memset()` Message-ID: References: <20230830135726.1939997-1-ammarfaizi2@gnuweeb.org> <20230830135726.1939997-3-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 30, 2023 at 10:09:51PM +0700, Ammar Faizi wrote: > On Wed, Aug 30, 2023 at 09:24:45PM +0700, Alviro Iskandar Setiawan wrote: > > Just a small idea to shrink this more, "mov %rdi, %rdx" and "mov %rdx, > > %rax" can be replaced with "push %rdi" and "pop %rax" (they are just a > > byte). So we can save 4 bytes more. > > > > 0000000000001500 : > > 1500: 48 89 f0 mov %rsi,%rax > > 1503: 48 89 d1 mov %rdx,%rcx > > 1506: 57 push %rdi > > 1507: f3 aa rep stos %al,%es:(%rdi) > > 1509: 58 pop %rax > > 150a: c3 ret > > > > But I know you don't like it because it costs extra memory access. > > Yes, that's an extra memory access. But I believe it doesn't hurt > someone targetting -Os. In many cases, the compilers use push/pop to > align the stack before a 'call' instruction. If they want to avoid extra > memory access, they could have used "subq $8, %rsp" and "addq $8, %rsp". Then "xchg %esi, %eax" is just one byte with no memory access ;-) Willy