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

Element-wise minimum, maximum, clamping, and selection. More...

Functions

template<vec_type _Vp>
requires std::totally_ordered<typename _Vp::value_type>
constexpr _Vp xvec::simd::min (const _Vp &lhs, const _Vp &rhs) noexcept
 Compute the smaller of each respective vec element from the two input arguments.
template<vec_type _Vp>
requires std::totally_ordered<typename _Vp::value_type>
constexpr _Vp xvec::simd::max (const _Vp &lhs, const _Vp &rhs) noexcept
 Compute the larger of each respective vec element from the two input arguments.
template<vec_totally_ordered _Vp>
requires std::totally_ordered<typename _Vp::value_type>
constexpr std::pair< _Vp, _Vp > xvec::simd::minmax (const _Vp &lhs, const _Vp &rhs) noexcept
 Compute a pair of vec values giving the smaller and larger respective of each corresponding vec element from the two input arguments.
template<vec_totally_ordered _Vp>
requires std::totally_ordered<typename _Vp::value_type>
constexpr _Vp xvec::simd::clamp (const _Vp &values, const _Vp &low, const _Vp &high)
 Clamp the input values to be contained within the range [low,high]. If a value is less than low it will return low. If a value is greater than high it will return high. Other values are unmodified.
template<mask_type _M, class _T, class _U>
constexpr auto xvec::simd::select (const _M &m, const _T &if_true, const _U &if_false) noexcept -> decltype(simd_select_impl(m, if_true, if_false))
 Select between corresponding elements according to a mask.
template<std::copyable _Tp, std::copyable _Up>
constexpr auto xvec::simd::select (bool c, const _Tp &a, const _Up &b) -> std::remove_cvref_t< decltype(c ? a :b)>
 Select between two values based on a boolean condition (scalar version).

Detailed Description

Element-wise minimum, maximum, clamping, and selection.

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

Function Documentation

◆ clamp()

template<vec_totally_ordered _Vp>
requires std::totally_ordered<typename _Vp::value_type>
_Vp xvec::simd::clamp ( const _Vp & values,
const _Vp & low,
const _Vp & high )
constexpr

Clamp the input values to be contained within the range [low,high]. If a value is less than low it will return low. If a value is greater than high it will return high. Other values are unmodified.

Template Parameters
_VpThe vec type.
Parameters
valuesThe values to clamp.
lowThe low value in the clamping range.
highThe high value in the clamping range.
Returns
A vec where each element is clamped to the range [low, high].

◆ max()

template<vec_type _Vp>
requires std::totally_ordered<typename _Vp::value_type>
_Vp xvec::simd::max ( const _Vp & lhs,
const _Vp & rhs )
constexprnoexcept

Compute the larger of each respective vec element from the two input arguments.

Template Parameters
_VpThe vec type
Parameters
lhsThe left-hand value to compare
rhsThe right-hand value to compare
Returns
A new vec where each element is the larger of the two respective elements from the input values.

◆ min()

template<vec_type _Vp>
requires std::totally_ordered<typename _Vp::value_type>
_Vp xvec::simd::min ( const _Vp & lhs,
const _Vp & rhs )
constexprnoexcept

Compute the smaller of each respective vec element from the two input arguments.

Template Parameters
_VpThe vec type
Parameters
lhsThe left-hand value to compare
rhsThe right-hand value to compare
Returns
A new vec where each element is the smaller of the two respective elements from the input values.

◆ minmax()

template<vec_totally_ordered _Vp>
requires std::totally_ordered<typename _Vp::value_type>
std::pair< _Vp, _Vp > xvec::simd::minmax ( const _Vp & lhs,
const _Vp & rhs )
constexprnoexcept

Compute a pair of vec values giving the smaller and larger respective of each corresponding vec element from the two input arguments.

Template Parameters
_VpThe vec type.
Parameters
lhsThe left-hand value to compare
rhsThe right-hand value to compare
Returns
A pair of vec values representing the results of the min and max functions applied to the inputs.

◆ select() [1/2]

template<std::copyable _Tp, std::copyable _Up>
auto xvec::simd::select ( bool c,
const _Tp & a,
const _Up & b )->std::remove_cvref_t< decltype(c?a:b)>
constexpr

Select between two values based on a boolean condition (scalar version).

Template Parameters
_TpThe type of the first value
_UpThe type of the second value
Parameters
cThe condition
aThe value to use if c is true
bThe value to use if c is false
Returns
a if c is true, otherwise b

◆ select() [2/2]

template<mask_type _M, class _T, class _U>
auto xvec::simd::select ( const _M & m,
const _T & if_true,
const _U & if_false )->decltype(simd_select_impl(m, if_true, if_false))
constexprnoexcept

Select between corresponding elements according to a mask.

Template Parameters
_MThe mask type
_TThe type of the first value
_UThe type of the second value
Parameters
mThe mask indicating which elements to select
if_trueThe value to use if the mask element is true
if_falseThe value to use if the mask element is false
Returns
A value where each element is selected from if_true or if_false according to the mask.