From patchwork Wed Jun 29 22:12:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1650404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=npJ7OuJ+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LYG1b4RhXz9s2R for ; Thu, 30 Jun 2022 08:13:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FE1E386F0CB for ; Wed, 29 Jun 2022 22:13:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FE1E386F0CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1656540785; bh=Oz42+fv4qjIdzBdQdU/n0db8Cox8Gho3fzfuZ9hr6S4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=npJ7OuJ+A4tqsLwLOcKv0VuY+gyTeZmWAD80DgTGLptc+8j6ItMZknm1xTH0wDcqR vhQgGOYpUbZoXmckZKRbG9usKxKTSgmmIc4ydCtGOaEZlA72s3ieQRvAxZFcBa8iUO zWF3F1tr73sdcT2CQA4HkMyvDRbZFniWr8YEjnN4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id C2A8D38485AF for ; Wed, 29 Jun 2022 22:12:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2A8D38485AF Received: by mail-pj1-x1036.google.com with SMTP id a11-20020a17090acb8b00b001eca0041455so1776335pju.1 for ; Wed, 29 Jun 2022 15:12:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Oz42+fv4qjIdzBdQdU/n0db8Cox8Gho3fzfuZ9hr6S4=; b=1GyLe+aX8zWscpx2zm5BxtLsqgQyOb0aYSpiYcLqtzt03dnoi2fxg0R3r+4K5wcZfM VrkRvnVKP+qtMpS37Ph36QeY+iWepg4fX85bp0Hy0ebXgvES56lTcXbFaiz05gsAX5pI SYrCLprTGaKNz2tDQbCG2cm7FPJNgWzJJMtUk03Err0Fxaj7kXBo2DAaCTkuj+re+ZcH Mt/wNc8tTl4dOUiBdhwDNlotdklXqlufzvhoXmKqjwgolD3ElYCwGBkTXw3E3TiIevZW JTpnGCShluNve3NCxOaQagn44Uh9sZVJBZ0f5lSthravkLS/m22/AGftDXm5svnxGa2+ tsiQ== X-Gm-Message-State: AJIora8SMgLAIxowoM1Tz9QwokoPBKzBd/CL1ZFTAqgS1njyxvxK+Pg8 ftz8+Nwei47McAMaxjpR5ExL6HIjTIQ= X-Google-Smtp-Source: AGRyM1v2gwewSRxa9agoUkkv7uRRUc2Z3TLUSJNjlZSIHcqOU6Aiv3HQUhLGDeXkK3VpmMAvF0FIwA== X-Received: by 2002:a17:903:18a:b0:16a:6294:480e with SMTP id z10-20020a170903018a00b0016a6294480emr12676363plg.95.1656540728688; Wed, 29 Jun 2022 15:12:08 -0700 (PDT) Received: from noah-tgl.. ([192.55.60.43]) by smtp.gmail.com with ESMTPSA id k11-20020a6555cb000000b0040d87299ca3sm11638782pgs.54.2022.06.29.15.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 15:12:08 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/3] x86: Move and slightly improve memset_erms Date: Wed, 29 Jun 2022 15:12:03 -0700 Message-Id: <20220629221204.1242709-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220629221204.1242709-1-goldstein.w.n@gmail.com> References: <20220628152735.17863-1-goldstein.w.n@gmail.com> <20220629221204.1242709-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Implementation wise: 1. Remove the VZEROUPPER as memset_{impl}_unaligned_erms does not use the L(stosb) label that was previously defined. 2. Don't give the hotpath (fallthrough) to zero size. Code positioning wise: Move memset_{chk}_erms to its own file. Leaving it in between the memset_{impl}_unaligned both adds unnecessary complexity to the file and wastes space in a relatively hot cache section. --- sysdeps/x86_64/multiarch/Makefile | 1 + sysdeps/x86_64/multiarch/memset-erms.S | 25 +++++++++++++++ .../multiarch/memset-vec-unaligned-erms.S | 31 ------------------- 3 files changed, 26 insertions(+), 31 deletions(-) create mode 100644 sysdeps/x86_64/multiarch/memset-erms.S diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile index 62a4d96fb8..18cea04423 100644 --- a/sysdeps/x86_64/multiarch/Makefile +++ b/sysdeps/x86_64/multiarch/Makefile @@ -30,6 +30,7 @@ sysdep_routines += \ memset-avx2-unaligned-erms-rtm \ memset-avx512-no-vzeroupper \ memset-avx512-unaligned-erms \ + memset-erms \ memset-evex-unaligned-erms \ memset-sse2-unaligned-erms \ rawmemchr-avx2 \ diff --git a/sysdeps/x86_64/multiarch/memset-erms.S b/sysdeps/x86_64/multiarch/memset-erms.S new file mode 100644 index 0000000000..1fce0c9fcc --- /dev/null +++ b/sysdeps/x86_64/multiarch/memset-erms.S @@ -0,0 +1,25 @@ +#include + +#if defined USE_MULTIARCH && IS_IN (libc) + .text +ENTRY (__memset_chk_erms) + cmp %RDX_LP, %RCX_LP + jb HIDDEN_JUMPTARGET (__chk_fail) +END (__memset_chk_erms) + +/* Only used to measure performance of REP STOSB. */ +ENTRY (__memset_erms) + /* Skip zero length. */ + test %RDX_LP, %RDX_LP + jz L(stosb_return_zero) + mov %RDX_LP, %RCX_LP + movzbl %sil, %eax + mov %RDI_LP, %RDX_LP + rep stosb + mov %RDX_LP, %RAX_LP + ret +L(stosb_return_zero): + movq %rdi, %rax + ret +END (__memset_erms) +#endif diff --git a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S index abc12d9cda..905d0fa464 100644 --- a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S +++ b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S @@ -156,37 +156,6 @@ L(entry_from_wmemset): #if defined USE_MULTIARCH && IS_IN (libc) END (MEMSET_SYMBOL (__memset, unaligned)) -# if VEC_SIZE == 16 -ENTRY (__memset_chk_erms) - cmp %RDX_LP, %RCX_LP - jb HIDDEN_JUMPTARGET (__chk_fail) -END (__memset_chk_erms) - -/* Only used to measure performance of REP STOSB. */ -ENTRY (__memset_erms) - /* Skip zero length. */ - test %RDX_LP, %RDX_LP - jnz L(stosb) - movq %rdi, %rax - ret -# else -/* Provide a hidden symbol to debugger. */ - .hidden MEMSET_SYMBOL (__memset, erms) -ENTRY (MEMSET_SYMBOL (__memset, erms)) -# endif -L(stosb): - mov %RDX_LP, %RCX_LP - movzbl %sil, %eax - mov %RDI_LP, %RDX_LP - rep stosb - mov %RDX_LP, %RAX_LP - VZEROUPPER_RETURN -# if VEC_SIZE == 16 -END (__memset_erms) -# else -END (MEMSET_SYMBOL (__memset, erms)) -# endif - # if defined SHARED && IS_IN (libc) ENTRY_CHK (MEMSET_CHK_SYMBOL (__memset_chk, unaligned_erms)) cmp %RDX_LP, %RCX_LP