diff --git a/include/xsimd/arch/xsimd_avx512f.hpp b/include/xsimd/arch/xsimd_avx512f.hpp index 658b7d448..8bfc1feb5 100644 --- a/include/xsimd/arch/xsimd_avx512f.hpp +++ b/include/xsimd/arch/xsimd_avx512f.hpp @@ -2258,7 +2258,7 @@ namespace xsimd using register_type = typename batch_bool::register_type; register_type r = 0; unsigned shift = 0; - (void)std::initializer_list { (r |= register_type(values ? 1 : 0) << (shift++))... }; + ((r |= register_type(values ? 1 : 0) << (shift++)), ...); return r; } @@ -2656,21 +2656,19 @@ namespace xsimd namespace detail { - template - struct is_pair_of_contiguous_indices; - - template - struct is_pair_of_contiguous_indices : std::true_type + template + constexpr bool is_pair_of_contiguous_indices_impl(std::index_sequence) noexcept { - }; + constexpr T idx[] = { Idx... }; + return (... && (idx[2 * Is] % 2 == 0 && idx[2 * Is] + 1 == idx[2 * Is + 1])); + } - template - struct is_pair_of_contiguous_indices : std::conditional_t<(Idx0 % 2 == 0) && (Idx0 + 1 == Idx1), is_pair_of_contiguous_indices, std::false_type> + template + constexpr bool is_pair_of_contiguous_indices() noexcept { - }; - - template - inline constexpr bool is_pair_of_contiguous_indices_v = is_pair_of_contiguous_indices::value; + static_assert(sizeof...(Idx) % 2 == 0, "indices come in pairs"); + return is_pair_of_contiguous_indices_impl(std::make_index_sequence()); + } template XSIMD_INLINE batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { - if constexpr (detail::is_pair_of_contiguous_indices_v) + if constexpr (detail::is_pair_of_contiguous_indices()) { constexpr typename detail::fold_batch_constant::type mask32; return _mm512_permutexvar_epi32(static_cast>(mask32), self); diff --git a/include/xsimd/arch/xsimd_avx512vl_128.hpp b/include/xsimd/arch/xsimd_avx512vl_128.hpp index 9922182fc..c2894c818 100644 --- a/include/xsimd/arch/xsimd_avx512vl_128.hpp +++ b/include/xsimd/arch/xsimd_avx512vl_128.hpp @@ -176,7 +176,7 @@ namespace xsimd using register_type = typename batch_bool::register_type; register_type r = 0; unsigned shift = 0; - (void)std::initializer_list { (r |= register_type(values ? 1 : 0) << (shift++))... }; + ((r |= register_type(values ? 1 : 0) << (shift++)), ...); return r; } diff --git a/include/xsimd/arch/xsimd_avx512vl_256.hpp b/include/xsimd/arch/xsimd_avx512vl_256.hpp index 3d58a67f5..3c3108d9c 100644 --- a/include/xsimd/arch/xsimd_avx512vl_256.hpp +++ b/include/xsimd/arch/xsimd_avx512vl_256.hpp @@ -176,7 +176,7 @@ namespace xsimd using register_type = typename batch_bool::register_type; register_type r = 0; unsigned shift = 0; - (void)std::initializer_list { (r |= register_type(values ? 1 : 0) << (shift++))... }; + ((r |= register_type(values ? 1 : 0) << (shift++)), ...); return r; } diff --git a/include/xsimd/config/xsimd_arch.hpp b/include/xsimd/config/xsimd_arch.hpp index 329421833..ac5546bbc 100644 --- a/include/xsimd/config/xsimd_arch.hpp +++ b/include/xsimd/config/xsimd_arch.hpp @@ -16,7 +16,6 @@ #include "./xsimd_config.hpp" #include "./xsimd_cpuid.hpp" -#include #include #include @@ -40,22 +39,6 @@ namespace xsimd namespace detail { - // Checks whether T appears in Tys. - template - struct contains; - - template - struct contains : std::false_type - { - }; - - template - struct contains - : std::conditional_t, std::true_type, - contains> - { - }; - template XSIMD_INLINE constexpr T max_of(T value) noexcept { @@ -100,13 +83,13 @@ namespace xsimd template static constexpr bool contains() noexcept { - return detail::contains::value; + return (std::is_same_v || ...); } template static XSIMD_INLINE void for_each(F&& f) noexcept { - (void)std::initializer_list { (f(Archs {}), true)... }; + (f(Archs {}), ...); } static constexpr std::size_t alignment() noexcept diff --git a/include/xsimd/types/xsimd_batch_constant.hpp b/include/xsimd/types/xsimd_batch_constant.hpp index c6f045f85..9cbe93b43 100644 --- a/include/xsimd/types/xsimd_batch_constant.hpp +++ b/include/xsimd/types/xsimd_batch_constant.hpp @@ -191,25 +191,15 @@ namespace xsimd private: // Build a 64-bit mask from Values... (LSB = index 0) - template - struct build_bits_helper; - - template - struct build_bits_helper - { - static constexpr uint64_t value = 0u; - }; - - template - struct build_bits_helper + template + static constexpr uint64_t build_bits(std::index_sequence) noexcept { - static constexpr uint64_t value = (Current ? (uint64_t(1) << I) : 0u) - | build_bits_helper::value; - }; + return (uint64_t(0) | ... | (Values ? (uint64_t(1) << Is) : uint64_t(0))); + } static constexpr uint64_t bits() noexcept { - return build_bits_helper<0, Values...>::value; + return build_bits(std::make_index_sequence()); } static constexpr uint64_t low_mask(std::size_t k) noexcept { diff --git a/include/xsimd/utils/bits.hpp b/include/xsimd/utils/bits.hpp index 5d2efbc6d..f789dbad3 100644 --- a/include/xsimd/utils/bits.hpp +++ b/include/xsimd/utils/bits.hpp @@ -19,20 +19,13 @@ namespace xsimd { namespace utils { - template - constexpr I make_bit_mask(I bit) - { - static_assert(std::is_unsigned_v, "Bit operations must be done on unsigned integers"); - assert(bit < static_cast(8 * sizeof(I))); - return static_cast(I { 1 } << bit); - } - template constexpr I make_bit_mask(I bit, Args... bits) { - // TODO(C++17): Use fold expression static_assert(std::is_unsigned_v, "Bit operations must be done on unsigned integers"); - return make_bit_mask(bit) | make_bit_mask(static_cast(bits)...); + [[maybe_unused]] constexpr I bit_count = static_cast(8 * sizeof(I)); + assert(((bit < bit_count) && ... && (static_cast(bits) < bit_count))); + return static_cast(((I { 1 } << bit) | ... | (I { 1 } << static_cast(bits)))); } template