From: Matthias Kretz <m.kretz@gsi.de>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, libstdc++ <libstdc++@gcc.gnu.org>
Subject: Re: [PATCH 11/11] libstdc++: Fix ODR issues with different -m flags
Date: Wed, 9 Jun 2021 14:53:02 +0200 [thread overview]
Message-ID: <1653537.qjhy4c4RdF@excalibur> (raw)
In-Reply-To: <CAFiYyc144W5ZDtronhnJM12a6wiCkWNt2CC8OHiP24zk9GkVag@mail.gmail.com>
On Wednesday, 9 June 2021 14:22:00 CEST Richard Biener wrote:
> On Tue, Jun 8, 2021 at 2:23 PM Matthias Kretz <m.kretz@gsi.de> wrote:
> > From: Matthias Kretz <kretz@kde.org>
> >
> > 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).
Ah, I should verify whether that's also the reason my stdx::simd
implementation is slow to compile.
However, I really must have the always_inline semantics in most of the places
stdx::simd uses it. Because most of these functions compile to either a single
function call or a single instruction (often f0 -> f1 -> f2 -> single
instruction). If the inliner even makes one single wrong inlining decision,
the whole program might slow down by integral factors, not only small
percentages. And without inlining these functions, -fno-inline builds (i.e.
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
+ = conditional_t<__machine_flags() == 0, _OdrEnforcer,
+ _MachineFlagsTemplate<__machine_flags(), __floating_point_flags()>>;
It can potentially blow up the code size and the instruction cache usage,
though. The trade-off isn't obvious to make. I guess I can't promise that
mixing different compiler flags is ODR violation free
> 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? ;-)
- Matthias
> > Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
> >
> > 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(-)
> >
> > --
> > ──────────────────────────────────────────────────────────────────────────
> >
> > 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
> >
> > ──────────────────────────────────────────────────────────────────────────
--
──────────────────────────────────────────────────────────────────────────
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
──────────────────────────────────────────────────────────────────────────
next prev parent reply other threads:[~2021-06-09 12:53 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 12:10 [PATCH 00/11] stdx::simd optimizations, corrections, and cleanups Matthias Kretz
2021-06-08 12:11 ` [PATCH 01/11] libstdc++: Improve copysign codegen Matthias Kretz
2021-06-08 12:11 ` [PATCH 02/11] libstdc++: Remove dead code Matthias Kretz
2021-06-08 12:11 ` [PATCH 03/11] libstdc++: Improve fixed_size codegen Matthias Kretz
2021-06-08 12:11 ` [PATCH 04/11] libstdc++: Make use of __builtin_bit_cast Matthias Kretz
2021-06-11 10:53 ` [PATCH 04/11 v2] " Matthias Kretz
2021-06-24 14:01 ` [PATCH 04/11 v3] " Matthias Kretz
2021-06-24 14:08 ` Jakub Jelinek
2021-06-24 14:11 ` Jonathan Wakely
2021-06-24 14:12 ` Jonathan Wakely
2021-06-24 14:21 ` Jakub Jelinek
2021-06-24 14:34 ` Jonathan Wakely
2021-06-24 14:40 ` Jonathan Wakely
2021-06-24 14:44 ` Jakub Jelinek
2021-06-25 11:23 ` Jonathan Wakely
2021-06-08 12:11 ` [PATCH 05/11] libstdc++: Remove incorrect fabs overload Matthias Kretz
2021-06-08 12:11 ` [PATCH 06/11] libstdc++: Minor simd_math cleanups Matthias Kretz
2021-06-08 12:11 ` [PATCH 07/11] libstdc++: Fix condition when AVX512F ldexp implementation is used Matthias Kretz
2021-06-08 12:11 ` [PATCH 08/11] libstdc++: Avoid raising fp exceptions in trunc, floor, and ceil Matthias Kretz
2021-06-08 12:11 ` [PATCH 09/11] libstdc++: Ensure unrolled loops inline the lambda Matthias Kretz
2021-06-08 12:12 ` [PATCH 10/11] libstdc++: Fix internal names: add missing underscores Matthias Kretz
2021-06-08 12:12 ` [PATCH 11/11] libstdc++: Fix ODR issues with different -m flags Matthias Kretz
2021-06-09 12:22 ` Richard Biener
2021-06-09 12:53 ` Matthias Kretz [this message]
2021-06-09 13:22 ` Richard Biener
2021-11-15 8:57 ` Matthias Kretz
2022-01-14 21:30 ` Jonathan Wakely
2022-01-17 0:08 ` Jonathan Wakely
2021-06-24 13:42 ` [PATCH 00/11] stdx::simd optimizations, corrections, and cleanups Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1653537.qjhy4c4RdF@excalibur \
--to=m.kretz@gsi.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).