From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lxmtout1.gsi.de (lxmtout1.gsi.de [140.181.3.111]) by sourceware.org (Postfix) with ESMTPS id 6931A3982C22; Wed, 9 Jun 2021 12:53:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6931A3982C22 Authentication-Results: sourceware.org; dmarc=none (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 lxmtout1.gsi.de (Postfix) with ESMTP id DC3542050D13; Wed, 9 Jun 2021 14:53:02 +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 PysNEeNKegBI; Wed, 9 Jun 2021 14:53:02 +0200 (CEST) Received: from srvex1.campus.gsi.de (unknown [10.10.4.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by lxmtout1.gsi.de (Postfix) with ESMTPS id C30EA2050D00; Wed, 9 Jun 2021 14:53:02 +0200 (CEST) Received: from excalibur.localnet (140.181.3.12) by srvex1.campus.gsi.de (10.10.4.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.10; Wed, 9 Jun 2021 14:53:02 +0200 From: Matthias Kretz To: Richard Biener CC: GCC Patches , libstdc++ Subject: Re: [PATCH 11/11] libstdc++: Fix ODR issues with different -m flags Date: Wed, 9 Jun 2021 14:53:02 +0200 Message-ID: <1653537.qjhy4c4RdF@excalibur> Organization: GSI Helmholtzzentrum =?UTF-8?B?ZsO8cg==?= Schwerionenforschung In-Reply-To: References: <270527782.u9WJ3AIrlG@excalibur> <2210452.fJnDbHsrEp@excalibur> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvex4.Campus.gsi.de (10.10.4.36) To srvex1.campus.gsi.de (10.10.4.11) X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_SBL, URIBL_SBL_A autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jun 2021 12:53:06 -0000 On Wednesday, 9 June 2021 14:22:00 CEST Richard Biener wrote: > On Tue, Jun 8, 2021 at 2:23 PM Matthias Kretz wrote: > > From: Matthias Kretz > >=20 > > Explicitly support use of the stdx::simd implementation in situations > > where the user links TUs that were compiled with different -m flags. In > > general, this is always a (quasi) ODR violation for inline functions > > because at least codegen may differ in important ways. However, in the > > resulting executable only one (unspecified which one) of them might be > > used. For simd we want to support users to compile code multiple times, > > with different -m flags and have a runtime dispatch to the TU matching > > the target CPU. But if internal functions are not inlined this may lead > > to unexpected performance loss or execution of illegal instructions. > > Therefore, inline functions that are not marked as always_inline must > > use an additional template parameter somewhere in their name, to > > disambiguate between the different -m translations. >=20 > Note that excessive use of always_inline can cause compile-time issues > (see for example PR99785). Ah, I should verify whether that's also the reason my stdx::simd=20 implementation is slow to compile. However, I really must have the always_inline semantics in most of the plac= es=20 stdx::simd uses it. Because most of these functions compile to either a sin= gle=20 function call or a single instruction (often f0 -> f1 -> f2 -> single=20 instruction). If the inliner even makes one single wrong inlining decision,= =20 the whole program might slow down by integral factors, not only small=20 percentages. And without inlining these functions, -fno-inline builds (i.e.= =20 many debug builds) become unbearably slow (aka useless). > I wonder whether the inlines can be > placed in an anonymous namespace instead of the difficult to maintain > explict list of SIMD features? It's possible, and part of the patch: + namespace + { + struct _OdrEnforcer {}; + } [...] + using __odr_helper + =3D conditional_t<__machine_flags() =3D=3D 0, _OdrEnforcer, + _MachineFlagsTemplate<__machine_flags(), __floating_point_flags()>>; It can potentially blow up the code size and the instruction cache usage,=20 though. The trade-off isn't obvious to make. I guess I can't promise that=20 mixing different compiler flags is ODR violation free=20 > It also doesn't solve the issue when > instantiating the functions from a TU which contains #pragma GCC target > sections to switch options, of course. Yes. Can I get PR83875? ;-) =2D Matthias > > Signed-off-by: Matthias Kretz > >=20 > > libstdc++-v3/ChangeLog: > > * include/experimental/bits/simd.h: Move feature detection bools > > and add __have_avx512bitalg, __have_avx512vbmi2, > > __have_avx512vbmi, __have_avx512ifma, __have_avx512cd, > > __have_avx512vnni, __have_avx512vpopcntdq. > > (__detail::__machine_flags): New function which returns a unique > > uint64 depending on relevant -m and -f flags. > > (__detail::__odr_helper): New type alias for either an anonymous > > type or a type specialized with the __machine_flags number. > > (_SimdIntOperators): Change template parameters from _Impl to > > _Tp, _Abi because _Impl now has an __odr_helper parameter which > > may be _OdrEnforcer from the anonymous namespace, which makes > > for a bad base class. > > (many): Either add __odr_helper template parameter or mark as > > always_inline. > > * include/experimental/bits/simd_detail.h: Add defines for > > AVX512BITALG, AVX512VBMI2, AVX512VBMI, AVX512IFMA, AVX512CD, > > AVX512VNNI, AVX512VPOPCNTDQ, and AVX512VP2INTERSECT. > > * include/experimental/bits/simd_builtin.h: Add __odr_helper > > template parameter or mark as always_inline. > > * include/experimental/bits/simd_fixed_size.h: Ditto. > > * include/experimental/bits/simd_math.h: Ditto. > > * include/experimental/bits/simd_scalar.h: Ditto. > > * include/experimental/bits/simd_neon.h: Add __odr_helper > > template parameter. > > * include/experimental/bits/simd_ppc.h: Ditto. > > * include/experimental/bits/simd_x86.h: Ditto. > >=20 > > --- > >=20 > > libstdc++-v3/include/experimental/bits/simd.h | 380 ++++++++++++------ > > .../include/experimental/bits/simd_builtin.h | 41 +- > > .../include/experimental/bits/simd_detail.h | 40 ++ > > .../experimental/bits/simd_fixed_size.h | 39 +- > > .../include/experimental/bits/simd_math.h | 45 ++- > > .../include/experimental/bits/simd_neon.h | 4 +- > > .../include/experimental/bits/simd_ppc.h | 4 +- > > .../include/experimental/bits/simd_scalar.h | 71 +++- > > .../include/experimental/bits/simd_x86.h | 4 +- > > 9 files changed, 440 insertions(+), 188 deletions(-) > >=20 > > -- > > =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > >=20 > > Dr. Matthias Kretz https://mattkretz.github.= io > > GSI Helmholtz Centre for Heavy Ion Research https://gsi.= de > > std::experimental::simd https://github.com/VcDevel/std-si= md > >=20 > > =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =2D-=20 =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 Dr. Matthias Kretz https://mattkretz.github.io GSI Helmholtz Centre for Heavy Ion Research https://gsi.de std::experimental::simd https://github.com/VcDevel/std-simd =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80