From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 2CDB53851C3B; Wed, 9 Jun 2021 12:22:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CDB53851C3B Received: by mail-ej1-x631.google.com with SMTP id c10so38159275eja.11; Wed, 09 Jun 2021 05:22:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=BXh7V/tRzF7ZoizGd+G8k0AhUubvXvzSYxa7KIzfs6s=; b=hTIdXft/xr8Iva5h8CFpV3JIb+QvBM1R8o/ufIE+kUXLqXpBI5mA0j3EbWfnm1ngr0 jIEx3j+T1ujTjMqVdMg3q7rPWOk19dzwI/NLsL8TZvARTssNe1F9VHfnNho1/68QgiQn f1BF0nd8E0eVb2Uf8bYwM6nVyyHwhG9JchycukVlRr6eOB+sJmJAMWts9HeZppLNnm2P +pjMSHxcKPoMXjT+EPeYM/oIcoxN+EIrj+H44+mOtCLP4GbdXwlsOfXDriP5nWPwyoRq 8AfrjoSn3tOH9cY9a1GPav7cDPDrTXpSNEWvjjPp3bbdNg7mnogCxogz+Jv0NOi5B+gT RjQQ== X-Gm-Message-State: AOAM530AmeeI2kkcNohq3MK6f2A+SUZqe3qmvCKv7HmDZhz1NVSMgYol cplzAMc2BzePdH83SIhyVDCoDA5MGwrY8DyezZs= X-Google-Smtp-Source: ABdhPJy2YTtSne1rJH+bZ3gSES92vBxSvsCVSFtQP6xy8QZMlE8JRUoM+G6LgNifjaQg3Nxi8Pd6OKjXkfLDCDdMQTg= X-Received: by 2002:a17:906:a458:: with SMTP id cb24mr28510114ejb.482.1623241331245; Wed, 09 Jun 2021 05:22:11 -0700 (PDT) MIME-Version: 1.0 References: <270527782.u9WJ3AIrlG@excalibur> <2210452.fJnDbHsrEp@excalibur> In-Reply-To: <2210452.fJnDbHsrEp@excalibur> From: Richard Biener Date: Wed, 9 Jun 2021 14:22:00 +0200 Message-ID: Subject: Re: [PATCH 11/11] libstdc++: Fix ODR issues with different -m flags To: Matthias Kretz Cc: GCC Patches , "libstdc++" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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:22:13 -0000 On Tue, Jun 8, 2021 at 2:23 PM Matthias Kretz wrote: > > > From: Matthias Kretz > > 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. Note that excessive use of always_inline can cause compile-time issues (see for example PR99785). I wonder whether the inlines can be placed in an anonymous namespace instead of the difficult to maintain explict list of SIMD features? 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. Richard. > Signed-off-by: Matthias Kretz > > 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. > --- > 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(-) > > > -- > =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=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