From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gsi.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gsi.de 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 From: Matthias Kretz 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 Content-Type: multipart/mixed; boundary="nextPart3407573.QJadu78ljV" Content-Transfer-Encoding: 7Bit 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 List-Id: --nextPart3407573.QJadu78ljV Content-Transfer-Encoding: base64 Content-Type: text/plain; charset="UTF-8" CgpTaWduZWQtb2ZmLWJ5OiBNYXR0aGlhcyBLcmV0eiA8bS5rcmV0ekBnc2kuZGU+CgpsaWJzdGRj KystdjMvQ2hhbmdlTG9nOgoKCVBSIGxpYnN0ZGMrKy8xMDg4NTYKCSogaW5jbHVkZS9leHBlcmlt ZW50YWwvYml0cy9zaW1kX2J1aWx0aW4uaAoJKF9TaW1kSW1wbEJ1aWx0aW46Ol9TX21hc2tlZF91 bmFyeSk6IE1vcmUgZWZmaWNpZW50CglpbXBsZW1lbnRhdGlvbiBvZiBtYXNrZWQgaW5jLS9kZWNy ZW1lbnQgZm9yIGludGVnZXJzIGFuZCBmbG9hdHMKCXdpdGhvdXQgQVZYMi4KCSogaW5jbHVkZS9l eHBlcmltZW50YWwvYml0cy9zaW1kX3g4Ni5oCgkoX1NpbWRJbXBsWDg2OjpfU19tYXNrZWRfdW5h cnkpOiBOZXcuIFVzZSBBVlg1MTIgbWFza2VkIHN1YnRyYWN0CglidWlsdGlucyBmb3IgbWFza2Vk IGluYy0vZGVjcmVtZW50LgotLS0KIC4uLi9pbmNsdWRlL2V4cGVyaW1lbnRhbC9iaXRzL3NpbWRf YnVpbHRpbi5oICB8IDI3ICsrKysrKystCiAuLi4vaW5jbHVkZS9leHBlcmltZW50YWwvYml0cy9z aW1kX3g4Ni5oICAgICAgfCA2OCArKysrKysrKysrKysrKysrKysrCiAyIGZpbGVzIGNoYW5nZWQs IDkzIGluc2VydGlvbnMoKyksIDIgZGVsZXRpb25zKC0pCgoKLS0K4pSA4pSA4pSA4pSA4pSA4pSA 4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA 4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA 4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA 4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSACiBEci4gTWF0dGhpYXMgS3JldHogICAg ICAgICAgICAgICAgICAgICAgICAgICBodHRwczovL21hdHRrcmV0ei5naXRodWIuaW8KIEdTSSBI ZWxtaG9sdHogQ2VudHJlIGZvciBIZWF2eSBJb24gUmVzZWFyY2ggICAgICAgICAgICAgICBodHRw czovL2dzaS5kZQogc3Rk4oKTOjpzaW1kCuKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgA== --nextPart3407573.QJadu78ljV Content-Disposition: inline; filename="0003-libstdc-More-efficient-masked-inc-decrement-implemen.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="0003-libstdc-More-efficient-masked-inc-decrement-implemen.patch" 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