From patchwork Thu Feb 23 08:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kretz X-Patchwork-Id: 60853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp208337wrd; Thu, 23 Feb 2023 00:57:06 -0800 (PST) X-Google-Smtp-Source: AK7set88UQhC2DIwUWesaQMT17HCXDkqCRbAW8biK4vAjHYVqOjPMWMFol6MFvajTwDgor4SGlf+ X-Received: by 2002:a05:6402:1253:b0:4ad:7c44:c46b with SMTP id l19-20020a056402125300b004ad7c44c46bmr11875986edw.40.1677142625870; Thu, 23 Feb 2023 00:57:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677142625; cv=none; d=google.com; s=arc-20160816; b=cECvYJ2610z60UhHS6UL7sWF4Sq/Tp6oXpqeOyVKsky5gWC9ZykRj1A1StR7LiCGXM Yn6lhqfuGzMqyJ8tOgI3/jhmAjG4CKB90/RLFKZopA/6hiArdgy5tXdnX65rkbPCpBRj d9D8Ay8JFQ/XU3HYxE+E8Uq5Xa8I002XlR+Mj1uyHDFhpvd765LEjJLX9Ur4SMTKtYB/ sIXf457CRMfqnVTReqy1dhnjOUyc3SZ0S5KDzGxfp0gsYjWbMd9pi6IrDY9xhkV15OgT acKMJDwYa0csmu2GG/hBQc8DBwN6qm7bcPUkoGsBqqWeWM4UPWnZMK9428f+C/owcyB2 +R3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :organization:message-id:date:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=zX8dr5qOgmtA+vcXCkCgVpBSXm1YyZ+Dwn4bVYAREFM=; b=J0NHPtCWJiRpPXqVGNwOEhgj5OWLHr27EhLJ0piQl6parj3Mf7jTmg3gq4xA+fffW3 dpumaJ2RHoqCM23xhOmATmGe0iZIHRdjh/1V/lMZ+VYZm047Qn7kbvtj4hSqGojkMmoj qI4i8xwOnQ9ovF3FS7xZC/04pyxRLLKyg6TQwkjXlROyV5CrhPl9v7nla+BA8plS66lW Ivzr7VlfwO7cn8GA+oMaac9NNgQaogCN42XGPGz+yZ4g1olePOaL19RIDTWT7YXiN7Im ievvEpL3GThxRXBagYcyLaSk7IjtWu/BqE2ukUQ+dfh5MWOS8npvF1ynenN5RieAPwdN I3QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="CaMwzUc/"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e10-20020a50fb8a000000b004aef418518asi1075113edq.282.2023.02.23.00.57.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 00:57:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="CaMwzUc/"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A6A53888832 for ; Thu, 23 Feb 2023 08:53:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A6A53888832 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677142421; bh=zX8dr5qOgmtA+vcXCkCgVpBSXm1YyZ+Dwn4bVYAREFM=; 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=CaMwzUc/kO/XCW8p67xeDxwnnVl4n/CDBp1+AnvjO+kkdPgPborTGPGOEoo4pslq4 BpJ1VqL8AqlTR+reKutxr1zs7KErv5Ns1rYlRXBnvEsrM5YcmYJcfUAxsoRWAr5pmG 0CKSG8iaqxKnlPya16aNr81GDzm+RdcNh3lNWFG8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from lxmtout2.gsi.de (lxmtout2.gsi.de [140.181.3.112]) by sourceware.org (Postfix) with ESMTPS id A84923858C2C; Thu, 23 Feb 2023 08:50:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A84923858C2C Received: from localhost (localhost [127.0.0.1]) by lxmtout2.gsi.de (Postfix) with ESMTP id D17E4203E7E8; Thu, 23 Feb 2023 09:50:52 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lxmtout2.gsi.de Received: from lxmtout2.gsi.de ([127.0.0.1]) by localhost (lxmtout2.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id v5SmfN7rH0Xl; Thu, 23 Feb 2023 09:50:52 +0100 (CET) Received: from srvEX6.campus.gsi.de (unknown [10.10.4.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lxmtout2.gsi.de (Postfix) with ESMTPS id AE230203E7FB; Thu, 23 Feb 2023 09:50:52 +0100 (CET) Received: from minbar.localnet (140.181.3.12) by srvEX6.campus.gsi.de (10.10.4.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Thu, 23 Feb 2023 09:50:52 +0100 To: , Subject: [PATCH 3/8] libstdc++: More efficient masked inc-/decrement implementation Date: Thu, 23 Feb 2023 09:49:43 +0100 Message-ID: <1944554.usQuhbGJ8B@minbar> Organization: GSI Helmholtz Centre for Heavy Ion Research In-Reply-To: <2218250.iZASKD2KPV@minbar> References: <2218250.iZASKD2KPV@minbar> MIME-Version: 1.0 X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvEX8.Campus.gsi.de (10.10.4.160) To srvEX6.campus.gsi.de (10.10.4.96) X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matthias Kretz via Gcc-patches From: Matthias Kretz Reply-To: Matthias Kretz Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758611506305645455?= X-GMAIL-MSGID: =?utf-8?q?1758611506305645455?= Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/108856 * include/experimental/bits/simd_builtin.h (_SimdImplBuiltin::_S_masked_unary): More efficient implementation of masked inc-/decrement for integers and floats without AVX2. * include/experimental/bits/simd_x86.h (_SimdImplX86::_S_masked_unary): New. Use AVX512 masked subtract builtins for masked inc-/decrement. --- .../include/experimental/bits/simd_builtin.h | 27 +++++++- .../include/experimental/bits/simd_x86.h | 68 +++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) -- ────────────────────────────────────────────────────────────────────────── Dr. Matthias Kretz https://mattkretz.github.io GSI Helmholtz Centre for Heavy Ion Research https://gsi.de stdₓ::simd ────────────────────────────────────────────────────────────────────────── diff --git a/libstdc++-v3/include/experimental/bits/simd_builtin.h b/libstdc++-v3/include/experimental/bits/simd_builtin.h index 792439a81bf..4a4de4534f3 100644 --- a/libstdc++-v3/include/experimental/bits/simd_builtin.h +++ b/libstdc++-v3/include/experimental/bits/simd_builtin.h @@ -2546,8 +2546,31 @@ _S_masked_unary(const _SimdWrapper<_K, _Np> __k, _Op __op; if (__k._M_is_constprop_all_of()) return __data(__op(__vv)); - else - return _CommonImpl::_S_blend(__k, __v, __data(__op(__vv))); + else if constexpr (is_same_v<_Op, __increment>) + { + static_assert(not std::is_same_v<_K, bool>); + if constexpr (is_integral_v<_Tp>) + // Take a shortcut knowing that __k is an integer vector with values -1 or 0. + return __v._M_data - __vector_bitcast<_Tp>(__k._M_data); + else if constexpr (not __have_avx2) + return __v._M_data + + __vector_bitcast<_Tp>(__k._M_data & __builtin_bit_cast( + _K, _Tp(1))); + // starting with AVX2 it is more efficient to blend after add + } + else if constexpr (is_same_v<_Op, __decrement>) + { + static_assert(not std::is_same_v<_K, bool>); + if constexpr (is_integral_v<_Tp>) + // Take a shortcut knowing that __k is an integer vector with values -1 or 0. + return __v._M_data + __vector_bitcast<_Tp>(__k._M_data); + else if constexpr (not __have_avx2) + return __v._M_data + - __vector_bitcast<_Tp>(__k._M_data & __builtin_bit_cast( + _K, _Tp(1))); + // starting with AVX2 it is more efficient to blend after sub + } + return _CommonImpl::_S_blend(__k, __v, __data(__op(__vv))); } //}}}2 diff --git a/libstdc++-v3/include/experimental/bits/simd_x86.h b/libstdc++-v3/include/experimental/bits/simd_x86.h index dcfdc2a9496..897a67829d1 100644 --- a/libstdc++-v3/include/experimental/bits/simd_x86.h +++ b/libstdc++-v3/include/experimental/bits/simd_x86.h @@ -3462,6 +3462,74 @@ _S_islessgreater(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y) } //}}} }}} + template