diff --git a/docs/source/api/batch_manip.rst b/docs/source/api/batch_manip.rst index d6aad12cf..67e4a853e 100644 --- a/docs/source/api/batch_manip.rst +++ b/docs/source/api/batch_manip.rst @@ -1,25 +1,27 @@ -.. Copyright (c) 2021, Serge Guelton +..Copyright(c) 2021, Serge Guelton - Distributed under the terms of the BSD 3-Clause License. + Distributed under the terms of the BSD 3 + - Clause License. - The full license is in the file LICENSE, distributed with this software. + The full license is in the file LICENSE, + distributed with this software. -Conditional expression -====================== + Conditional expression + == == == == == == == == == == == -+------------------------------+-------------------------------------------+ -| :cpp:func:`select` | conditional selection with mask | -+------------------------------+-------------------------------------------+ + +-- -- -- -- -- -- -- -- -- -- -- -- -- -- --+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -+ + | : cpp : func :`select` | conditional selection with mask | +-- -- -- -- -- -- -- -- -- -- -- -- -- -- --+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -+ ----- + -- -- -.. doxygenfunction:: select(batch_bool const &cond, batch const &true_br, batch const &false_br) noexcept - :project: xsimd + ..doxygenfunction::select(batch_bool const& cond, batch const& true_br, batch const& false_br) noexcept + : project : xsimd -.. doxygenfunction:: select(batch_bool_constant, Values...> const &cond, batch const &true_br, batch const &false_br) noexcept - :project: xsimd + ..doxygenfunction::select(batch_bool_constant const& cond, batch const& true_br, batch const& false_br) noexcept + : project : xsimd - -In the specific case when one needs to conditionnaly increment or decrement a -batch based on a mask, :cpp:func:`incr_if` and -:cpp:func:`decr_if` provide specialized version. + In the specific case when one needs to conditionnaly increment + or decrement a + batch based on a mask, + : +cpp : func :`incr_if` and : cpp : func :`decr_if` provide specialized version. diff --git a/include/xsimd/arch/generic/xsimd_generic_math.hpp b/include/xsimd/arch/generic/xsimd_generic_math.hpp index 7bcc4da24..a7b8e2f90 100644 --- a/include/xsimd/arch/generic/xsimd_generic_math.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_math.hpp @@ -2064,7 +2064,7 @@ namespace xsimd inline T reduce(Op op, batch const& self, std::integral_constant) noexcept { using index_type = as_unsigned_integer_t; - batch split = swizzle(self, make_batch_constant, split_high>()); + batch split = swizzle(self, make_batch_constant>()); return reduce(op, op(split, self), std::integral_constant()); } } diff --git a/include/xsimd/arch/generic/xsimd_generic_memory.hpp b/include/xsimd/arch/generic/xsimd_generic_memory.hpp index 233d39a26..f92f6b48b 100644 --- a/include/xsimd/arch/generic/xsimd_generic_memory.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_memory.hpp @@ -21,10 +21,10 @@ namespace xsimd { - template + template struct batch_constant; - template + template struct batch_bool_constant; namespace kernel @@ -180,7 +180,7 @@ namespace xsimd } }; batch tmp(val); - return select(make_batch_bool_constant, index_mask>(), self, tmp); + return select(make_batch_bool_constant(), self, tmp); } // get @@ -295,7 +295,7 @@ namespace xsimd } }; - return swizzle(self, make_batch_constant, A>, rotate_generator>(), A {}); + return swizzle(self, make_batch_constant, A, rotate_generator>(), A {}); } template @@ -316,7 +316,7 @@ namespace xsimd } }; - return swizzle(self, make_batch_constant, A>, rotate_generator>(), A {}); + return swizzle(self, make_batch_constant, A, rotate_generator>(), A {}); } template @@ -455,19 +455,19 @@ namespace xsimd } template - inline batch shuffle(batch const& x, batch const& y, batch_constant, Indices...>, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant, requires_arch) noexcept { constexpr size_t bsize = sizeof...(Indices); // Detect common patterns XSIMD_IF_CONSTEXPR(detail::is_swizzle_fst(bsize, Indices...)) { - return swizzle(x, batch_constant, ((Indices >= bsize) ? 0 /* never happens */ : Indices)...>()); + return swizzle(x, batch_constant= bsize) ? 0 /* never happens */ : Indices)...>()); } XSIMD_IF_CONSTEXPR(detail::is_swizzle_snd(bsize, Indices...)) { - return swizzle(y, batch_constant, ((Indices >= bsize) ? (Indices - bsize) : 0 /* never happens */)...>()); + return swizzle(y, batch_constant= bsize) ? (Indices - bsize) : 0 /* never happens */)...>()); } XSIMD_IF_CONSTEXPR(detail::is_zip_lo(bsize, Indices...)) @@ -482,7 +482,7 @@ namespace xsimd XSIMD_IF_CONSTEXPR(detail::is_select(bsize, Indices...)) { - return select(batch_bool_constant, (Indices < bsize)...>(), x, y); + return select(batch_bool_constant(), x, y); } #if defined(__has_builtin) @@ -503,9 +503,9 @@ namespace xsimd #else // Use a generic_pattern. It is suboptimal but clang optimizes this // pretty well. - batch x_lane = swizzle(x, batch_constant, ((Indices >= bsize) ? (Indices - bsize) : Indices)...>()); - batch y_lane = swizzle(y, batch_constant, ((Indices >= bsize) ? (Indices - bsize) : Indices)...>()); - batch_bool_constant, (Indices < bsize)...> select_x_lane; + batch x_lane = swizzle(x, batch_constant= bsize) ? (Indices - bsize) : Indices)...>()); + batch y_lane = swizzle(y, batch_constant= bsize) ? (Indices - bsize) : Indices)...>()); + batch_bool_constant select_x_lane; return select(select_x_lane, x_lane, y_lane); #endif } @@ -542,7 +542,7 @@ namespace xsimd // swizzle template - inline batch, A> swizzle(batch, A> const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch, A> swizzle(batch, A> const& self, batch_constant mask, requires_arch) noexcept { return { swizzle(self.real(), mask), swizzle(self.imag(), mask) }; } diff --git a/include/xsimd/arch/xsimd_avx.hpp b/include/xsimd/arch/xsimd_avx.hpp index 5ec1e02d4..51121a327 100644 --- a/include/xsimd/arch/xsimd_avx.hpp +++ b/include/xsimd/arch/xsimd_avx.hpp @@ -1161,22 +1161,22 @@ namespace xsimd return detail::merge_sse(res_low, res_hi); } template ::value, void>::type> - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { Values... }, true_br, false_br, avx2 {}); } template - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { - constexpr auto mask = batch_bool_constant, Values...>::mask(); + constexpr auto mask = batch_bool_constant::mask(); return _mm256_blend_ps(false_br, true_br, mask); } template - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { - constexpr auto mask = batch_bool_constant, Values...>::mask(); + constexpr auto mask = batch_bool_constant::mask(); return _mm256_blend_pd(false_br, true_br, mask); } @@ -1238,7 +1238,7 @@ namespace xsimd // shuffle template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1, I2, I3, I4, I5, I6, I7> mask, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant mask, requires_arch) noexcept { constexpr uint32_t smask = detail::mod_shuffle(I0, I1, I2, I3); // shuffle within lane @@ -1253,7 +1253,7 @@ namespace xsimd } template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1, I2, I3> mask, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant mask, requires_arch) noexcept { constexpr uint32_t smask = (I0 & 0x1) | ((I1 & 0x1) << 1) | ((I2 & 0x1) << 2) | ((I3 & 0x1) << 3); // shuffle within lane @@ -1504,7 +1504,7 @@ namespace xsimd // swizzle (constant mask) template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { // duplicate low and high part of input __m256 hi = _mm256_castps128_ps256(_mm256_extractf128_ps(self, 1)); @@ -1514,14 +1514,14 @@ namespace xsimd __m256 low_low = _mm256_insertf128_ps(self, _mm256_castps256_ps128(low), 1); // normalize mask - batch_constant, (V0 % 4), (V1 % 4), (V2 % 4), (V3 % 4), (V4 % 4), (V5 % 4), (V6 % 4), (V7 % 4)> half_mask; + batch_constant half_mask; // permute within each lane __m256 r0 = _mm256_permutevar_ps(low_low, (batch)half_mask); __m256 r1 = _mm256_permutevar_ps(hi_hi, (batch)half_mask); // mask to choose the right lane - batch_bool_constant, (V0 >= 4), (V1 >= 4), (V2 >= 4), (V3 >= 4), (V4 >= 4), (V5 >= 4), (V6 >= 4), (V7 >= 4)> blend_mask; + batch_bool_constant= 4), (V1 >= 4), (V2 >= 4), (V3 >= 4), (V4 >= 4), (V5 >= 4), (V6 >= 4), (V7 >= 4)> blend_mask; // blend the two permutes constexpr auto mask = blend_mask.mask(); @@ -1529,7 +1529,7 @@ namespace xsimd } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { // duplicate low and high part of input __m256d hi = _mm256_castpd128_pd256(_mm256_extractf128_pd(self, 1)); @@ -1539,14 +1539,14 @@ namespace xsimd __m256d low_low = _mm256_insertf128_pd(self, _mm256_castpd256_pd128(low), 1); // normalize mask - batch_constant, (V0 % 2) * -1, (V1 % 2) * -1, (V2 % 2) * -1, (V3 % 2) * -1> half_mask; + batch_constant half_mask; // permute within each lane __m256d r0 = _mm256_permutevar_pd(low_low, (batch)half_mask); __m256d r1 = _mm256_permutevar_pd(hi_hi, (batch)half_mask); // mask to choose the right lane - batch_bool_constant, (V0 >= 2), (V1 >= 2), (V2 >= 2), (V3 >= 2)> blend_mask; + batch_bool_constant= 2), (V1 >= 2), (V2 >= 2), (V3 >= 2)> blend_mask; // blend the two permutes constexpr auto mask = blend_mask.mask(); @@ -1564,7 +1564,7 @@ namespace xsimd uint32_t V7, detail::enable_sized_integral_t = 0> inline batch swizzle(batch const& self, - batch_constant, + batch_constant = 0> inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3> const& mask, + batch_constant const& mask, requires_arch) noexcept { return bitwise_cast( diff --git a/include/xsimd/arch/xsimd_avx2.hpp b/include/xsimd/arch/xsimd_avx2.hpp index a4881778e..7e6ec629d 100644 --- a/include/xsimd/arch/xsimd_avx2.hpp +++ b/include/xsimd/arch/xsimd_avx2.hpp @@ -729,9 +729,9 @@ namespace xsimd } } template ::value, void>::type> - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { - constexpr int mask = batch_bool_constant, Values...>::mask(); + constexpr int mask = batch_bool_constant::mask(); // FIXME: for some reason mask here is not considered as an immediate, // but it's okay for _mm256_blend_epi32 // case 2: return _mm256_blend_epi16(false_br, true_br, mask); @@ -912,36 +912,36 @@ namespace xsimd // swizzle (constant mask) template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return _mm256_permutevar8x32_ps(self, (batch)mask); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr auto mask = detail::shuffle(V0, V1, V2, V3); return _mm256_permute4x64_pd(self, mask); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr auto mask = detail::shuffle(V0, V1, V2, V3); return _mm256_permute4x64_epi64(self, mask); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, avx2 {})); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return _mm256_permutevar8x32_epi32(self, (batch)mask); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, avx2 {})); } diff --git a/include/xsimd/arch/xsimd_avx512bw.hpp b/include/xsimd/arch/xsimd_avx512bw.hpp index 95fbcbd46..1532dd091 100644 --- a/include/xsimd/arch/xsimd_avx512bw.hpp +++ b/include/xsimd/arch/xsimd_avx512bw.hpp @@ -617,25 +617,25 @@ namespace xsimd // swizzle (static version) template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512bw {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512bw {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512bw {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512bw {}); } diff --git a/include/xsimd/arch/xsimd_avx512f.hpp b/include/xsimd/arch/xsimd_avx512f.hpp index 7ee461013..140f430b7 100644 --- a/include/xsimd/arch/xsimd_avx512f.hpp +++ b/include/xsimd/arch/xsimd_avx512f.hpp @@ -1422,7 +1422,7 @@ namespace xsimd template ::type> inline T reduce_max(batch const& self, requires_arch) noexcept { - constexpr batch_constant, 5, 6, 7, 8, 0, 0, 0, 0> mask; + constexpr batch_constant mask; batch step = _mm512_permutexvar_epi64((batch)mask, self); batch acc = max(self, step); __m256i low = _mm512_castsi512_si256(acc); @@ -1433,7 +1433,7 @@ namespace xsimd template ::type> inline T reduce_min(batch const& self, requires_arch) noexcept { - constexpr batch_constant, 5, 6, 7, 8, 0, 0, 0, 0> mask; + constexpr batch_constant mask; batch step = _mm512_permutexvar_epi64((batch)mask, self); batch acc = min(self, step); __m256i low = _mm512_castsi512_si256(acc); @@ -1571,7 +1571,7 @@ namespace xsimd } template ::value, void>::type> - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { Values... }, true_br, false_br, avx512f {}); } @@ -1709,7 +1709,7 @@ namespace xsimd // shuffle template inline batch shuffle(batch const& x, batch const& y, - batch_constant, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15> mask, + batch_constant mask, requires_arch) noexcept { constexpr uint32_t smask = (I0 & 0x3) | ((I1 & 0x3) << 2) | ((I2 & 0x3) << 4) | ((I3 & 0x3) << 6); @@ -1726,7 +1726,7 @@ namespace xsimd } template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1, I2, I3, I4, I5, I6, I7> mask, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant mask, requires_arch) noexcept { constexpr uint32_t smask = (I0 & 0x1) | ((I1 & 0x1) << 1) | ((I2 & 0x1) << 2) | ((I3 & 0x1) << 3) | ((I4 & 0x1) << 4) | ((I5 & 0x1) << 5) | ((I6 & 0x1) << 6) | ((I7 & 0x1) << 7); // shuffle within lane @@ -1917,37 +1917,37 @@ namespace xsimd // swizzle (constant version) template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512f {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512f {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512f {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512f {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512f {}); } template - inline batch swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, avx512f {}); } @@ -1973,14 +1973,14 @@ namespace xsimd uint16_t I24, uint16_t I25, uint16_t I26, uint16_t I27, uint16_t I28, uint16_t I29, uint16_t I30, uint16_t I31> struct fold_batch_constant { - using type = batch_constant, I0 / 2, I2 / 2, I4 / 2, I6 / 2, I8 / 2, I10 / 2, I12 / 2, I14 / 2, + using type = batch_constant; }; } template ::value, void>::type> - inline batch swizzle(batch const& self, batch_constant, Idx...>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr typename detail::fold_batch_constant::type mask32; return _mm512_permutexvar_epi32(static_cast>(mask32), self); @@ -1988,13 +1988,13 @@ namespace xsimd template inline batch - swizzle(batch const& self, batch_constant, (uint16_t)1, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1, (uint16_t)0, (uint16_t)1>, requires_arch) noexcept + swizzle(batch const& self, batch_constant, requires_arch) noexcept { // FIXME: this sequence is very inefficient, but it's here to catch // a pattern generated by detail::reduce from xsimd_generic_math.hpp. // The whole pattern is actually decently folded by GCC and Clang, // so bare with it. - constexpr batch_constant, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> mask32; + constexpr batch_constant mask32; auto tmp = _mm512_permutexvar_epi32(static_cast>(mask32), self); alignas(A::alignment()) uint16_t buffer[32]; @@ -2005,7 +2005,7 @@ namespace xsimd template inline batch - swizzle(batch const& self, batch_constant, Vs...> mask, requires_arch) noexcept + swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, avx512f {})); } diff --git a/include/xsimd/arch/xsimd_emulated.hpp b/include/xsimd/arch/xsimd_emulated.hpp index 248d50dfd..ac3dd4fef 100644 --- a/include/xsimd/arch/xsimd_emulated.hpp +++ b/include/xsimd/arch/xsimd_emulated.hpp @@ -24,13 +24,13 @@ namespace xsimd { - template + template struct batch_bool_constant; template inline batch bitwise_cast(batch const& x) noexcept; - template + template struct batch_constant; namespace kernel @@ -41,7 +41,7 @@ namespace xsimd template inline batch insert(batch const& self, T val, index, requires_arch) noexcept; template - inline batch shuffle(batch const& x, batch const& y, batch_constant, Indices...>, requires_arch) noexcept; + inline batch shuffle(batch const& x, batch const& y, batch_constant, requires_arch) noexcept; namespace detail { @@ -599,7 +599,7 @@ namespace xsimd } template - inline batch select(batch_bool_constant, Values...> const& cond, batch const& true_br, batch const& false_br, requires_arch::size>>) noexcept + inline batch select(batch_bool_constant const& cond, batch const& true_br, batch const& false_br, requires_arch::size>>) noexcept { constexpr size_t size = batch::size; static_assert(sizeof...(Values) == size, "consistent init"); @@ -608,7 +608,7 @@ namespace xsimd // shuffle template - inline batch shuffle(batch const& x, batch const& y, batch_constant, Is...> mask, requires_arch::size>>) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant mask, requires_arch::size>>) noexcept { constexpr size_t size = batch::size; batch bmask = mask; @@ -710,7 +710,7 @@ namespace xsimd // swizzle template - inline batch swizzle(batch const& self, batch_constant, Is...> mask, requires_arch::size>>) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch::size>>) noexcept { constexpr size_t size = batch::size; batch bmask = mask; diff --git a/include/xsimd/arch/xsimd_neon.hpp b/include/xsimd/arch/xsimd_neon.hpp index 3510eb21d..b0edae863 100644 --- a/include/xsimd/arch/xsimd_neon.hpp +++ b/include/xsimd/arch/xsimd_neon.hpp @@ -146,7 +146,7 @@ inline float32x4_t vreinterpretq_f32_f32(float32x4_t arg) noexcept { return arg; namespace xsimd { - template + template struct batch_bool_constant; namespace kernel @@ -1743,7 +1743,7 @@ namespace xsimd } template = 0> - inline batch select(batch_bool_constant, b...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { b... }, true_br, false_br, neon {}); } @@ -2717,7 +2717,7 @@ namespace xsimd } } - template + template struct batch_constant; namespace kernel @@ -2728,7 +2728,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, idx...>, + batch_constant, requires_arch) noexcept { static_assert(batch::size == sizeof...(idx), "valid swizzle indices"); diff --git a/include/xsimd/arch/xsimd_neon64.hpp b/include/xsimd/arch/xsimd_neon64.hpp index 77538d1c2..2469b14f3 100644 --- a/include/xsimd/arch/xsimd_neon64.hpp +++ b/include/xsimd/arch/xsimd_neon64.hpp @@ -21,7 +21,7 @@ namespace xsimd { - template + template struct batch_bool_constant; namespace kernel @@ -942,7 +942,7 @@ namespace xsimd } template - inline batch select(batch_bool_constant, b...> const&, + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept @@ -1243,7 +1243,7 @@ namespace xsimd } } - template + template struct batch_constant; namespace kernel @@ -1354,42 +1354,40 @@ namespace xsimd template struct index_burst_impl; - template - struct index_burst_impl, batch_constant, - integer_sequence> + template + struct index_burst_impl, batch_constant, + integer_sequence> { - using type = batch_constant; + using type = batch_constant; }; - template - struct index_burst_impl, batch_constant, - integer_sequence> + template + struct index_burst_impl, batch_constant, + integer_sequence> { - using value_type = typename B2::value_type; - using next_input = batch_constant; - using next_output = batch_constant; - using type = typename index_burst_impl>::type; + using next_input = batch_constant; + using next_output = batch_constant; + using type = typename index_burst_impl>::type; }; template struct index_burst; - template - struct index_burst, T> + template + struct index_burst, T> { - static constexpr size_t mul = sizeof(typename B::value_type) / sizeof(T); - using input = batch_constant; - using output = batch_constant>; + static constexpr size_t mul = sizeof(Tp) / sizeof(T); + using input = batch_constant; + using output = batch_constant; using type = typename index_burst_impl>::type; }; - template + template using index_burst_t = typename index_burst::type; - template + template inline index_burst_t burst_index(B) { return index_burst_t(); @@ -1399,7 +1397,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15> idx, + batch_constant idx, requires_arch) noexcept { return vqtbl1q_u8(self, batch(idx)); @@ -1408,7 +1406,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15> idx, + batch_constant idx, requires_arch) noexcept { return vqtbl1q_s8(self, batch(idx)); @@ -1416,7 +1414,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1425,7 +1423,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1434,7 +1432,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1443,7 +1441,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1452,7 +1450,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1461,7 +1459,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1470,7 +1468,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1, V2, V3> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1479,7 +1477,7 @@ namespace xsimd template inline batch swizzle(batch const& self, - batch_constant, V0, V1> idx, + batch_constant idx, requires_arch) noexcept { using batch_type = batch; @@ -1488,7 +1486,7 @@ namespace xsimd template inline batch, A> swizzle(batch, A> const& self, - batch_constant, V0, V1, V2, V3> idx, + batch_constant idx, requires_arch) noexcept { return batch>(swizzle(self.real(), idx, A()), swizzle(self.imag(), idx, A())); @@ -1496,7 +1494,7 @@ namespace xsimd template inline batch, A> swizzle(batch, A> const& self, - batch_constant, V0, V1> idx, + batch_constant idx, requires_arch) noexcept { return batch>(swizzle(self.real(), idx, A()), swizzle(self.imag(), idx, A())); diff --git a/include/xsimd/arch/xsimd_rvv.hpp b/include/xsimd/arch/xsimd_rvv.hpp index 98d1de9ce..2b8cebe5c 100644 --- a/include/xsimd/arch/xsimd_rvv.hpp +++ b/include/xsimd/arch/xsimd_rvv.hpp @@ -284,7 +284,7 @@ namespace xsimd { - template + template struct batch_constant; namespace kernel @@ -1150,7 +1150,7 @@ namespace xsimd // swizzle template - inline batch swizzle(batch const& arg, batch_constant, idx...>, requires_arch) noexcept + inline batch swizzle(batch const& arg, batch_constant, requires_arch) noexcept { static_assert(batch::size == sizeof...(idx), "invalid swizzle indices"); const batch indices { idx... }; @@ -1159,11 +1159,11 @@ namespace xsimd template inline batch, A> swizzle(batch, A> const& self, - batch_constant, idx...>, + batch_constant, requires_arch) noexcept { - const auto real = swizzle(self.real(), batch_constant, idx...> {}, rvv {}); - const auto imag = swizzle(self.imag(), batch_constant, idx...> {}, rvv {}); + const auto real = swizzle(self.real(), batch_constant {}, rvv {}); + const auto imag = swizzle(self.imag(), batch_constant {}, rvv {}); return batch>(real, imag); } @@ -1188,7 +1188,7 @@ namespace xsimd } template - inline batch select(batch_bool_constant, b...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { b... }, true_br, false_br, rvv {}); } diff --git a/include/xsimd/arch/xsimd_sse2.hpp b/include/xsimd/arch/xsimd_sse2.hpp index 2ee7bd6b2..d733a8c36 100644 --- a/include/xsimd/arch/xsimd_sse2.hpp +++ b/include/xsimd/arch/xsimd_sse2.hpp @@ -20,13 +20,13 @@ namespace xsimd { - template + template struct batch_bool_constant; template inline batch bitwise_cast(batch const& x) noexcept; - template + template struct batch_constant; namespace kernel @@ -59,7 +59,7 @@ namespace xsimd template inline batch insert(batch const& self, T val, index, requires_arch) noexcept; template - inline batch shuffle(batch const& x, batch const& y, batch_constant, Indices...>, requires_arch) noexcept; + inline batch shuffle(batch const& x, batch const& y, batch_constant, requires_arch) noexcept; template inline batch avg(batch const&, batch const&, requires_arch) noexcept; template @@ -1322,7 +1322,7 @@ namespace xsimd return _mm_or_si128(_mm_and_si128(cond, true_br), _mm_andnot_si128(cond, false_br)); } template ::value, void>::type> - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { Values... }, true_br, false_br, sse2 {}); } @@ -1334,7 +1334,7 @@ namespace xsimd // shuffle template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1, I2, I3> mask, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant mask, requires_arch) noexcept { constexpr uint32_t smask = detail::mod_shuffle(I0, I1, I2, I3); // shuffle within lane @@ -1348,7 +1348,7 @@ namespace xsimd } template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1> mask, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant mask, requires_arch) noexcept { constexpr uint32_t smask = detail::mod_shuffle(I0, I1); // shuffle within lane @@ -1601,41 +1601,41 @@ namespace xsimd // swizzle template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr uint32_t index = detail::shuffle(V0, V1, V2, V3); return _mm_shuffle_ps(self, self, index); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr uint32_t index = detail::shuffle(V0, V1); return _mm_shuffle_pd(self, self, index); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr uint32_t index = detail::shuffle(2 * V0, 2 * V0 + 1, 2 * V1, 2 * V1 + 1); return _mm_shuffle_epi32(self, index); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, sse2 {})); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { constexpr uint32_t index = detail::shuffle(V0, V1, V2, V3); return _mm_shuffle_epi32(self, index); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, sse2 {})); } diff --git a/include/xsimd/arch/xsimd_sse4_1.hpp b/include/xsimd/arch/xsimd_sse4_1.hpp index 165a191e4..18cfe38ce 100644 --- a/include/xsimd/arch/xsimd_sse4_1.hpp +++ b/include/xsimd/arch/xsimd_sse4_1.hpp @@ -284,9 +284,9 @@ namespace xsimd } template ::value, void>::type> - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { - constexpr int mask = batch_bool_constant, Values...>::mask(); + constexpr int mask = batch_bool_constant::mask(); XSIMD_IF_CONSTEXPR(sizeof(T) == 2) { return _mm_blend_epi16(false_br, true_br, mask); @@ -304,19 +304,19 @@ namespace xsimd } else { - return select(batch_bool_constant, Values...>(), true_br, false_br, ssse3 {}); + return select(batch_bool_constant(), true_br, false_br, ssse3 {}); } } template - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { - constexpr int mask = batch_bool_constant, Values...>::mask(); + constexpr int mask = batch_bool_constant::mask(); return _mm_blend_ps(false_br, true_br, mask); } template - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { - constexpr int mask = batch_bool_constant, Values...>::mask(); + constexpr int mask = batch_bool_constant::mask(); return _mm_blend_pd(false_br, true_br, mask); } diff --git a/include/xsimd/arch/xsimd_ssse3.hpp b/include/xsimd/arch/xsimd_ssse3.hpp index b6ea11921..9070eaf67 100644 --- a/include/xsimd/arch/xsimd_ssse3.hpp +++ b/include/xsimd/arch/xsimd_ssse3.hpp @@ -140,30 +140,30 @@ namespace xsimd // swizzle (constant mask) template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { - constexpr batch_constant, 2 * V0, 2 * V0 + 1, 2 * V1, 2 * V1 + 1, 2 * V2, 2 * V2 + 1, 2 * V3, 2 * V3 + 1, + constexpr batch_constant mask8; return _mm_shuffle_epi8(self, (batch)mask8); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, ssse3 {})); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, ssse3 {}); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return swizzle(self, (batch)mask, ssse3 {}); } diff --git a/include/xsimd/arch/xsimd_sve.hpp b/include/xsimd/arch/xsimd_sve.hpp index 3177c97b2..7916e6b56 100644 --- a/include/xsimd/arch/xsimd_sve.hpp +++ b/include/xsimd/arch/xsimd_sve.hpp @@ -20,7 +20,7 @@ namespace xsimd { - template + template struct batch_constant; namespace kernel @@ -739,7 +739,7 @@ namespace xsimd // swizzle (static) template - inline batch swizzle(batch const& arg, batch_constant, idx...> indices, requires_arch) noexcept + inline batch swizzle(batch const& arg, batch_constant indices, requires_arch) noexcept { static_assert(batch::size == sizeof...(idx), "invalid swizzle indices"); return swizzle(arg, (batch)indices, sve {}); @@ -747,7 +747,7 @@ namespace xsimd template inline batch, A> swizzle(batch, A> const& arg, - batch_constant, idx...> indices, + batch_constant indices, requires_arch) noexcept { static_assert(batch, A>::size == sizeof...(idx), "invalid swizzle indices"); @@ -811,7 +811,7 @@ namespace xsimd } template - inline batch select(batch_bool_constant, b...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { b... }, true_br, false_br, sve {}); } diff --git a/include/xsimd/arch/xsimd_wasm.hpp b/include/xsimd/arch/xsimd_wasm.hpp index ab9acdc8c..050b1a08f 100644 --- a/include/xsimd/arch/xsimd_wasm.hpp +++ b/include/xsimd/arch/xsimd_wasm.hpp @@ -19,13 +19,13 @@ namespace xsimd { - template + template struct batch_bool_constant; template inline batch bitwise_cast(batch const& x) noexcept; - template + template struct batch_constant; namespace kernel @@ -36,7 +36,7 @@ namespace xsimd template inline batch insert(batch const& self, T val, index, requires_arch) noexcept; template - inline batch shuffle(batch const& x, batch const& y, batch_constant, Indices...>, requires_arch) noexcept; + inline batch shuffle(batch const& x, batch const& y, batch_constant, requires_arch) noexcept; template inline batch avg(batch const&, batch const&, requires_arch) noexcept; @@ -1275,7 +1275,7 @@ namespace xsimd return wasm_v128_or(wasm_v128_and(cond, true_br), wasm_v128_andnot(false_br, cond)); } template ::value, void>::type> - inline batch select(batch_bool_constant, Values...> const&, batch const& true_br, batch const& false_br, requires_arch) noexcept + inline batch select(batch_bool_constant const&, batch const& true_br, batch const& false_br, requires_arch) noexcept { return select(batch_bool { Values... }, true_br, false_br, wasm {}); } @@ -1287,13 +1287,13 @@ namespace xsimd // shuffle template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1, I2, I3>, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant, requires_arch) noexcept { return wasm_i32x4_shuffle(x, y, I0, I1, I2, I3); } template - inline batch shuffle(batch const& x, batch const& y, batch_constant, I0, I1>, requires_arch) noexcept + inline batch shuffle(batch const& x, batch const& y, batch_constant, requires_arch) noexcept { return wasm_i64x2_shuffle(x, y, I0, I1); } @@ -1515,63 +1515,63 @@ namespace xsimd // swizzle template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { return wasm_i32x4_shuffle(self, self, V0, V1, V2, V3); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { return wasm_i64x2_shuffle(self, self, V0, V1); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { return wasm_i64x2_shuffle(self, self, V0, V1); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, wasm {})); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { return wasm_i32x4_shuffle(self, self, V0, V1, V2, V3); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, wasm {})); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { return wasm_i16x8_shuffle(self, self, V0, V1, V2, V3, V4, V5, V6, V7); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, wasm {})); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15>, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant, requires_arch) noexcept { return wasm_i8x16_shuffle(self, self, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15); } template - inline batch swizzle(batch const& self, batch_constant, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15> mask, requires_arch) noexcept + inline batch swizzle(batch const& self, batch_constant mask, requires_arch) noexcept { return bitwise_cast(swizzle(bitwise_cast(self), mask, wasm {})); } diff --git a/include/xsimd/types/xsimd_api.hpp b/include/xsimd/types/xsimd_api.hpp index 78e70f6a5..138c9642d 100644 --- a/include/xsimd/types/xsimd_api.hpp +++ b/include/xsimd/types/xsimd_api.hpp @@ -2031,7 +2031,7 @@ namespace xsimd * @return the result of the selection. */ template - inline batch select(batch_bool_constant, Values...> const& cond, batch const& true_br, batch const& false_br) noexcept + inline batch select(batch_bool_constant const& cond, batch const& true_br, batch const& false_br) noexcept { detail::static_check_supported_config(); return kernel::select(cond, true_br, false_br, A {}); @@ -2047,7 +2047,7 @@ namespace xsimd * element of \c x and \c y. Each element of the mask index the vector that * would be formed by the concatenation of \c x and \c y. For instance * \code{.cpp} - * batch_constant, 0, 4, 3, 7> + * batch_constant * \endcode * Picks \c x[0], \c y[0], \c x[3], \c y[3] * @@ -2055,7 +2055,7 @@ namespace xsimd */ template inline typename std::enable_if::value, batch>::type - shuffle(batch const& x, batch const& y, batch_constant, Values...> mask) noexcept + shuffle(batch const& x, batch const& y, batch_constant mask) noexcept { static_assert(sizeof(T) == sizeof(Vt), "consistent mask"); detail::static_check_supported_config(); @@ -2357,14 +2357,14 @@ namespace xsimd */ template inline typename std::enable_if::value, batch>::type - swizzle(batch const& x, batch_constant, Values...> mask) noexcept + swizzle(batch const& x, batch_constant mask) noexcept { static_assert(sizeof(T) == sizeof(Vt), "consistent mask"); detail::static_check_supported_config(); return kernel::swizzle(x, mask, A {}); } template - inline batch, A> swizzle(batch, A> const& x, batch_constant, Values...> mask) noexcept + inline batch, A> swizzle(batch, A> const& x, batch_constant mask) noexcept { static_assert(sizeof(T) == sizeof(Vt), "consistent mask"); detail::static_check_supported_config(); diff --git a/include/xsimd/types/xsimd_batch_constant.hpp b/include/xsimd/types/xsimd_batch_constant.hpp index 0de9c8ad4..ce304d20d 100644 --- a/include/xsimd/types/xsimd_batch_constant.hpp +++ b/include/xsimd/types/xsimd_batch_constant.hpp @@ -25,17 +25,16 @@ namespace xsimd * @tparam batch_type the type of the associated batch values. * @tparam Values boolean constant represented by this batch **/ - template + template struct batch_bool_constant { - - public: + using batch_type = batch_bool; static constexpr std::size_t size = sizeof...(Values); - using arch_type = typename batch_type::arch_type; using value_type = bool; static_assert(sizeof...(Values) == batch_type::size, "consistent batch size"); - constexpr operator batch_bool() const noexcept { return { Values... }; } + public: + constexpr operator batch_bool() const noexcept { return { Values... }; } constexpr bool get(size_t i) const noexcept { @@ -70,14 +69,14 @@ namespace xsimd }; template - static constexpr batch_bool_constant::type::value, std::tuple_element::type::value)...> + static constexpr batch_bool_constant::type::value, std::tuple_element::type::value)...> apply(detail::index_sequence) { return {}; } template - static constexpr auto apply(batch_bool_constant, batch_bool_constant) + static constexpr auto apply(batch_bool_constant, batch_bool_constant) -> decltype(apply...>, std::tuple...>>(detail::make_index_sequence())) { static_assert(sizeof...(Values) == sizeof...(OtherValues), "compatible constant batches"); @@ -85,12 +84,12 @@ namespace xsimd } public: -#define MAKE_BINARY_OP(OP, NAME) \ - template \ - constexpr auto operator OP(batch_bool_constant other) const \ - -> decltype(apply(*this, other)) \ - { \ - return apply(*this, other); \ +#define MAKE_BINARY_OP(OP, NAME) \ + template \ + constexpr auto operator OP(batch_bool_constant other) const \ + -> decltype(apply(*this, other)) \ + { \ + return apply(*this, other); \ } MAKE_BINARY_OP(|, logical_or) @@ -101,12 +100,12 @@ namespace xsimd #undef MAKE_BINARY_OP - constexpr batch_bool_constant operator!() const + constexpr batch_bool_constant operator!() const { return {}; } - constexpr batch_bool_constant operator~() const + constexpr batch_bool_constant operator~() const { return {}; } @@ -120,11 +119,11 @@ namespace xsimd * @tparam batch_type the type of the associated batch values. * @tparam Values constants represented by this batch **/ - template + template struct batch_constant { static constexpr std::size_t size = sizeof...(Values); - using arch_type = typename batch_type::arch_type; + using batch_type = batch; using value_type = typename batch_type::value_type; static_assert(sizeof...(Values) == batch_type::size, "consistent batch size"); @@ -136,72 +135,72 @@ namespace xsimd /** * @brief Get the @p i th element of this @p batch_constant */ - constexpr value_type get(size_t i) const noexcept + constexpr T get(size_t i) const noexcept { - return get(i, std::array { Values... }); + return get(i, std::array { Values... }); } private: - constexpr value_type get(size_t i, std::array const& values) const noexcept + constexpr T get(size_t i, std::array const& values) const noexcept { return values[i]; } struct arithmetic_add { - constexpr value_type operator()(value_type x, value_type y) const { return x + y; } + constexpr T operator()(T x, T y) const { return x + y; } }; struct arithmetic_sub { - constexpr value_type operator()(value_type x, value_type y) const { return x - y; } + constexpr T operator()(T x, T y) const { return x - y; } }; struct arithmetic_mul { - constexpr value_type operator()(value_type x, value_type y) const { return x * y; } + constexpr T operator()(T x, T y) const { return x * y; } }; struct arithmetic_div { - constexpr value_type operator()(value_type x, value_type y) const { return x / y; } + constexpr T operator()(T x, T y) const { return x / y; } }; struct arithmetic_mod { - constexpr value_type operator()(value_type x, value_type y) const { return x % y; } + constexpr T operator()(T x, T y) const { return x % y; } }; struct binary_and { - constexpr value_type operator()(value_type x, value_type y) const { return x & y; } + constexpr T operator()(T x, T y) const { return x & y; } }; struct binary_or { - constexpr value_type operator()(value_type x, value_type y) const { return x | y; } + constexpr T operator()(T x, T y) const { return x | y; } }; struct binary_xor { - constexpr value_type operator()(value_type x, value_type y) const { return x ^ y; } + constexpr T operator()(T x, T y) const { return x ^ y; } }; template - static constexpr batch_constant::type::value, std::tuple_element::type::value)...> + static constexpr batch_constant::type::value, std::tuple_element::type::value)...> apply(detail::index_sequence) { return {}; } - template - static constexpr auto apply(batch_constant, batch_constant) - -> decltype(apply...>, std::tuple...>>(detail::make_index_sequence())) + template + static constexpr auto apply(batch_constant, batch_constant) + -> decltype(apply...>, std::tuple...>>(detail::make_index_sequence())) { static_assert(sizeof...(Values) == sizeof...(OtherValues), "compatible constant batches"); - return apply...>, std::tuple...>>(detail::make_index_sequence()); + return apply...>, std::tuple...>>(detail::make_index_sequence()); } public: -#define MAKE_BINARY_OP(OP, NAME) \ - template \ - constexpr auto operator OP(batch_constant other) const \ - -> decltype(apply(*this, other)) \ - { \ - return apply(*this, other); \ +#define MAKE_BINARY_OP(OP, NAME) \ + template \ + constexpr auto operator OP(batch_constant other) const \ + -> decltype(apply(*this, other)) \ + { \ + return apply(*this, other); \ } MAKE_BINARY_OP(+, arithmetic_add) @@ -215,17 +214,17 @@ namespace xsimd #undef MAKE_BINARY_OP - constexpr batch_constant operator-() const + constexpr batch_constant operator-() const { return {}; } - constexpr batch_constant operator+() const + constexpr batch_constant operator+() const { return {}; } - constexpr batch_constant operator~() const + constexpr batch_constant operator~() const { return {}; } @@ -233,15 +232,15 @@ namespace xsimd namespace detail { - template + template inline constexpr auto make_batch_constant(detail::index_sequence) noexcept - -> batch_constant + -> batch_constant { return {}; } - template + template inline constexpr auto make_batch_bool_constant(detail::index_sequence) noexcept - -> batch_bool_constant + -> batch_bool_constant { return {}; } @@ -268,19 +267,19 @@ namespace xsimd * }; * @endcode */ - template - inline constexpr auto make_batch_constant() noexcept -> decltype(detail::make_batch_constant(detail::make_index_sequence())) + template + inline constexpr auto make_batch_constant() noexcept -> decltype(detail::make_batch_constant(detail::make_index_sequence::size>())) { - return detail::make_batch_constant(detail::make_index_sequence()); + return detail::make_batch_constant(detail::make_index_sequence::size>()); } - template + template inline constexpr auto make_batch_bool_constant() noexcept - -> decltype(detail::make_batch_bool_constant( - detail::make_index_sequence())) + -> decltype(detail::make_batch_bool_constant( + detail::make_index_sequence::size>())) { - return detail::make_batch_bool_constant( - detail::make_index_sequence()); + return detail::make_batch_bool_constant( + detail::make_index_sequence::size>()); } } // namespace xsimd diff --git a/test/test_batch_constant.cpp b/test/test_batch_constant.cpp index 7b00acc4e..384020fe0 100644 --- a/test/test_batch_constant.cpp +++ b/test/test_batch_constant.cpp @@ -19,6 +19,7 @@ struct constant_batch_test { using batch_type = B; using value_type = typename B::value_type; + using arch_type = typename B::arch_type; static constexpr size_t size = B::size; using array_type = std::array; using bool_array_type = std::array; @@ -39,7 +40,7 @@ struct constant_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return generator::get(i++, size); }); - constexpr auto b = xsimd::make_batch_constant(); + constexpr auto b = xsimd::make_batch_constant(); INFO("batch(value_type)"); CHECK_BATCH_EQ((batch_type)b, expected); } @@ -59,7 +60,7 @@ struct constant_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return arange::get(i++, size); }); - constexpr auto b = xsimd::make_batch_constant(); + constexpr auto b = xsimd::make_batch_constant(); INFO("batch(value_type)"); CHECK_BATCH_EQ((batch_type)b, expected); } @@ -77,34 +78,34 @@ struct constant_batch_test { array_type expected; std::fill(expected.begin(), expected.end(), constant<3>::get(0, 0)); - constexpr auto b = xsimd::make_batch_constant>(); + constexpr auto b = xsimd::make_batch_constant>(); INFO("batch(value_type)"); CHECK_BATCH_EQ((batch_type)b, expected); } void test_ops() const { - constexpr auto n12 = xsimd::make_batch_constant>(); - constexpr auto n3 = xsimd::make_batch_constant>(); + constexpr auto n12 = xsimd::make_batch_constant>(); + constexpr auto n3 = xsimd::make_batch_constant>(); constexpr auto n12_add_n3 = n12 + n3; - constexpr auto n15 = xsimd::make_batch_constant>(); + constexpr auto n15 = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "n12 + n3 == n15"); constexpr auto n12_sub_n3 = n12 - n3; - constexpr auto n9 = xsimd::make_batch_constant>(); + constexpr auto n9 = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "n12 - n3 == n9"); constexpr auto n12_mul_n3 = n12 * n3; - constexpr auto n36 = xsimd::make_batch_constant>(); + constexpr auto n36 = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "n12 * n3 == n36"); constexpr auto n12_div_n3 = n12 / n3; - constexpr auto n4 = xsimd::make_batch_constant>(); + constexpr auto n4 = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "n12 / n3 == n4"); constexpr auto n12_mod_n3 = n12 % n3; - constexpr auto n0 = xsimd::make_batch_constant>(); + constexpr auto n0 = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "n12 % n3 == n0"); constexpr auto n12_land_n3 = n12 & n3; @@ -120,11 +121,11 @@ struct constant_batch_test static_assert(std::is_same::value, "+n12 == n12"); constexpr auto n12_inv = ~n12; - constexpr auto n12_inv_ = xsimd::make_batch_constant>(); + constexpr auto n12_inv_ = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "~n12 == n12_inv"); constexpr auto n12_usub = -n12; - constexpr auto n12_usub_ = xsimd::make_batch_constant>(); + constexpr auto n12_usub_ = xsimd::make_batch_constant>(); static_assert(std::is_same::value, "-n12 == n12_usub"); } }; @@ -152,6 +153,7 @@ struct constant_bool_batch_test { using batch_type = B; using value_type = typename B::value_type; + using arch_type = typename B::arch_type; static constexpr size_t size = B::size; using array_type = std::array; using bool_array_type = std::array; @@ -172,7 +174,7 @@ struct constant_bool_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return generator::get(i++, size); }); - constexpr auto b = xsimd::make_batch_bool_constant(); + constexpr auto b = xsimd::make_batch_bool_constant(); INFO("batch_bool_constant(value_type)"); CHECK_BATCH_EQ((batch_bool_type)b, expected); } @@ -192,7 +194,7 @@ struct constant_bool_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return split::get(i++, size); }); - constexpr auto b = xsimd::make_batch_bool_constant(); + constexpr auto b = xsimd::make_batch_bool_constant(); INFO("batch_bool_constant(value_type)"); CHECK_BATCH_EQ((batch_bool_type)b, expected); } @@ -216,11 +218,11 @@ struct constant_bool_batch_test void test_ops() const { - constexpr auto all_true = xsimd::make_batch_bool_constant>(); - constexpr auto all_false = xsimd::make_batch_bool_constant>(); + constexpr auto all_true = xsimd::make_batch_bool_constant>(); + constexpr auto all_false = xsimd::make_batch_bool_constant>(); - constexpr auto x = xsimd::make_batch_bool_constant(); - constexpr auto y = xsimd::make_batch_bool_constant(); + constexpr auto x = xsimd::make_batch_bool_constant(); + constexpr auto y = xsimd::make_batch_bool_constant(); constexpr auto x_or_y = x | y; static_assert(std::is_same::value, "x | y == true"); diff --git a/test/test_batch_manip.cpp b/test/test_batch_manip.cpp index 5113f4bac..ad25284b8 100644 --- a/test/test_batch_manip.cpp +++ b/test/test_batch_manip.cpp @@ -87,8 +87,8 @@ struct as_index using type = xsimd::as_unsigned_integer_t; }; -template -struct as_index, A>> : as_index> +template +struct as_index> : as_index { }; @@ -145,6 +145,7 @@ struct swizzle_test { using batch_type = B; using value_type = typename B::value_type; + using arch_type = typename B::arch_type; static constexpr size_t size = B::size; void rotate_right() @@ -185,13 +186,13 @@ struct swizzle_test B b_lhs = B::load_unaligned(v_lhs.data()); B b_exped = B::load_unaligned(v_exped.data()); - using index_type = typename as_index::type; - auto index_batch = xsimd::make_batch_constant>(); + using index_type = typename as_index::type; + auto index_batch = xsimd::make_batch_constant>(); B b_res = xsimd::swizzle(b_lhs, index_batch); CHECK_BATCH_EQ(b_res, b_exped); - B b_dyres = xsimd::swizzle(b_lhs, (index_type)index_batch); + B b_dyres = xsimd::swizzle(b_lhs, (xsimd::batch)index_batch); CHECK_BATCH_EQ(b_dyres, b_exped); } @@ -205,13 +206,13 @@ struct swizzle_test B b_lhs = B::load_unaligned(v_lhs.data()); B b_exped = B::load_unaligned(v_exped.data()); - using index_type = typename as_index::type; - auto index_batch = xsimd::make_batch_constant>(); + using index_type = typename as_index::type; + auto index_batch = xsimd::make_batch_constant>(); B b_res = xsimd::swizzle(b_lhs, index_batch); CHECK_BATCH_EQ(b_res, b_exped); - B b_dyres = xsimd::swizzle(b_lhs, (index_type)index_batch); + B b_dyres = xsimd::swizzle(b_lhs, (xsimd::batch)index_batch); CHECK_BATCH_EQ(b_dyres, b_exped); } @@ -225,13 +226,13 @@ struct swizzle_test B b_lhs = B::load_unaligned(v_lhs.data()); B b_exped = B::load_unaligned(v_exped.data()); - using index_type = typename as_index::type; - auto index_batch = xsimd::make_batch_constant>(); + using index_type = typename as_index::type; + auto index_batch = xsimd::make_batch_constant>(); B b_res = xsimd::swizzle(b_lhs, index_batch); CHECK_BATCH_EQ(b_res, b_exped); - B b_dyres = xsimd::swizzle(b_lhs, (index_type)index_batch); + B b_dyres = xsimd::swizzle(b_lhs, (xsimd::batch)index_batch); CHECK_BATCH_EQ(b_dyres, b_exped); } }; diff --git a/test/test_select.cpp b/test/test_select.cpp index 19256efcf..436ea647e 100644 --- a/test/test_select.cpp +++ b/test/test_select.cpp @@ -19,6 +19,7 @@ struct select_test { using batch_type = B; using value_type = typename B::value_type; + using arch_type = typename B::arch_type; static constexpr size_t size = B::size; using vector_type = std::vector; @@ -67,7 +68,7 @@ struct select_test void test_select_static() { - constexpr auto mask = xsimd::make_batch_bool_constant(); + constexpr auto mask = xsimd::make_batch_bool_constant(); for (size_t i = 0; i < nb_input; ++i) { diff --git a/test/test_shuffle.cpp b/test/test_shuffle.cpp index 5b03a20e5..3ea9dca4d 100644 --- a/test/test_shuffle.cpp +++ b/test/test_shuffle.cpp @@ -469,7 +469,8 @@ struct shuffle_test { using batch_type = B; using value_type = typename B::value_type; - using mask_batch_type = xsimd::as_unsigned_integer_t; + using arch_type = typename B::arch_type; + using mask_type = xsimd::as_unsigned_integer_t; static constexpr size_t size = B::size; std::array lhs; std::array rhs; @@ -497,7 +498,7 @@ struct shuffle_test }; INFO("no op lhs"); - B b_res_lhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_lhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_lhs, b_lhs); struct no_op_rhs_generator @@ -509,7 +510,7 @@ struct shuffle_test }; INFO("no op rhs"); - B b_res_rhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_rhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_rhs, b_rhs); } @@ -534,7 +535,7 @@ struct shuffle_test } B b_ref = B::load_unaligned(ref.data()); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -556,7 +557,7 @@ struct shuffle_test ref[i] = (i > 2) ? lhs[0] : rhs[0]; B b_ref = B::load_unaligned(ref.data()); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -580,7 +581,7 @@ struct shuffle_test B b_ref = B::load_unaligned(ref.data()); INFO("swizzle first batch"); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -599,7 +600,7 @@ struct shuffle_test B b_ref = B::load_unaligned(ref.data()); INFO("swizzle second batch"); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } } @@ -623,7 +624,7 @@ struct shuffle_test B b_ref = B::load_unaligned(ref.data()); INFO("select"); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -646,7 +647,7 @@ struct shuffle_test B b_ref_lo = B::load_unaligned(ref_lo.data()); INFO("zip_lo"); - B b_res_lo = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_lo = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_lo, b_ref_lo); struct zip_hi_generator @@ -665,7 +666,7 @@ struct shuffle_test B b_ref_hi = B::load_unaligned(ref_hi.data()); INFO("zip_hi"); - B b_res_hi = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_hi = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_hi, b_ref_hi); } };