Skip to content

Commit afe91c8

Browse files
committed
Migrate recursive template instantiations
1 parent 5491a13 commit afe91c8

6 files changed

Lines changed: 24 additions & 60 deletions

File tree

include/xsimd/arch/xsimd_avx512f.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ namespace xsimd
22582258
using register_type = typename batch_bool<T, A>::register_type;
22592259
register_type r = 0;
22602260
unsigned shift = 0;
2261-
(void)std::initializer_list<register_type> { (r |= register_type(values ? 1 : 0) << (shift++))... };
2261+
((r |= register_type(values ? 1 : 0) << (shift++)), ...);
22622262
return r;
22632263
}
22642264

@@ -2656,21 +2656,19 @@ namespace xsimd
26562656

26572657
namespace detail
26582658
{
2659-
template <class T, class A, T... Idx>
2660-
struct is_pair_of_contiguous_indices;
2661-
2662-
template <class T, class A>
2663-
struct is_pair_of_contiguous_indices<T, A> : std::true_type
2659+
template <class T, T... Idx, std::size_t... Is>
2660+
constexpr bool is_pair_of_contiguous_indices_impl(std::index_sequence<Is...>) noexcept
26642661
{
2665-
};
2662+
constexpr T idx[] = { Idx... };
2663+
return (... && (idx[2 * Is] % 2 == 0 && idx[2 * Is] + 1 == idx[2 * Is + 1]));
2664+
}
26662665

2667-
template <class T, class A, T Idx0, T Idx1, T... Idx>
2668-
struct is_pair_of_contiguous_indices<T, A, Idx0, Idx1, Idx...> : std::conditional_t<(Idx0 % 2 == 0) && (Idx0 + 1 == Idx1), is_pair_of_contiguous_indices<T, A, Idx...>, std::false_type>
2666+
template <class T, T... Idx>
2667+
constexpr bool is_pair_of_contiguous_indices() noexcept
26692668
{
2670-
};
2671-
2672-
template <class T, class A, T... Idx>
2673-
inline constexpr bool is_pair_of_contiguous_indices_v = is_pair_of_contiguous_indices<T, A, Idx...>::value;
2669+
static_assert(sizeof...(Idx) % 2 == 0, "indices come in pairs");
2670+
return is_pair_of_contiguous_indices_impl<T, Idx...>(std::make_index_sequence<sizeof...(Idx) / 2>());
2671+
}
26742672

26752673
template <class A, uint16_t I0, uint16_t I1, uint16_t I2, uint16_t I3, uint16_t I4, uint16_t I5, uint16_t I6, uint16_t I7,
26762674
uint16_t I8, uint16_t I9, uint16_t I10, uint16_t I11, uint16_t I12, uint16_t I13, uint16_t I14, uint16_t I15,
@@ -2703,7 +2701,7 @@ namespace xsimd
27032701
template <class A, uint16_t... Idx>
27042702
XSIMD_INLINE batch<uint16_t, A> swizzle(batch<uint16_t, A> const& self, batch_constant<uint16_t, A, Idx...> mask, requires_arch<avx512f>) noexcept
27052703
{
2706-
if constexpr (detail::is_pair_of_contiguous_indices_v<uint16_t, A, Idx...>)
2704+
if constexpr (detail::is_pair_of_contiguous_indices<uint16_t, Idx...>())
27072705
{
27082706
constexpr typename detail::fold_batch_constant<A, Idx...>::type mask32;
27092707
return _mm512_permutexvar_epi32(static_cast<batch<uint32_t, A>>(mask32), self);

include/xsimd/arch/xsimd_avx512vl_128.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace xsimd
176176
using register_type = typename batch_bool<T, A>::register_type;
177177
register_type r = 0;
178178
unsigned shift = 0;
179-
(void)std::initializer_list<register_type> { (r |= register_type(values ? 1 : 0) << (shift++))... };
179+
((r |= register_type(values ? 1 : 0) << (shift++)), ...);
180180
return r;
181181
}
182182

include/xsimd/arch/xsimd_avx512vl_256.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace xsimd
176176
using register_type = typename batch_bool<T, A>::register_type;
177177
register_type r = 0;
178178
unsigned shift = 0;
179-
(void)std::initializer_list<register_type> { (r |= register_type(values ? 1 : 0) << (shift++))... };
179+
((r |= register_type(values ? 1 : 0) << (shift++)), ...);
180180
return r;
181181
}
182182

include/xsimd/config/xsimd_arch.hpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "./xsimd_config.hpp"
1717
#include "./xsimd_cpuid.hpp"
1818

19-
#include <initializer_list>
2019
#include <type_traits>
2120
#include <utility>
2221

@@ -40,22 +39,6 @@ namespace xsimd
4039

4140
namespace detail
4241
{
43-
// Checks whether T appears in Tys.
44-
template <class T, class... Tys>
45-
struct contains;
46-
47-
template <class T>
48-
struct contains<T> : std::false_type
49-
{
50-
};
51-
52-
template <class T, class Ty, class... Tys>
53-
struct contains<T, Ty, Tys...>
54-
: std::conditional_t<std::is_same_v<Ty, T>, std::true_type,
55-
contains<T, Tys...>>
56-
{
57-
};
58-
5942
template <typename T>
6043
XSIMD_INLINE constexpr T max_of(T value) noexcept
6144
{
@@ -100,13 +83,13 @@ namespace xsimd
10083
template <class Arch>
10184
static constexpr bool contains() noexcept
10285
{
103-
return detail::contains<Arch, Archs...>::value;
86+
return (std::is_same_v<Arch, Archs> || ...);
10487
}
10588

10689
template <class F>
10790
static XSIMD_INLINE void for_each(F&& f) noexcept
10891
{
109-
(void)std::initializer_list<bool> { (f(Archs {}), true)... };
92+
(f(Archs {}), ...);
11093
}
11194

11295
static constexpr std::size_t alignment() noexcept

include/xsimd/types/xsimd_batch_constant.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,15 @@ namespace xsimd
191191

192192
private:
193193
// Build a 64-bit mask from Values... (LSB = index 0)
194-
template <std::size_t I, bool... Remaining>
195-
struct build_bits_helper;
196-
197-
template <std::size_t I>
198-
struct build_bits_helper<I>
199-
{
200-
static constexpr uint64_t value = 0u;
201-
};
202-
203-
template <std::size_t I, bool Current, bool... Remaining>
204-
struct build_bits_helper<I, Current, Remaining...>
194+
template <std::size_t... Is>
195+
static constexpr uint64_t build_bits(std::index_sequence<Is...>) noexcept
205196
{
206-
static constexpr uint64_t value = (Current ? (uint64_t(1) << I) : 0u)
207-
| build_bits_helper<I + 1, Remaining...>::value;
208-
};
197+
return (uint64_t(0) | ... | (Values ? (uint64_t(1) << Is) : uint64_t(0)));
198+
}
209199

210200
static constexpr uint64_t bits() noexcept
211201
{
212-
return build_bits_helper<0, Values...>::value;
202+
return build_bits(std::make_index_sequence<sizeof...(Values)>());
213203
}
214204
static constexpr uint64_t low_mask(std::size_t k) noexcept
215205
{

include/xsimd/utils/bits.hpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ namespace xsimd
1919
{
2020
namespace utils
2121
{
22-
template <typename I>
23-
constexpr I make_bit_mask(I bit)
24-
{
25-
static_assert(std::is_unsigned_v<I>, "Bit operations must be done on unsigned integers");
26-
assert(bit < static_cast<I>(8 * sizeof(I)));
27-
return static_cast<I>(I { 1 } << bit);
28-
}
29-
3022
template <typename I, typename... Args>
3123
constexpr I make_bit_mask(I bit, Args... bits)
3224
{
33-
// TODO(C++17): Use fold expression
3425
static_assert(std::is_unsigned_v<I>, "Bit operations must be done on unsigned integers");
35-
return make_bit_mask<I>(bit) | make_bit_mask<I>(static_cast<I>(bits)...);
26+
[[maybe_unused]] constexpr I bit_count = static_cast<I>(8 * sizeof(I));
27+
assert(((bit < bit_count) && ... && (static_cast<I>(bits) < bit_count)));
28+
return static_cast<I>(((I { 1 } << bit) | ... | (I { 1 } << static_cast<I>(bits))));
3629
}
3730

3831
template <int... Bits, typename I>

0 commit comments

Comments
 (0)