Skip to content

Commit fc2659d

Browse files
Provide a generic implementation of swizzle with constant mask
As a side effect, improve test coverage for swizzle to all integer types.
1 parent 8696ba5 commit fc2659d

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/xsimd/arch/common/xsimd_common_details.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ namespace xsimd
9090
XSIMD_INLINE std::pair<batch<T, A>, batch<T, A>> sincos(batch<T, A> const& self) noexcept;
9191
template <class T, class A>
9292
XSIMD_INLINE batch<T, A> sqrt(batch<T, A> const& self) noexcept;
93+
template <class T, class A, class Vt, Vt... Values>
94+
XSIMD_INLINE typename std::enable_if<std::is_arithmetic<T>::value, batch<T, A>>::type
95+
swizzle(batch<T, A> const& x, batch_constant<Vt, A, Values...> mask) noexcept;
9396
template <class T, class A>
9497
XSIMD_INLINE batch<T, A> tan(batch<T, A> const& self) noexcept;
9598
template <class T, class A>

include/xsimd/arch/common/xsimd_common_memory.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ namespace xsimd
341341
}
342342
};
343343

344-
return swizzle(self, make_batch_constant<as_unsigned_integer_t<T>, rotate_generator, A>(), A {});
344+
return swizzle(self, make_batch_constant<as_unsigned_integer_t<T>, rotate_generator, A>());
345345
}
346346

347347
template <size_t N, class A, class T>
@@ -362,7 +362,7 @@ namespace xsimd
362362
}
363363
};
364364

365-
return swizzle(self, make_batch_constant<as_unsigned_integer_t<T>, rotate_generator, A>(), A {});
365+
return swizzle(self, make_batch_constant<as_unsigned_integer_t<T>, rotate_generator, A>());
366366
}
367367

368368
template <size_t N, class A, class T>
@@ -611,6 +611,15 @@ namespace xsimd
611611
return batch<T, A>::load_aligned(out_buffer);
612612
}
613613

614+
template <class A, class T, class ITy, ITy... Is>
615+
XSIMD_INLINE batch<T, A> swizzle(batch<T, A> const& self, batch_constant<ITy, A, Is...>, requires_arch<common>) noexcept
616+
{
617+
constexpr size_t size = batch<T, A>::size;
618+
alignas(A::alignment()) T self_buffer[size];
619+
store_aligned(&self_buffer[0], self);
620+
return { self_buffer[Is]... };
621+
}
622+
614623
template <class A, class T, class ITy>
615624
XSIMD_INLINE batch<std::complex<T>, A> swizzle(batch<std::complex<T>, A> const& self, batch<ITy, A> mask, requires_arch<common>) noexcept
616625
{

test/test_utils.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,7 @@ namespace xsimd
591591
#define BATCH_TYPES BATCH_INT_TYPES, BATCH_FLOAT_TYPES
592592
#define BATCH_MATH_TYPES xsimd::batch<int32_t>, BATCH_FLOAT_TYPES
593593

594-
#if !XSIMD_WITH_AVX || XSIMD_WITH_AVX2
595-
#define BATCH_SWIZZLE_TAIL , xsimd::batch<uint32_t>, xsimd::batch<int32_t>, xsimd::batch<uint64_t>, xsimd::batch<int64_t>
596-
#else
597-
#define BATCH_SWIZZLE_TAIL
598-
#endif
599-
600-
#define BATCH_SWIZZLE_TYPES BATCH_FLOAT_TYPES, BATCH_COMPLEX_TYPES BATCH_SWIZZLE_TAIL
594+
#define BATCH_SWIZZLE_TYPES BATCH_FLOAT_TYPES, BATCH_COMPLEX_TYPES, BATCH_INT_TYPES
601595

602596
/********************
603597
* conversion utils *

0 commit comments

Comments
 (0)