Intel xvec
Experimental C++ simd class library
Loading...
Searching...
No Matches
C++26: Permutations

Permute vector and mask elements using generated indexes, index vectors, selection masks, or indexed memory accesses. More...

Functions

template<simd_size_type _NewSize = 0, vec_type _Vp>
constexpr auto xvec::simd::permute (const _Vp &v, detail::index_generator_function auto &&fn)
 Permute the elements in a vec value using a generator function to compute the indexing.
template<simd_size_type _NewSize = 0, mask_type _Mask>
constexpr auto xvec::simd::permute (const _Mask &mask, detail::index_generator_function auto &&fn)
 Permute mask elements using a generator function to compute the indexing.
template<vec_or_mask_type _V, vec_integral _I>
constexpr resize_t< _I::size, _V > xvec::simd::permute (const _V &v, const _I &indexes)
 Permute a vec or mask value by the unsigned integral indexes supplied in another basic_vec value.
template<vec_type _V>
constexpr _V xvec::simd::compress (const _V &v, const typename _V::mask_type &selector)
 Compress a basic_vec or basic_mask value by a mask. The elements corresponding to any set mask bits will be packed contiguously into the output. Excess elements will be zeroed. The output basic_vec will have elements of the same type as the input basic_vec, and the same number of elements as the input mask.
template<vec_type _V>
constexpr _V xvec::simd::compress (const _V &v, const typename _V::mask_type &selector, const typename _V::value_type &fill_value)
 Compress selected vector elements and fill the remaining positions.
template<mask_type _M>
constexpr _M xvec::simd::compress (const _M &v, const std::type_identity_t< _M > &selector)
 Compress one mask using another mask.
template<mask_type _M>
constexpr _M xvec::simd::compress (const _M &v, const std::type_identity_t< _M > &selector, bool fill_value)
 Compress one mask using another mask, filling the remaining positions.
template<vec_type _V>
constexpr _V xvec::simd::expand (const _V &v, const typename _V::mask_type &selector, const _V &original={})
 Expand consecutive input elements into positions selected by a mask.
template<mask_type _M>
constexpr _M xvec::simd::expand (const _M &v, const std::type_identity_t< _M > &selector, const _M &original={})
 Expand consecutive mask elements into selected output positions.
template<typename _Vp = std::nullptr_t, detail::contiguous_sized_range _Range, vec_integral _Indexes, typename... _Flags>
requires detail::gather_from_requires<_Vp, _Range, _Indexes>
constexpr auto xvec::simd::partial_gather_from (_Range &&r, const _Indexes &indexes, flags< _Flags... > f={})
 Gather the contents of a contiguous range using the integral indexes supplied in another vec value.
template<typename _Vp = std::nullptr_t, detail::contiguous_sized_range _Range, vec_integral _Indexes, typename... _Flags>
requires detail::gather_from_requires<_Vp, _Range, _Indexes>
constexpr auto xvec::simd::unchecked_gather_from (_Range &&r, const _Indexes &indexes, flags< _Flags... > f={})
 Unchecked variant of gather.
template<typename _Vp = std::nullptr_t, detail::contiguous_sized_range _Range, vec_integral _Indexes, typename... _Flags>
requires detail::gather_from_requires<_Vp, _Range, _Indexes>
constexpr auto xvec::simd::partial_gather_from (_Range &&r, const typename _Indexes::mask_type &mask, const _Indexes &indexes, flags< _Flags... > f={})
 Gather selected elements from a contiguous range.
template<typename _Vp = std::nullptr_t, detail::contiguous_sized_range _Range, vec_integral _Indexes, typename... _Flags>
requires detail::gather_from_requires<_Vp, _Range, _Indexes>
constexpr auto xvec::simd::unchecked_gather_from (_Range &&r, const typename _Indexes::mask_type &mask, const _Indexes &indexes, flags< _Flags... > f={})
 Unchecked variant of masked gather_from.
template<detail::contiguous_sized_range _Range, vec_type _Vp, vec_integral _Indexes, typename... _Flags>
requires detail::scatter_to_requires<_Vp, _Range, _Indexes>
constexpr void xvec::simd::partial_scatter_to (const _Vp &values, _Range &&r, const _Indexes &indexes, flags< _Flags... > f={})
 Scatter the contents of a basic_vec into memory at the integral index positions supplied in another basic_vec value.
template<detail::contiguous_sized_range _Range, vec_type _Vp, vec_integral _Indexes, typename... _Flags>
requires detail::scatter_to_requires<_Vp, _Range, _Indexes>
constexpr void xvec::simd::partial_scatter_to (const _Vp &values, _Range &&r, const typename _Indexes::mask_type &mask, const _Indexes &indexes, flags< _Flags... > f={})
 Scatter selected vector elements into a contiguous range.
template<detail::contiguous_sized_range _Range, vec_type _Vp, vec_integral _Indexes, typename... _Flags>
requires detail::scatter_to_requires<_Vp, _Range, _Indexes>
constexpr void xvec::simd::unchecked_scatter_to (const _Vp &values, _Range &&r, const _Indexes &indexes, flags< _Flags... > f={})
 Unchecked variant of scatter.
template<detail::contiguous_sized_range _Range, vec_type _Vp, vec_integral _Indexes, typename... _Flags>
requires detail::scatter_to_requires<_Vp, _Range, _Indexes>
constexpr void xvec::simd::unchecked_scatter_to (const _Vp &values, _Range &&r, const typename _Indexes::mask_type &mask, const _Indexes &indexes, flags< _Flags... > f={})
 Unchecked variant of masked scatter.

Detailed Description

Permute vector and mask elements using generated indexes, index vectors, selection masks, or indexed memory accesses.

Includes compression, expansion, gather, and scatter operations.

See also
https://eel.is/c++draft/simd.permute

Function Documentation

◆ compress() [1/2]

template<vec_type _V>
_V xvec::simd::compress ( const _V & v,
const typename _V::mask_type & selector )
constexpr

Compress a basic_vec or basic_mask value by a mask. The elements corresponding to any set mask bits will be packed contiguously into the output. Excess elements will be zeroed. The output basic_vec will have elements of the same type as the input basic_vec, and the same number of elements as the input mask.

Template Parameters
_VThe vec type
Parameters
vThe values to permute
selectorThe mask by which to permute.
Returns
The active elements of the basic_vec or basic_mask selected by the mask and packed contiguously into the output.

◆ compress() [2/2]

template<vec_type _V>
_V xvec::simd::compress ( const _V & v,
const typename _V::mask_type & selector,
const typename _V::value_type & fill_value )
constexpr

Compress selected vector elements and fill the remaining positions.

Parameters
vThe input vector.
selectorThe mask selecting elements.
fill_valueThe value used after the packed elements.
Returns
The compressed vector with the specified padding.

◆ expand() [1/2]

template<mask_type _M>
_M xvec::simd::expand ( const _M & v,
const std::type_identity_t< _M > & selector,
const _M & original = {} )
constexpr

Expand consecutive mask elements into selected output positions.

Parameters
vThe mask supplying consecutive input elements.
selectorThe mask selecting output positions.
originalThe values retained at unselected positions.

◆ expand() [2/2]

template<vec_type _V>
_V xvec::simd::expand ( const _V & v,
const typename _V::mask_type & selector,
const _V & original = {} )
constexpr

Expand consecutive input elements into positions selected by a mask.

Template Parameters
_VThe vec type.
Parameters
vThe vector supplying consecutive input elements.
selectorThe mask selecting output positions.
originalThe values retained at positions where the selector is false.
Returns
A vector containing expanded elements and retained original values.

◆ partial_gather_from() [1/2]

template<typename _Vp = std::nullptr_t, detail::contiguous_sized_range _Range, vec_integral _Indexes, typename... _Flags>
requires detail::gather_from_requires<_Vp, _Range, _Indexes>
auto xvec::simd::partial_gather_from ( _Range && r,
const _Indexes & indexes,
flags< _Flags... > f = {} )
constexpr

Gather the contents of a contiguous range using the integral indexes supplied in another vec value.

Template Parameters
_VpA deduced type which the caller can override to specify the return type. This allows type conversions.
_RangeThe range type from which to read.
_IndexesThe type of the vec indexes used in the gather.
_FlagsFlag types controlling the memory access.
Parameters
rThe source range.
indexesThe indexes from which to gather.
fFlags controlling the memory operation.
Returns
A new vec value formed by reading the range at the supplied indexes.

◆ partial_gather_from() [2/2]

template<typename _Vp = std::nullptr_t, detail::contiguous_sized_range _Range, vec_integral _Indexes, typename... _Flags>
requires detail::gather_from_requires<_Vp, _Range, _Indexes>
auto xvec::simd::partial_gather_from ( _Range && r,
const typename _Indexes::mask_type & mask,
const _Indexes & indexes,
flags< _Flags... > f = {} )
constexpr

Gather selected elements from a contiguous range.

Parameters
rThe source range.
maskThe mask enabling index-vector elements.
indexesThe indexes from which to gather.
fFlags controlling the memory operation.

◆ partial_scatter_to() [1/2]

template<detail::contiguous_sized_range _Range, vec_type _Vp, vec_integral _Indexes, typename... _Flags>
requires detail::scatter_to_requires<_Vp, _Range, _Indexes>
void xvec::simd::partial_scatter_to ( const _Vp & values,
_Range && r,
const _Indexes & indexes,
flags< _Flags... > f = {} )
constexpr

Scatter the contents of a basic_vec into memory at the integral index positions supplied in another basic_vec value.

Template Parameters
_VpThe type of the values to scatter to memory.
_IndexesThe type of the indexes used in the scatter.
_RangeThe range type to which to write.
Parameters
valuesThe values to scatter to memory.
rA contiguous range into which to scatter.
indexesThe indexes to which to scatter.
fFlags controlling the memory operation.

◆ partial_scatter_to() [2/2]

template<detail::contiguous_sized_range _Range, vec_type _Vp, vec_integral _Indexes, typename... _Flags>
requires detail::scatter_to_requires<_Vp, _Range, _Indexes>
void xvec::simd::partial_scatter_to ( const _Vp & values,
_Range && r,
const typename _Indexes::mask_type & mask,
const _Indexes & indexes,
flags< _Flags... > f = {} )
constexpr

Scatter selected vector elements into a contiguous range.

Parameters
valuesThe values to scatter.
rThe destination range.
maskThe mask enabling index-vector elements.
indexesThe indexes to which to scatter.
fFlags controlling the memory operation.

◆ permute() [1/3]

template<simd_size_type _NewSize = 0, mask_type _Mask>
auto xvec::simd::permute ( const _Mask & mask,
detail::index_generator_function auto && fn )
constexpr

Permute mask elements using a generator function to compute the indexing.

Template Parameters
_NewSizeThe number of output elements, or zero to retain the input width.
_MaskThe input mask type.
Parameters
maskThe mask to permute.
fnThe index generator function.
Returns
The permuted mask.

◆ permute() [2/3]

template<vec_or_mask_type _V, vec_integral _I>
resize_t< _I::size, _V > xvec::simd::permute ( const _V & v,
const _I & indexes )
constexpr

Permute a vec or mask value by the unsigned integral indexes supplied in another basic_vec value.

Template Parameters
_VThe type of the basic_vec or basic_mask value to permute
_IThe type of the index basic_vec value containing unsigned integral values
Parameters
vThe basic_vec or basic_mask value to permute
indexesThe indexes by which to permute
Returns
The contents of v permuted by the indexes. The output of each element position is v[idx[iota()]].

◆ permute() [3/3]

template<simd_size_type _NewSize = 0, vec_type _Vp>
auto xvec::simd::permute ( const _Vp & v,
detail::index_generator_function auto && fn )
constexpr

Permute the elements in a vec value using a generator function to compute the indexing.

Template Parameters
_NewSizeThe number of elements required in the permuted output basic_vec.
_VpThe type of the basic_vec value to permute
Parameters
vThe value to permute
fnThe index generator function. Given an index position in the output basic_vec this function should return the index of the element to use from the input value. The function may accept an optional parameter giving the size of v.
Returns
A new basic_vec value where every element takes as its input the element generated by the index functon.