// { dg-options "-std=gnu++17" } // { dg-require-effective-target c++17 } // { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } } // { dg-require-cmath "" } #include namespace stdx = std::experimental; using T = std::uint64_t; template using V = stdx::simd>; [[gnu::noinline, gnu::noipa]] int reduce(V x) { static_assert(stdx::find_last_set(V([](unsigned i) { return i; }) != V(0)) == 3); return stdx::find_last_set(x != -1); } [[gnu::noinline, gnu::noipa]] int reduce2() { using M8 = typename V::mask_type; using M4 = typename V::mask_type; if constexpr (sizeof(M8) == sizeof(M4) && !std::is_same_v>) // fixed_size invariant: padding bits of masks are zero, the memcpy would violate that { M4 k; __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4)); return stdx::find_last_set(k); } return 3; } int main() { const V x {}; const int r = reduce(x); if (r != 3) __builtin_abort(); const int r2 = reduce2(); if (r2 != 3) __builtin_abort(); }