Intel xvec
Experimental C++ simd class library
Loading...
Searching...
No Matches
C++26: Vector and mask creation

Split vectors and masks into chunks, or concatenate them into larger values. More...

Functions

template<simd_size_type _Np, vec_or_mask_type _S>
constexpr auto xvec::simd::chunk (const _S &container) noexcept
template<typename _V, typename _Abi>
constexpr auto xvec::simd::chunk (const basic_vec< typename _V::value_type, _Abi > &s) noexcept
template<mask_type _M, typename _Abi>
constexpr auto xvec::simd::chunk (const basic_mask< simd_mask_element_size_v< _M >, _Abi > &m) noexcept
template<std::size_t _Bytes, typename... _Abis>
constexpr auto xvec::simd::cat (const basic_mask< _Bytes, _Abis > &... masks) noexcept
 Concatenate several smaller mask values with the same element size into a single large mask value.
template<typename _Tp, typename... _Abis>
constexpr auto xvec::simd::cat (const basic_vec< _Tp, _Abis > &... vecs) noexcept
 Concatenate several smaller vec values with the same element type into a single large value. The result is the same size as the concatenation of the incoming containers.
template<vec_type _Vp>
constexpr auto xvec::simd::vec_as_container (const _Vp &v)
 Generate a variable containing the iota sequence (i.e., 0, 1, 2, ... size-1) for the given simd::vec type. This can be used as the basis of generating other sequences, including those used in constexpr scenarios. For example, to generate all multiples of 3 you can do `iota<T> * 3'. Using the constexpr nature of iota, along with the constexpr operations and functions makes it natural to build simd::vec constants with particular properties. Perhaps even easier than using the generator constructor.
template<mask_type _Mp>
constexpr auto xvec::simd::vec_as_container (const _Mp &m)
 The mask equivalent uses the negate operation to generate the implementation builtin mask.

Detailed Description

Split vectors and masks into chunks, or concatenate them into larger values.

See also
https://wg21.link/P3441R2

Function Documentation

◆ cat() [1/2]

template<std::size_t _Bytes, typename... _Abis>
auto xvec::simd::cat ( const basic_mask< _Bytes, _Abis > &... masks)
constexprnoexcept

Concatenate several smaller mask values with the same element size into a single large mask value.

Template Parameters
_BytesThe element size represented by each mask
_AbisMultiple parameter ABIs which specify the size of each incoming mask
Parameters
masksMultiple masks to concatenate together
Returns
A mask containing all incoming mask elements in argument order.

◆ cat() [2/2]

template<typename _Tp, typename... _Abis>
auto xvec::simd::cat ( const basic_vec< _Tp, _Abis > &... vecs)
constexprnoexcept

Concatenate several smaller vec values with the same element type into a single large value. The result is the same size as the concatenation of the incoming containers.

Template Parameters
_TpThe element type of the vec
_AbisMultiple parameter ABIs which specify the size of each incoming vec.
Parameters
vecsMultiple vec values to concatenate together.
Returns
A single vec which is the same size as all the incoming vec values put together, and in which their respective elements are concatenated together.

◆ chunk() [1/3]

template<simd_size_type _Np, vec_or_mask_type _S>
auto xvec::simd::chunk ( const _S & container)
constexprnoexcept

Chunk the vec_or_mask_type values into a tuple of smaller values, each of which has no more than N elements. The returned tuple will be a set of (size / N) full-sized vec or mask values, and one element with (size % N) vec or mask values. If there are no remainders then an array of equal-sized simd values will be returned.

Template Parameters
_NpThe size to split into
Parameters
containerThe vec or mask object to split
Returns
A tuple or array of vec or mask values of no more than _Np elements.

◆ chunk() [2/3]

template<mask_type _M, typename _Abi>
auto xvec::simd::chunk ( const basic_mask< simd_mask_element_size_v< _M >, _Abi > & m)
constexprnoexcept

Chunk the mask into smaller values determined by the target mask width.

Template Parameters
_MThe target mask type that determines the chunk size
_AbiThe ABI type of the input mask value
Parameters
mThe mask-like object to split
Returns
A tuple or array of mask-like values of no more than _M::size elements.

◆ chunk() [3/3]

template<typename _V, typename _Abi>
auto xvec::simd::chunk ( const basic_vec< typename _V::value_type, _Abi > & s)
constexprnoexcept

Chunk the vec into smaller values, each of which has no more than _V::size elements. An exact partition returns an array; a partition with a remainder returns a tuple.

Template Parameters
_VThe target vector type that determines the chunk size
_AbiThe ABI type of the input vec value
Parameters
sThe vec object to split
Returns
A tuple or array of vec values of no more than _V::size elements.

◆ vec_as_container()

template<vec_type _Vp>
auto xvec::simd::vec_as_container ( const _Vp & v)
constexpr

Generate a variable containing the iota sequence (i.e., 0, 1, 2, ... size-1) for the given simd::vec type. This can be used as the basis of generating other sequences, including those used in constexpr scenarios. For example, to generate all multiples of 3 you can do `iota<T> * 3'. Using the constexpr nature of iota, along with the constexpr operations and functions makes it natural to build simd::vec constants with particular properties. Perhaps even easier than using the generator constructor.

Template Parameters
_TpThe vec or arithmetic type for which to generate the iota sequence
Returns
A simd::vec or scalar value containing the iota sequence for the type */ template<typename _Tp> requires (vec_type<_Tp> || std::is_arithmetic_v<_Tp>) inline constexpr _Tp iota = []{ if constexpr (vec_type<_Tp>) return _Tp([](simd_size_type i) { return typename _Tp::value_type(i); }); else return _Tp{}; }();

namespace detail {

:TODO: Move into utilities. const auto perm_uninitResize = [](auto idx, auto isize) { return idx < isize ? idx : uninit_element; };

Provide a way to initialise the values in a vec_impl::vector from a generator. template<vec_type _Vp, typename _Gp> constexpr auto generate(_Gp generator) { if constexpr (complex_number<typename _Vp::value_type>) { using _Tp = typename _Vp::traits::element_type; 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([=]<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()>())); } }

template<simd_size_type _NewSize, vec_or_mask_type _Vp> constexpr resize_t<_NewSize, _Vp> fit_to_size(const _Vp& v) { if constexpr (_NewSize == _Vp::size()) return v; else return permute<_NewSize>(v, [](simd_size_type i) { return (i < _Vp::size()) ? i : zero_element; }); }

template<vec_type _Vp, contiguous_sized_range _Range, typename _Flags> constexpr void mandates_for_store(const _Vp&, const _Range&, _Flags f) { using _Tp = typename _Vp::value_type; using _Rp = std::ranges::range_value_t<_Range>;

static_assert(detail::contains_flag<detail::flag_convert>(f) || !detail::needs_explicit_conversion<_Tp, _Rp>, "Store or scatter conversion requires flag_convert"); }

template<vec_type _Vp, contiguous_sized_range _Range, typename _Flags> constexpr void mandates_for_load(const _Range&, const _Vp&, _Flags f) { using _Tp = typename _Vp::value_type; using _Rp = std::ranges::range_value_t<_Range>;

static_assert(detail::vectorizable<_Rp>); static_assert(detail::explicitly_convertible_to<_Rp, _Tp>); static_assert(std::same_as<std::remove_cvref_t<_Vp>, _Vp>);

flag_convert is required if and only if the equivalent simd converting constructor would be explicit. static_assert(detail::contains_flag<detail::flag_convert>(f) || !detail::needs_explicit_conversion<_Rp, _Tp>, "Load or gather conversion requires flag_convert"); }

/** Convert a vec_type into the appropriate container type. Each element is the same size as the original and the number of elements is the same. The return value is bitwise equivalent to the original, but with a new type. This function is useful for converting a simd of a specific element type into a generic simd container which can be manipulated as a bucket-of-bits. It can also be used to convert a mask into a suitable container, allowing generic permute-like operations to work on masks too.