From patchwork Wed May 24 15:04:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kretz X-Patchwork-Id: 98544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c790:0:b0:3b6:ef29:a0d7 with SMTP id b16csp3087820vqu; Wed, 24 May 2023 08:05:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YvSsZZ1WF9c9VxPgSoo21yBgyxYw096q1LFxnFfdmj7gc3cWbZCzml1gpeLNMRrVeYeZb X-Received: by 2002:a17:907:2d08:b0:970:1bc9:2efc with SMTP id gs8-20020a1709072d0800b009701bc92efcmr8347475ejc.74.1684940750304; Wed, 24 May 2023 08:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684940750; cv=none; d=google.com; s=arc-20160816; b=GKdEB7s1+joz4kTNcab6TR1S6lSqC66u9bLmjacQXVCExOeBvGsPwJ3ojKFcLd6zr2 zYFXTnp4ThQ1HgN2ybJyYfNQ1JgFl7lBM4htHnmG4xOMRfX5QtejrXZKVsxpA0ynDVrc jrZ/povlehx00YLK9czqYtvfWzl5e6Aq8jNLBlXQGdLMOijUg1qGSz7799nBobsORrGv 2aOIQjDNX+ut3hrWzOtx6XJz5LYdaiwvjlRog8KXJysxD4dVBZ1cSZyWr0F9HTNXjSAs ElLZEq/lfpFWDHVyI1R2r+iRh2eI0/oIRQJfePS+pKDAT56cfAEtkCWuhvNNIK2yJMIh nK7A== 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=9Fg+6TrxvPsA2Cg8LdxvFXjaxYhwH4jMzoc1oE2cXaM=; b=f958B9bvqa9br8waQOCuKnq0NoZ2b+6Xh3VDwy3cgCkWUTpUUUNo4O9yOeNyPywyaq O0XGipEISt9tclD1AYMxLp0ti/qPshb46mkpH59ouNFlQLfjWSM6LVmLxs9QWCAigNvM lXGHPrjoHd4gi1A1maS0kgjLQttCUHNBYL5PjY06ERqaw+WnqgyAimA9sb5YbGza9dwx R/j3U350ibw6LF124uB65Qjzte8DN9ROIQ8EDsTVKpOgNDJoGI6X3HOPwkE7d3PsFFen QAfydo0hAPiv8cB8XSJ18CekwCmE2zPQz58TXkgEYbxb1S81Aek88GmSNcQ6kkdSntTx Ow2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=REM+7vRU; 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 f10-20020a170906494a00b0096f8e7214e0si3471610ejt.483.2023.05.24.08.05.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 08:05:50 -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=REM+7vRU; 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 855953856954 for ; Wed, 24 May 2023 15:05:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 855953856954 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684940728; bh=9Fg+6TrxvPsA2Cg8LdxvFXjaxYhwH4jMzoc1oE2cXaM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=REM+7vRUuB5MNFOpns5Jy055ceMULyChiz4yhCtiaic3p3VbVOkR3x2z8IZWbMR2V itxlj/0PScH7CxG5VSk3bDM5eZfU0BqKGTJWFweY8aA+91WW8hI2HxsWKv4gh6+zqK B6U3jHVF1YR/5DavqB8qf9qPHCDMgBhgNKpEoH9g= 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 465053858D39; Wed, 24 May 2023 15:04:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 465053858D39 Received: from localhost (localhost [127.0.0.1]) by lxmtout2.gsi.de (Postfix) with ESMTP id 2CAEA203E7E8; Wed, 24 May 2023 17:04:33 +0200 (CEST) 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 kKTAxKdKEQjQ; Wed, 24 May 2023 17:04:33 +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 lxmtout2.gsi.de (Postfix) with ESMTPS id 025D22027E5B; Wed, 24 May 2023 17:04:33 +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; Wed, 24 May 2023 17:04:32 +0200 To: , Subject: [PATCH] libstdc++: Fix type of first argument to vec_cntm call Date: Wed, 24 May 2023 17:04:32 +0200 Message-ID: <7719656.MHq7AAxBmi@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.2 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, 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?1766788432058664563?= X-GMAIL-MSGID: =?utf-8?q?1766788432058664563?= OK for master and backports? (also a long-standing bug that didn't surface until the new constexpr test was added) tested on powerpc64le-linux-gnu ------------- 8< ----------------- Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/109949 * include/experimental/bits/simd.h (__intrinsic_type): If __ALTIVEC__ is defined, map gnu::vector_size types to their corresponding __vector T types without losing unsignedness of integer types. Also prefer long long over long. * include/experimental/bits/simd_ppc.h (_S_popcount): Cast mask object to the expected unsigned vector type. --- libstdc++-v3/include/experimental/bits/simd.h | 39 ++++++++++++++++--- .../include/experimental/bits/simd_ppc.h | 3 +- 2 files changed, 36 insertions(+), 6 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.h b/libstdc++-v3/include/experimental/bits/simd.h index d1f388310f9..26f08f83ab0 100644 --- a/libstdc++-v3/include/experimental/bits/simd.h +++ b/libstdc++-v3/include/experimental/bits/simd.h @@ -2466,11 +2466,40 @@ struct __intrinsic_type<_Tp, _Bytes, enable_if_t<__is_vectorizable_v<_Tp> && _By "no __intrinsic_type support for 64-bit floating point on PowerPC w/o VSX"); #endif - using type = - typename __intrinsic_type_impl< - conditional_t, - conditional_t<_S_is_ldouble, double, _Tp>, - __int_for_sizeof_t<_Tp>>>::type; + static constexpr auto __element_type() + { + if constexpr (is_floating_point_v<_Tp>) + { + if constexpr (_S_is_ldouble) + return double {}; + else + return _Tp {}; + } + else if constexpr (is_signed_v<_Tp>) + { + if constexpr (sizeof(_Tp) == sizeof(_SChar)) + return _SChar {}; + else if constexpr (sizeof(_Tp) == sizeof(short)) + return short {}; + else if constexpr (sizeof(_Tp) == sizeof(int)) + return int {}; + else if constexpr (sizeof(_Tp) == sizeof(_LLong)) + return _LLong {}; + } + else + { + if constexpr (sizeof(_Tp) == sizeof(_UChar)) + return _UChar {}; + else if constexpr (sizeof(_Tp) == sizeof(_UShort)) + return _UShort {}; + else if constexpr (sizeof(_Tp) == sizeof(_UInt)) + return _UInt {}; + else if constexpr (sizeof(_Tp) == sizeof(_ULLong)) + return _ULLong {}; + } + } + + using type = typename __intrinsic_type_impl::type; }; #endif // __ALTIVEC__ diff --git a/libstdc++-v3/include/experimental/bits/simd_ppc.h b/libstdc++-v3/include/experimental/bits/simd_ppc.h index eca1b34241b..2ea7234bd99 100644 --- a/libstdc++-v3/include/experimental/bits/simd_ppc.h +++ b/libstdc++-v3/include/experimental/bits/simd_ppc.h @@ -130,7 +130,8 @@ _S_popcount(simd_mask<_Tp, _Abi> __k) const auto __kv = __as_vector(__k); if constexpr (__have_power10vec) { - return vec_cntm(__to_intrin(__kv), 1); + using _Intrin = __intrinsic_type16_t>>; + return vec_cntm(reinterpret_cast<_Intrin>(__kv), 1); } else if constexpr (sizeof(_Tp) >= sizeof(int)) {