From patchwork Tue Jun 6 12:29:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kretz X-Patchwork-Id: 103778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3356507vqr; Tue, 6 Jun 2023 05:30:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ671HRNmGWZkO2NgMwQ+3PIUITwmEfb1DXxEEjD32aLhZFOCQNO5Z662yogWqW4nqXGlkmh X-Received: by 2002:a05:6402:31e4:b0:50d:975f:3729 with SMTP id dy4-20020a05640231e400b0050d975f3729mr2172299edb.11.1686054612995; Tue, 06 Jun 2023 05:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686054612; cv=none; d=google.com; s=arc-20160816; b=Zm+ZvtNzkpRmNcE7i6Pigs+o00LmXGh/2JdoIt2bNu5cvvoonO2e7vXFTwUUGnbjTu N4rfrM7rX+K9d+9aRS++uaH0wgQ6yYupRu1wL1318QrZ0WkoiuZJ3REMDnCJL+MbBZls 7gma+s5LIpouz0rZJuXGRgzLxuX9RICXltwxPhUTFQXTdd3MqgcgAK8E8kRpPUtydEjc 8LUbrtgQCn2yX9gpA7YK/EDkooMesF551Wnt2DCKCK77KgicTUyuCNzF8pC51/D2hX83 qDLz/oBAUqfm6TpaJwE8py5p1NAZv22ZfOEBt6bYuWIPSl3nxAgn/V/YNNi5FNS70egX buLg== 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:organization:message-id:date :subject:to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UBz8ewcRXao2q9mzcZBjY/jFoarUo+bTvbVmwjsyNNo=; b=Kc69jISvP1Usy3Tpmp5+giJ0tQq3Y9HraGFRFLyps52QLPTDGZPj60hhgXgvK82Qwa 8+MZRXK4fuLKSKzbr+ncio6OMiLsiU4gPwKDE0dKzeNJAojyGSeR6yHas+VArWBtSA9s KPLGpFDSGwIgukLHqf9OY3LMiwyLL2oFHHF3XegadBt6vLBoGHP54AFXo6thTvCTTODD C4+N5bnPJgS4MnMwnIwswNOr2y3xNTpBeqyZ0otZcxga9PFI4PHVT7t57TyZlRmJdLcO ZMbxSzvI3Rp35Sg9ZvupONaQE9FU8Lxwaa9E0tzJjtEqg71od9DTv23E8lkEUH4LQMTI G5aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WN2nhGnp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d12-20020aa7d5cc000000b00514b37ff886si6536884eds.512.2023.06.06.05.30.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 05:30:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WN2nhGnp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 822F23857723 for ; Tue, 6 Jun 2023 12:30:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 822F23857723 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686054600; bh=UBz8ewcRXao2q9mzcZBjY/jFoarUo+bTvbVmwjsyNNo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WN2nhGnp1F6fuph65lhbOS/2sRERXEc+jTaxXzLGQeLd+ARaRO6VckgWmkSMB+JAN fF1aqL8OUc4NjdnqsCk8l91zJSgq2+vudOP43UybqpPobrDDe+7t4S8h26cI476tnn /Yzt7JZkD5mJhC4Ckt3DMi8AfjjxoNMa3+OeZdpA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from lxmtout1.gsi.de (lxmtout1.gsi.de [140.181.3.111]) by sourceware.org (Postfix) with ESMTPS id 5A2353858D33; Tue, 6 Jun 2023 12:29:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A2353858D33 Received: from localhost (localhost [127.0.0.1]) by lxmtout1.gsi.de (Postfix) with ESMTP id 9404F2051049; Tue, 6 Jun 2023 14:29:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lxmtout1.gsi.de Received: from lxmtout1.gsi.de ([127.0.0.1]) by localhost (lxmtout1.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 04xaa6ZXk-iD; Tue, 6 Jun 2023 14:29:17 +0200 (CEST) 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 lxmtout1.gsi.de (Postfix) with ESMTPS id 79AC32051040; Tue, 6 Jun 2023 14:29:17 +0200 (CEST) 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.26; Tue, 6 Jun 2023 14:29:17 +0200 To: , Subject: [PATCH] libstdc++: Avoid vector casts while still avoiding PR90424 Date: Tue, 6 Jun 2023 14:29:16 +0200 Message-ID: <6348100.iIbC2pHGDl@minbar> Organization: GSI Helmholtz Centre for Heavy Ion Research MIME-Version: 1.0 X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvEX7.Campus.gsi.de (10.10.4.97) To srvEX6.campus.gsi.de (10.10.4.96) X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, SPF_HELO_PASS, 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: 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?1767956401779284911?= X-GMAIL-MSGID: =?utf-8?q?1767956401779284911?= This is the first part of a fix for the failure of the new simd test on non- VSX POWER targets. There are more casts to unavailable vectors of 64-bit element types to be rewritten. OK for master and backports? Tested on x86_64-pc-linux-gnu and powerpc64le-linux-gnu ------ >8 ------- Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/109822 * include/experimental/bits/simd_builtin.h (_S_store): Rewrite to avoid casts to other vector types. Implement store as succession of power-of-2 sized memcpy to avoid PR90424. --- .../include/experimental/bits/simd_builtin.h | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 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 64ef6efaf8c..6ccc2fcec9c 100644 --- a/libstdc++-v3/include/experimental/bits/simd_builtin.h +++ b/libstdc++-v3/include/experimental/bits/simd_builtin.h @@ -1295,6 +1295,18 @@ _S_load(const void* __p) // }}} // _S_store {{{ + template + _GLIBCXX_SIMD_INTRINSIC static void + _S_memcpy(char* __dst, const char* __src) + { + if constexpr (_Bytes > 0) + { + constexpr size_t _Ns = std::__bit_floor(_Bytes); + __builtin_memcpy(__dst, __src, _Ns); + _S_memcpy<_Bytes - _Ns>(__dst + _Ns, __src + _Ns); + } + } + template _GLIBCXX_SIMD_INTRINSIC static void _S_store(_TV __x, void* __addr) @@ -1302,33 +1314,11 @@ _S_store(_TV __x, void* __addr) constexpr size_t _Bytes = _ReqBytes == 0 ? sizeof(__x) : _ReqBytes; static_assert(sizeof(__x) >= _Bytes); +#if !defined __clang__ && _GLIBCXX_SIMD_WORKAROUND_PR90424 if constexpr (__is_vector_type_v<_TV>) - { - using _Tp = typename _VectorTraits<_TV>::value_type; - constexpr size_t _Np = _Bytes / sizeof(_Tp); - static_assert(_Np * sizeof(_Tp) == _Bytes); - -#ifdef _GLIBCXX_SIMD_WORKAROUND_PR90424 - using _Up = conditional_t< - (is_integral_v<_Tp> || _Bytes < 4), - conditional_t<(sizeof(__x) > sizeof(long long)), long long, _Tp>, - float>; - const auto __v = __vector_bitcast<_Up>(__x); -#else // _GLIBCXX_SIMD_WORKAROUND_PR90424 - const __vector_type_t<_Tp, _Np> __v = __x; -#endif // _GLIBCXX_SIMD_WORKAROUND_PR90424 - - if constexpr ((_Bytes & (_Bytes - 1)) != 0) - { - constexpr size_t _MoreBytes = std::__bit_ceil(_Bytes); - alignas(decltype(__v)) char __tmp[_MoreBytes]; - __builtin_memcpy(__tmp, &__v, _MoreBytes); - __builtin_memcpy(__addr, __tmp, _Bytes); - } - else - __builtin_memcpy(__addr, &__v, _Bytes); - } + _S_memcpy<_Bytes>(reinterpret_cast(__addr), reinterpret_cast(&__x)); else +#endif // _GLIBCXX_SIMD_WORKAROUND_PR90424 __builtin_memcpy(__addr, &__x, _Bytes); }