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

Element-wise bit counting, rotation, power-of-two, and byte-order operations. More...

Functions

template<vec_unsigned_integer _Up, vec_integral _Sp>
requires (_Up::size() == _Sp::size() && sizeof(typename _Up::value_type) == sizeof(typename _Sp::value_type))
constexpr _Up xvec::simd::rotl (const _Up &u, const _Sp &s)
 Rotate each unsigned element left by its corresponding offset. Bits rotated off one end reappear at the other end. Negative offsets rotate in the opposite direction.
template<vec_unsigned_integer _Up, std::integral _Sp>
constexpr _Up xvec::simd::rotl (const _Up &u, _Sp s)
 Rotate every unsigned element left using a shared offset.
template<vec_unsigned_integer _Up, vec_integral _Sp>
requires (_Up::size() == _Sp::size() && sizeof(typename _Up::value_type) == sizeof(typename _Sp::value_type))
constexpr _Up xvec::simd::rotr (const _Up &u, const _Sp &s)
 Rotate each unsigned element right by its corresponding offset. Bits rotated off one end reappear at the other end. Negative offsets rotate in the opposite direction.
template<vec_unsigned_integer _Up, std::integral _Sp>
constexpr _Up xvec::simd::rotr (const _Up &u, _Sp s)
 Rotate every unsigned element right using a shared offset.
template<vec_unsigned_integer _Vp>
constexpr auto xvec::simd::countl_zero (const _Vp &v) noexcept
 Count consecutive zero bits from the most significant bit of each element.
template<vec_unsigned_integer _Vp>
constexpr auto xvec::simd::countl_one (const _Vp &x) noexcept
 Count consecutive one bits from the most significant bit of each element.
template<vec_unsigned_integer _Vp>
constexpr auto xvec::simd::countr_zero (const _Vp &v) noexcept
 Count consecutive zero bits from the least significant bit of each element.
template<vec_unsigned_integer _Vp>
constexpr auto xvec::simd::countr_one (const _Vp &x) noexcept
 Count consecutive one bits from the least significant bit of each element.
template<vec_unsigned_integer _Vp>
constexpr auto xvec::simd::popcount (const _Vp &x) noexcept
 Count the one bits in each element.
template<vec_unsigned_integer _Vp>
constexpr _Vp::mask_type xvec::simd::has_single_bit (const _Vp &x) noexcept
 Identify elements that are integral powers of two.
template<vec_unsigned_integer _Vp>
constexpr rebind_t< std::make_signed_t< typename _Vp::value_type >, _Vp > xvec::simd::bit_width (const _Vp &x) noexcept
 Compute the number of bits needed to represent each element.
template<vec_unsigned_integer _Vp>
constexpr _Vp xvec::simd::bit_ceil (const _Vp &x) noexcept
 Compute the smallest integral power of two not smaller than each element.
template<vec_unsigned_integer _Vp>
constexpr _Vp xvec::simd::bit_floor (const _Vp &v) noexcept
 Compute the largest integral power of two not greater than each element. Zero input elements produce zero output elements.
template<vec_integral _Vp>
constexpr _Vp xvec::simd::byteswap (const _Vp &v) noexcept
 Reverse the bytes within each integral element.

Detailed Description

Element-wise bit counting, rotation, power-of-two, and byte-order operations.

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

Function Documentation

◆ bit_ceil()

template<vec_unsigned_integer _Vp>
_Vp xvec::simd::bit_ceil ( const _Vp & x)
constexprnoexcept

Compute the smallest integral power of two not smaller than each element.

Template Parameters
_VpThe input vector type.
Parameters
xThe input vector.
Returns
An unsigned vector containing the element-wise bit ceilings.

◆ bit_floor()

template<vec_unsigned_integer _Vp>
_Vp xvec::simd::bit_floor ( const _Vp & v)
constexprnoexcept

Compute the largest integral power of two not greater than each element. Zero input elements produce zero output elements.

Template Parameters
_VpThe input vector type.
Parameters
vThe input vector.
Returns
An unsigned vector containing the element-wise bit floors.

◆ bit_width()

template<vec_unsigned_integer _Vp>
rebind_t< std::make_signed_t< typename _Vp::value_type >, _Vp > xvec::simd::bit_width ( const _Vp & x)
constexprnoexcept

Compute the number of bits needed to represent each element.

Template Parameters
_VpThe input vector type.
Parameters
xThe input vector.
Returns
A signed integral vector containing the bit widths.

◆ byteswap()

template<vec_integral _Vp>
_Vp xvec::simd::byteswap ( const _Vp & v)
constexprnoexcept

Reverse the bytes within each integral element.

Template Parameters
_VpThe input vector type.
Parameters
vThe input vector.
Returns
A vector containing the byte-reversed elements.

◆ countl_one()

template<vec_unsigned_integer _Vp>
auto xvec::simd::countl_one ( const _Vp & x)
constexprnoexcept

Count consecutive one bits from the most significant bit of each element.

Template Parameters
_VpThe input vector type.
Parameters
xThe input vector.
Returns
A signed integral vector containing the counts.

◆ countl_zero()

template<vec_unsigned_integer _Vp>
auto xvec::simd::countl_zero ( const _Vp & v)
constexprnoexcept

Count consecutive zero bits from the most significant bit of each element.

Template Parameters
_VpThe input vector type.
Parameters
vThe input vector.
Returns
A signed integral vector containing the counts.

◆ countr_one()

template<vec_unsigned_integer _Vp>
auto xvec::simd::countr_one ( const _Vp & x)
constexprnoexcept

Count consecutive one bits from the least significant bit of each element.

Template Parameters
_VpThe input vector type.
Parameters
xThe input vector.
Returns
A signed integral vector containing the counts.

◆ countr_zero()

template<vec_unsigned_integer _Vp>
auto xvec::simd::countr_zero ( const _Vp & v)
constexprnoexcept

Count consecutive zero bits from the least significant bit of each element.

Template Parameters
_VpThe input vector type.
Parameters
vThe input vector.
Returns
A signed integral vector containing the counts.

◆ has_single_bit()

template<vec_unsigned_integer _Vp>
_Vp::mask_type xvec::simd::has_single_bit ( const _Vp & x)
constexprnoexcept

Identify elements that are integral powers of two.

Template Parameters
_VpThe input vector type.
Parameters
xThe input vector.
Returns
A mask that is true where the corresponding element contains exactly one set bit.

◆ popcount()

template<vec_unsigned_integer _Vp>
auto xvec::simd::popcount ( const _Vp & x)
constexprnoexcept

Count the one bits in each element.

Template Parameters
_VpThe input vector type.
Parameters
xThe input vector.
Returns
A signed integral vector containing the population counts.

◆ rotl() [1/2]

template<vec_unsigned_integer _Up, std::integral _Sp>
_Up xvec::simd::rotl ( const _Up & u,
_Sp s )
constexpr

Rotate every unsigned element left using a shared offset.

Parameters
uThe input vector.
sThe shared rotation offset.
Returns
A vector containing the rotated elements.

◆ rotl() [2/2]

template<vec_unsigned_integer _Up, vec_integral _Sp>
requires (_Up::size() == _Sp::size() && sizeof(typename _Up::value_type) == sizeof(typename _Sp::value_type))
_Up xvec::simd::rotl ( const _Up & u,
const _Sp & s )
constexpr

Rotate each unsigned element left by its corresponding offset. Bits rotated off one end reappear at the other end. Negative offsets rotate in the opposite direction.

Template Parameters
_UpThe unsigned vector type.
_SpThe integral offset vector type.
Parameters
uThe input vector.
sThe element-wise rotation offsets.
Returns
A vector containing the rotated elements.

◆ rotr() [1/2]

template<vec_unsigned_integer _Up, std::integral _Sp>
_Up xvec::simd::rotr ( const _Up & u,
_Sp s )
constexpr

Rotate every unsigned element right using a shared offset.

Parameters
uThe input vector.
sThe shared rotation offset.
Returns
A vector containing the rotated elements.

◆ rotr() [2/2]

template<vec_unsigned_integer _Up, vec_integral _Sp>
requires (_Up::size() == _Sp::size() && sizeof(typename _Up::value_type) == sizeof(typename _Sp::value_type))
_Up xvec::simd::rotr ( const _Up & u,
const _Sp & s )
constexpr

Rotate each unsigned element right by its corresponding offset. Bits rotated off one end reappear at the other end. Negative offsets rotate in the opposite direction.

Template Parameters
_UpThe unsigned vector type.
_SpThe integral offset vector type.
Parameters
uThe input vector.
sThe element-wise rotation offsets.
Returns
A vector containing the rotated elements.