https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83875

--- Comment #10 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> ---
(In reply to Matthias Kretz (Vir) from comment #7)
> what should the following print?
> [...]

By now I think we should just leave those examples continue to be ODR
violations. The C++ machinery for doing this is templates. E.g.

template<int value =  __builtin_target_supports("avx512f")
           ? 64 : __builtin_target_supports("avx")
           ? 32 : __builtin_target_supports("sse")
           ? 16 : __builtin_target_supports("mmx") ? 8 : 0>
  constexpr int native_simd_width = value;

Now, when the compiler gets to

[[gnu::target_clones("default,avx,avx512f")]]
void f()
{ std::cout << native_simd_width<>; }

it creates three clones of 'f', and in each of them the default template
arguments to 'native_simd_width' are different, instantiating
'native_simd_width<16>', 'native_simd_width<32>', and 'native_simd_width<64>'.

The std::simd implementation is prepared for working like this, since it
already uses a template parameter for avoiding ODR violations on linking TUs
compiled with different compiler flags. If this is implementable, that would be
a huge win for some use cases of the simd library type.

Reply via email to