[PATCH v2] libstdc++: simd: x86: accept 64-bit long double as double [PR124657]

Jonathan Wakely jwakely@redhat.com
Wed Apr 29 09:12:44 GMT 2026


On Tue, 28 Apr 2026 at 22:48, Alexandre Oliva <oliva@adacore.com> wrote:
>
> On Apr 22, 2026, Matthias Kretz <MatthiasKretz@gmx.net> wrote:
>
> >> Jonathan, should I credit you for the preprocessor micro-optimization?
> >> I didn't quite follow it to the letter, because I thought it looked
> >> cleaner this way, and IIUC it would not bring any notable inefficiency.
>
> >> +template <typename _Tp>
> >> +  constexpr bool
> >> +  __is_x86_pd()
> >> +  {
> >> +#if __LDBL_MANT_DIG == __DBL_MANT_DIG
> >> +    if constexpr (is_same_v<_Tp, long double>)
> >> +      return true;
> >> +#endif
> >> +    return is_same_v<_Tp, double>;
> >> +  }
>
> > I believe Jonathan's approach would not instantiate is_same_v<_Tp, long
> double> for __is_x86_pd<double>(). Yours always instantiates both is_same_v
> > templates for any _Tp.
>
> That's true.  But as noted in the other follow-up patch, is_same_v<_Tp,
> long double> is necessarily instantiated in struct __intrinsic_type, so
> as you say, it will surely be instantiated somewhere already.  By moving
> the necessarily-instantiated case first, we may conceivably avoid the
> instantiation of the other in the one case it is avoidable.

Not as you've written it, because both statements are compiled so both
template are always instantiated.

You could only avoid the second instantiation by making it a discarded
statement, so putting it in an else branch of the if-constexpr
statement:

if constexpr (true)
 { }
else
 { /* discarded statement */ }
/* not discarded statement */;

That's what my suggestion did, i.e. the 'else' was load-bearing. And I
put the common case (double) first so that the uncommon case (long
double) was not instantiated unless needed.

> So yeah, I didn't follow the suggestion to the letter, but I followed
> its spirit ;-)

The spirit was to use a discarded statement:
https://en.cppreference.com/cpp/language/if#Constexpr_if

But it doesn't matter, variable templates are cheap and we're already
instantiating it for long double elsewhere. And experimental::simd
isn't a priority now that we have std::simd.



More information about the Libstdc++ mailing list