Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/xvec/detail/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ concept generated_value_convertible_to =
template<typename _Gen, typename _Tp, simd_size_type _Idx>
concept generator_invocable_at =
requires(_Gen __gen) {
{ __gen(_Idx) } -> generated_value_convertible_to<_Tp>;
{ __gen(std::integral_constant<simd_size_type, _Idx>{}) }
-> generated_value_convertible_to<_Tp>;
};

template<typename _Gen, typename _Tp, int _Size>
Expand Down
2 changes: 1 addition & 1 deletion include/xvec/detail/mask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class basic_mask
/// construct pre-computed mask values.
/// @ingroup simd_mask_constructor
/// @param fn The generator function to compute each bit.
constexpr basic_mask(std::invocable<simd_size_type> auto fn) : basic_mask(detail::generate_mask<basic_mask>(target, fn)) {}
constexpr basic_mask(std::invocable<std::integral_constant<simd_size_type, 0>> auto fn) : basic_mask(detail::generate_mask<basic_mask>(target, fn)) {}

/// Generate a mask which represents the bottom N bits of the mask.
/// @internal
Expand Down
2 changes: 1 addition & 1 deletion include/xvec/detail/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ constexpr void checkStaticMemoryBounds([[maybe_unused]] const std::string& op_na
{
#if defined(XVEC_ALWAYS_RANGE_CHECK_MEMORY)
auto biggestIndex = reduce_max(indexes, m);
if (biggestIndex >= range_size)
if (std::size_t(biggestIndex) >= range_size)
{
std::string msg =
"xvec range error for " + op_name + ". Range size:" + std::to_string(range_size) +
Expand Down
23 changes: 13 additions & 10 deletions include/xvec/generic/generic_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ constexpr auto generate(_Gp generator) {
if constexpr (complex_number<typename _Vp::value_type>)
{
using _Tp = typename _Vp::traits::element_type;
return _Vp([=]<std::size_t... _Idx>(std::index_sequence<_Idx...>) {
return typename _Vp::traits::builtin_type{_Tp((_Idx % 2) ? generator(_Idx / 2).imag() : generator(_Idx / 2).real())...};
}(std::make_index_sequence<_Vp::size() * 2>()));
return _Vp([=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>) {
return typename _Vp::traits::builtin_type{_Tp((_Idx % 2) ?
generator(size_constant<_Idx / 2>()).imag() :
generator(size_constant<_Idx / 2>()).real())...};
}(std::make_integer_sequence<simd_size_type, _Vp::size() * 2>()));
}
else
{
return _Vp([=]<std::size_t... _Idx>(std::index_sequence<_Idx...>) {
return typename _Vp::traits::builtin_type{std::bit_cast<typename _Vp::traits::element_type>(generator(_Idx))...};
}(std::make_index_sequence<_Vp::size()>()));
return _Vp([=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>) {
return typename _Vp::traits::builtin_type{std::bit_cast<typename _Vp::traits::element_type>(
generator(size_constant<_Idx>{}))...};
}(std::make_integer_sequence<simd_size_type, _Vp::size()>()));
}
}

Expand Down Expand Up @@ -151,18 +154,18 @@ constexpr _Mp generate_mask(generic_tag, _Gp generator) {
using _Tp = container_for_num_bytes<simd_mask_element_size_v<_Mp>>;
using _Vp = typename _Mp::builtin_type;

auto r = [=]<std::size_t... _Idx>(std::index_sequence<_Idx...>) {
auto r = [=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>) {
return _Vp{_Tp(generator(size_constant<_Idx>()) ? ~_Tp() : _Tp())...};
}(std::make_index_sequence<_Mp::size()>());
}(std::make_integer_sequence<simd_size_type, _Mp::size()>());

return _Mp::from_builtin(r);
}

template<mask_type _Mp, typename _Gp>
constexpr _Mp generate_mask(compact_mask_tag, _Gp generator) {
return _Mp::from_builtin([=]<std::size_t... _Idx>(std::index_sequence<_Idx...>) {
return _Mp::from_builtin([=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>) {
return ((typename _Mp::builtin_type(generator(size_constant<_Idx>{})) << _Idx) | ...);
} (std::make_index_sequence<_Mp::size>()));
} (std::make_integer_sequence<simd_size_type, _Mp::size()>()));
}
///@}

Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ target_compile_options(
-Wextra
-Werror
-Wno-psabi
-Wno-sign-compare
"${XVEC_TEST_OLEVEL}"
-fno-fast-math
)
Expand Down
2 changes: 1 addition & 1 deletion test/SimdTestUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ GetConstexprRandomVector (int limit = 32)
limit = limit * 2;

// Hashy-like algorithm to pick a number. Relies on the position and the incoming `seed` index.
auto genRnd = [=](auto i) -> typename _V::value_type
auto genRnd = [=](xvec::simd::simd_size_type i) -> typename _V::value_type
{
auto v = (r[(i + 7) & 0xF] ^ std::rotl(r[(i + index) & 0xF], i)) % int(limit);
if (hasNegative && ((v & 1) == 1))
Expand Down
4 changes: 3 additions & 1 deletion test/TestSimdBit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(BitReverse, TypeParam, UnsignedSimdTypes)
#if defined(_XVEC_HAS_CONSTEXPR)
{
constexpr auto cv = GetConstexprRandomVector<TypeParam, 1011>();
static_assert(to_array(bit_reverse(cv)) == applyUnaryToArray(cv, expected_bit_reverse));
constexpr auto reversed = bit_reverse(cv);
constexpr auto expected = applyUnaryToArray(cv, expected_bit_reverse);
static_assert(to_array(reversed) == expected);
}
#endif
}
Expand Down
24 changes: 24 additions & 0 deletions test/TestSimdConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,30 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Generator, TypeParam, AllSimdTypes)
BOOST_TEST(to_array(computedConstexpr) == expected, boost::test_tools::per_element());
}

BOOST_AUTO_TEST_CASE(GeneratorIndexType)
{
using Vec = xvec::simd::vec<int, 4>;
using ComplexVec = xvec::simd::vec<std::complex<float>, 4>;
using xvec::simd::simd_size_type;

// Check that the generator passes a compile-time constant of the correct type.
const Vec computed([]<simd_size_type I>(std::integral_constant<simd_size_type, I>) -> int {
return I + 2;
});
const std::array<int, 4> expected{2, 3, 4, 5};
BOOST_TEST(to_array(computed) == expected, boost::test_tools::per_element());

// Same again, but for complex (which currently uses a different code path).
const ComplexVec complexComputed([]<simd_size_type I>(
std::integral_constant<simd_size_type, I>) -> std::complex<float> {
return {float(I + 2), float(I + 12)};
});
const std::array<std::complex<float>, 4> complexExpected{{
{2.0f, 12.0f}, {3.0f, 13.0f}, {4.0f, 14.0f}, {5.0f, 15.0f}
}};
BOOST_TEST(to_array(complexComputed) == complexExpected, boost::test_tools::per_element());
}

void CheckDisallowedGenerators()
{
struct S {
Expand Down
12 changes: 12 additions & 0 deletions test/TestSimdMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(InitialiseFromGenerator, TypeParam, AllSimdMaskTyp
#endif
}

BOOST_AUTO_TEST_CASE(GeneratorIndexType)
{
using Mask = xvec::simd::mask<int, 4>;
using xvec::simd::simd_size_type;

// Only accepts integral_constant<simd_size_type, I>, not a plain index.
const Mask computed([]<simd_size_type I>(std::integral_constant<simd_size_type, I>) -> bool
{ return I == 0 || I == 3; });

BOOST_TEST(computed.to_bitset() == std::bitset<4>(0b1001));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(InitialiseNbitMask, TypeParam, AllSimdMaskTypes)
{
using xvec::simd::mask_from_count;
Expand Down
Loading