| 1 | // { dg-options "-std=gnu++17" } |
| 2 | // { dg-require-effective-target c++17 } |
| 3 | // { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } } |
| 4 | // { dg-require-cmath "" } |
| 5 | |
| 6 | #include <experimental/simd> |
| 7 | |
| 8 | namespace stdx = std::experimental; |
| 9 | |
| 10 | using T = std::uint64_t; |
| 11 | |
| 12 | template <typename U, int N> |
| 13 | using V = stdx::simd<U, stdx::simd_abi::deduce_t<U, N>>; |
| 14 | |
| 15 | [[gnu::noinline, gnu::noipa]] |
| 16 | int reduce(V<T, 4> x) |
| 17 | { |
| 18 | static_assert(stdx::find_last_set(V<T, 4>([](unsigned i) { return i; }) != V<T, 4>(0)) == 3); |
| 19 | return stdx::find_last_set(x != -1); |
| 20 | } |
| 21 | |
| 22 | [[gnu::noinline, gnu::noipa]] |
| 23 | int reduce2() |
| 24 | { |
| 25 | using M8 = typename V<short, 8>::mask_type; |
| 26 | using M4 = typename V<int, 4>::mask_type; |
| 27 | if constexpr (sizeof(M8) == sizeof(M4) |
| 28 | && !std::is_same_v<M4, stdx::fixed_size_simd_mask<int, 4>>) |
| 29 | // fixed_size invariant: padding bits of masks are zero, the memcpy would violate that |
| 30 | { |
| 31 | M4 k; |
| 32 | __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4)); |
| 33 | return stdx::find_last_set(k); |
| 34 | } |
| 35 | return 3; |
| 36 | } |
| 37 | |
| 38 | |
| 39 | int main() |
| 40 | { |
| 41 | const V<T, 4> x {}; |
| 42 | |
| 43 | const int r = reduce(x); |
| 44 | if (r != 3) |
| 45 | __builtin_abort(); |
| 46 | |
| 47 | const int r2 = reduce2(); |
| 48 | if (r2 != 3) |
| 49 | __builtin_abort(); |
| 50 | } |