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

Reduce vectors to scalar values, with masked and scalar-generic overloads. More...

Functions

template<vec_type _V, detail::binary_reduction_fn< typename _V::value_type > _BinaryFn = std::plus<>>
constexpr _V::value_type xvec::simd::reduce (const _V &v, _BinaryFn binop={})
 Apply a reduction operation across all elements of the basic_vec value to reduce them to a single scalar value.
template<typename _Tp, typename _Abi, detail::binary_reduction_fn< _Tp > _BinaryFn = std::plus<>>
constexpr _Tp xvec::simd::reduce (const basic_vec< _Tp, _Abi > &v, const typename basic_vec< _Tp, _Abi >::mask_type &m, _BinaryFn binop={}, std::type_identity_t< _Tp > identity_element=detail::choose_identity_element< _BinaryFn, _Tp >())
 Apply a reduction operation across all elements of the basic_vec value, using a mask and identity element.
template<detail::vectorizable _Tp, detail::binary_reduction_fn< _Tp > _BinaryFn = std::plus<>>
constexpr _Tp xvec::simd::reduce (const _Tp &v, _BinaryFn binop={}) noexcept
 Apply a reduction operation to a scalar value.
template<detail::vectorizable _Tp, detail::binary_reduction_fn< _Tp > _BinaryFn = std::plus<>>
constexpr _Tp xvec::simd::reduce (const _Tp &v, std::same_as< bool > auto m, _BinaryFn binop={}, std::type_identity_t< _Tp > identity_element=detail::choose_identity_element< _BinaryFn, _Tp >()) noexcept
 Apply a reduction operation to a conditionally selected scalar value.
template<vec_type _V>
requires requires (_V x) { min(x, x); }
constexpr _V::value_type xvec::simd::reduce_min (const _V &v) noexcept
 Return the minimum vector element.
template<vec_type _V>
requires requires (_V x) { reduce_min(x); }
constexpr _V::value_type xvec::simd::reduce_min (const _V &v, const typename _V::mask_type &m) noexcept
 Compute the minimum reduction over selected vector elements.
template<vec_type _V>
requires requires (_V x) { max(x, x); }
constexpr _V::value_type xvec::simd::reduce_max (const _V &v) noexcept
 Return the maximum vector element.
template<vec_type _V>
requires requires (_V x) { reduce_max(x); }
constexpr _V::value_type xvec::simd::reduce_max (const _V &v, const typename _V::mask_type &m) noexcept
 Compute the maximum reduction over selected vector elements.
template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
constexpr _Tp xvec::simd::reduce_min (const _Tp &v) noexcept
 Return the minimum of a scalar value.
template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
constexpr _Tp xvec::simd::reduce_min (const _Tp &v, std::same_as< bool > auto m) noexcept
 Return the minimum of a conditionally selected scalar value.
template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
constexpr _Tp xvec::simd::reduce_max (const _Tp &v) noexcept
 Return the maximum of a scalar value.
template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
constexpr _Tp xvec::simd::reduce_max (const _Tp &v, std::same_as< bool > auto m) noexcept
 Return the maximum of a conditionally selected scalar value.

Detailed Description

Reduce vectors to scalar values, with masked and scalar-generic overloads.

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

Function Documentation

◆ reduce() [1/4]

template<detail::vectorizable _Tp, detail::binary_reduction_fn< _Tp > _BinaryFn = std::plus<>>
_Tp xvec::simd::reduce ( const _Tp & v,
_BinaryFn binop = {} )
constexprnoexcept

Apply a reduction operation to a scalar value.

Template Parameters
_TpThe scalar value type.
_BinaryFnThe type of function to apply.
Parameters
vThe scalar value to reduce.
binopThe binary operation for the reduction.
Returns
The input value.

◆ reduce() [2/4]

template<detail::vectorizable _Tp, detail::binary_reduction_fn< _Tp > _BinaryFn = std::plus<>>
_Tp xvec::simd::reduce ( const _Tp & v,
std::same_as< bool > auto m,
_BinaryFn binop = {},
std::type_identity_t< _Tp > identity_element = detail::choose_identity_element<_BinaryFn, _Tp>() )
constexprnoexcept

Apply a reduction operation to a conditionally selected scalar value.

Template Parameters
_TpThe scalar value type.
_BinaryFnThe type of function to apply.
Parameters
vThe scalar value to reduce.
mWhether the scalar value is selected.
binopThe binary operation for the reduction.
identity_elementThe identity value for the reduction operation.
Returns
The input value when selected; otherwise, the identity element.

◆ reduce() [3/4]

template<vec_type _V, detail::binary_reduction_fn< typename _V::value_type > _BinaryFn = std::plus<>>
_V::value_type xvec::simd::reduce ( const _V & v,
_BinaryFn binop = {} )
constexpr

Apply a reduction operation across all elements of the basic_vec value to reduce them to a single scalar value.

Template Parameters
_VThe vector type to reduce
_BinaryFnThe type of function to apply
Parameters
vThe basic_vec value to reduce into a single element
binopThe binary operation to use to generate the reduction (defaults to std::plus)
Returns
A scalar value resulting from repeatedly applying the binary operation to all values in the basic_vec in some arbitrary order.

◆ reduce() [4/4]

template<typename _Tp, typename _Abi, detail::binary_reduction_fn< _Tp > _BinaryFn = std::plus<>>
_Tp xvec::simd::reduce ( const basic_vec< _Tp, _Abi > & v,
const typename basic_vec< _Tp, _Abi >::mask_type & m,
_BinaryFn binop = {},
std::type_identity_t< _Tp > identity_element = detail::choose_identity_element<_BinaryFn, _Tp>() )
constexpr

Apply a reduction operation across all elements of the basic_vec value, using a mask and identity element.

Template Parameters
_TpThe element type of the basic_vec to reduce
_AbiThe ABI of the basic_vec to reduce
_BinaryFnThe type of function to apply
Parameters
vThe basic_vec value to reduce
mThe mask indicating which elements to include in the reduction
binopThe binary operation to use to generate the reduction (defaults to std::plus)
identity_elementThe identity value for the reduction operation
Returns
A scalar value resulting from repeatedly applying the binary operation to all selected values in the basic_vec

◆ reduce_max() [1/4]

template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
_Tp xvec::simd::reduce_max ( const _Tp & v)
constexprnoexcept

Return the maximum of a scalar value.

Template Parameters
_TpThe scalar value type.
Parameters
vThe scalar value.
Returns
The input value.

◆ reduce_max() [2/4]

template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
_Tp xvec::simd::reduce_max ( const _Tp & v,
std::same_as< bool > auto m )
constexprnoexcept

Return the maximum of a conditionally selected scalar value.

Template Parameters
_TpThe scalar value type.
Parameters
vThe scalar value.
mWhether the scalar value is selected.
Returns
The input value when selected; otherwise, the lowest value of _Tp.

◆ reduce_max() [3/4]

template<vec_type _V>
requires requires (_V x) { max(x, x); }
_V::value_type xvec::simd::reduce_max ( const _V & v)
constexprnoexcept

Return the maximum vector element.

Parameters
vThe vector to reduce.
Returns
The maximum value.

◆ reduce_max() [4/4]

template<vec_type _V>
requires requires (_V x) { reduce_max(x); }
_V::value_type xvec::simd::reduce_max ( const _V & v,
const typename _V::mask_type & m )
constexprnoexcept

Compute the maximum reduction over selected vector elements.

Parameters
vThe vector to reduce.
mThe mask selecting elements.

◆ reduce_min() [1/4]

template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
_Tp xvec::simd::reduce_min ( const _Tp & v)
constexprnoexcept

Return the minimum of a scalar value.

Template Parameters
_TpThe scalar value type.
Parameters
vThe scalar value.
Returns
The input value.

◆ reduce_min() [2/4]

template<detail::vectorizable _Tp>
requires std::totally_ordered<_Tp>
_Tp xvec::simd::reduce_min ( const _Tp & v,
std::same_as< bool > auto m )
constexprnoexcept

Return the minimum of a conditionally selected scalar value.

Template Parameters
_TpThe scalar value type.
Parameters
vThe scalar value.
mWhether the scalar value is selected.
Returns
The input value when selected; otherwise, the maximum value of _Tp.

◆ reduce_min() [3/4]

template<vec_type _V>
requires requires (_V x) { min(x, x); }
_V::value_type xvec::simd::reduce_min ( const _V & v)
constexprnoexcept

Return the minimum vector element.

Template Parameters
_VThe vector type.
Parameters
vThe vector to reduce.
Returns
The minimum value.

◆ reduce_min() [4/4]

template<vec_type _V>
requires requires (_V x) { reduce_min(x); }
_V::value_type xvec::simd::reduce_min ( const _V & v,
const typename _V::mask_type & m )
constexprnoexcept

Compute the minimum reduction over selected vector elements.

Parameters
vThe vector to reduce.
mThe mask selecting elements.