61constexpr auto chunked_invoke(_Fn fn,
const _Arg0& arg0,
const _Args&... args)
66 static_assert(are_all_sizes_equal<_Arg0::size(), _Args::size()...>,
"chunked_invoke expects all vec or mask arguments to have the same size");
69 static_assert(_SuggestedN != 0 || are_all_sizes_equal<arg_native_size<_Arg0>, arg_native_size<_Args>...>,
"chunked_invoke expects all vec or mask arguments to have the same native size. Use the first template parameter to override this");
72 constexpr auto _B = _SuggestedN == 0 ? arg_native_size<_Arg0> : _SuggestedN;
75 constexpr auto _TS = std::min<simd_size_type>(_B, _Arg0::size());
76 using ArgTypesWithoutIndex = std::tuple<resize_t<_TS, _Arg0>, resize_t<_TS, _Args>...>;
77 using ArgTypesWithIndex = std::tuple<resize_t<_TS, _Arg0>, resize_t<_TS, _Args>..., simd_size_type>;
80 static_assert(callableWithIndex || callableWithoutIndex,
"chunked_invoke can't call the function");
81 using ArgTypes = std::conditional_t<callableWithIndex, ArgTypesWithIndex, ArgTypesWithoutIndex>;
86 using ResultType =
decltype(std::apply(fn, ArgTypes()));
87 constexpr bool isVoidFn = std::same_as<void, ResultType>;
88 static_assert(isVoidFn ||
vec_or_mask_type<ResultType>,
"chunked_invoke expects the function to return a vec or mask result, or none at all");
91 auto callFn = [&]<simd_size_type _Begin>(size_constant<_Begin>) {
92 constexpr int _End = std::min<int>(_Begin + _B, _Arg0::size());
93 if constexpr (callableWithoutIndex)
100 constexpr int numBlocks = (_Arg0::size() + (_B - 1)) / _B;
101 return [=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>)
104 if constexpr (isVoidFn)
105 (callFn(size_constant<_Idx * _B>{}), ...);
109 auto results = std::tuple { callFn(size_constant<_Idx * _B>{})... };
112 return std::apply([](
auto&&... r) {
return cat(std::forward<
decltype(r)>(r)...); }, results);
114 }(std::make_integer_sequence<simd_size_type, numBlocks>{});
constexpr auto cat(const basic_mask< _Bytes, _Abis > &... masks) noexcept
Concatenate several smaller mask values with the same element size into a single large mask value.
Definition split_concat.hpp:144
constexpr auto chunked_invoke(_Fn fn, const _Arg0 &arg0, const _Args &... args)
Invoke a callable on corresponding vector or mask chunks.
Definition invoke.hpp:61
constexpr resize_t< _End - _Begin, _Vp > extract(const _Vp &v)
Extract the subset denoted by the range [begin..end) from the supplied vec or mask.
Definition named_permute.hpp:304