11#include <xvec/detail/config.hpp>
18namespace _XVEC_NAMESPACE::simd
37template<vec_
unsigned_
integer _Up, vec_
integral _Sp>
38 requires (_Up::size() == _Sp::size() &&
39 sizeof(
typename _Up::value_type) ==
sizeof(
typename _Sp::value_type))
40constexpr _Up
rotl(
const _Up& u,
const _Sp& s)
42 if (std::is_constant_evaluated())
43 return _Up([=](
auto i) {
return typename _Up::value_type(std::rotl(u[i], s[i])); });
45 return detail::rotate_left(target, u, s);
52template<vec_
unsigned_
integer _Up, std::
integral _Sp>
53constexpr _Up
rotl(
const _Up& u, _Sp s) {
54 using _Rp = std::make_signed_t<typename _Up::value_type>;
55 return rotl(u, rebind_t<_Rp, _Up>(_Rp(s))); }
65template<vec_
unsigned_
integer _Up, vec_
integral _Sp>
66 requires (_Up::size() == _Sp::size() &&
67 sizeof(
typename _Up::value_type) ==
sizeof(
typename _Sp::value_type))
68constexpr _Up
rotr(
const _Up& u,
const _Sp& s)
70 if (std::is_constant_evaluated())
71 return _Up([=](
auto i) {
return typename _Up::value_type(std::rotr(u[i], s[i])); });
73 return detail::rotate_right(target, u, s);
80template<vec_
unsigned_
integer _Up, std::
integral _Sp>
81constexpr _Up
rotr(
const _Up& u, _Sp s) {
82 using _Rp = std::make_signed_t<typename _Up::value_type>;
83 return rotr(u, rebind_t<_Rp, _Up>(_Rp(s))); }
89template<vec_
unsigned_
integer _Vp>
91 using _Rp = std::make_signed_t<typename _Vp::value_type>;
92 if (std::is_constant_evaluated())
93 return rebind_t<_Rp, _Vp>([=](
auto i){
return _Rp(std::countl_zero(v[i])); });
108template<vec_
unsigned_
integer _Vp>
110 using _Rp = std::make_signed_t<typename _Vp::value_type>;
111 if (std::is_constant_evaluated())
112 return rebind_t<_Rp, _Vp>([&](
auto i){
return _Rp(std::countr_zero(v[i])); });
117 auto lsbBits = ~v & (v - detail::cw<1>);
132template<vec_
unsigned_
integer _Vp>
134 using _Rp = std::make_signed_t<typename _Vp::value_type>;
135 if (std::is_constant_evaluated())
136 return rebind_t<_Rp, _Vp>([=](
auto i) {
return _Rp(std::popcount(x[i])); });
145template<vec_
unsigned_
integer _Vp>
154template<vec_
unsigned_
integer _Vp>
155constexpr rebind_t<std::make_signed_t<typename _Vp::value_type>, _Vp>
157 using _R = rebind_t<std::make_signed_t<typename _Vp::value_type>, _Vp>;
158 return _R(detail::cw<std::numeric_limits<typename _Vp::value_type>::digits> -
countl_zero(x));
165template<vec_
unsigned_
integer _Vp>
167 if (std::is_constant_evaluated())
168 return _Vp([=](
auto i) {
return std::bit_ceil(x[i]); });
174 constexpr auto one = _Vp(std::uint8_t(1));
175 auto shift_amount = _Vp(
bit_width(x - one));
176 return select(x < std::uint8_t(2), one, one << shift_amount);
185template<vec_
unsigned_
integer _Vp>
187 using _Tp =
typename _Vp::value_type;
188 if (std::is_constant_evaluated())
189 return _Vp([=](
auto i) {
return std::bit_floor(v[i]); });
193 return select(v != _Vp(), std::uint8_t(1) << log2, _Vp());
213template<vec_
unsigned_
integer _Vp>
215 if (std::is_constant_evaluated())
225template<vec_
integral _Vp>
227 if (std::is_constant_evaluated())
230 auto bswap = [](
auto b) {
231 auto value_representation = std::bit_cast<std::array<std::byte,
sizeof(b)>>(b);
232 std::ranges::reverse(value_representation);
233 return std::bit_cast<decltype(b)>(value_representation);
235 return _Vp([=](
auto i) {
return bswap(v[i]); });
238 return detail::byteswap(target, v);
263template<vec_
unsigned_
integer _Up, vec_
integral _Sp>
264 requires (
sizeof(
typename _Up::value_type) ==
sizeof(
typename _Sp::value_type))
267 if (std::is_constant_evaluated())
270 return detail::fsr(target, high, low, s);
279template<vec_
unsigned_
integer _Up, std::
integral _Sp>
293template<vec_
unsigned_
integer _Up, vec_
integral _Sp>
294 requires (
sizeof(
typename _Up::value_type) ==
sizeof(
typename _Sp::value_type))
297 if (std::is_constant_evaluated())
300 return detail::fsl(target, high, low, s);
309template<vec_
unsigned_
integer _Up, std::
integral _Sp>
317namespace _XVEC_NAMESPACE
319 using simd::byteswap;
320 using simd::bit_floor;
321 using simd::bit_ceil;
322 using simd::has_single_bit;
325 using simd::bit_width;
326 using simd::countl_zero;
327 using simd::countl_one;
328 using simd::countr_zero;
329 using simd::countr_one;
330 using simd::popcount;
331 using simd::funnel_shift_left;
332 using simd::funnel_shift_right;
constexpr auto 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.
Definition std_algorithm.hpp:88
constexpr rebind_t< std::make_signed_t< typename _Vp::value_type >, _Vp > bit_width(const _Vp &x) noexcept
Compute the number of bits needed to represent each element.
Definition std_bit.hpp:156
constexpr auto countl_zero(const _Vp &v) noexcept
Count consecutive zero bits from the most significant bit of each element.
Definition std_bit.hpp:90
constexpr auto countr_one(const _Vp &x) noexcept
Count consecutive one bits from the least significant bit of each element.
Definition std_bit.hpp:126
constexpr _Vp bit_floor(const _Vp &v) noexcept
Compute the largest integral power of two not greater than each element. Zero input elements produce ...
Definition std_bit.hpp:186
constexpr auto countl_one(const _Vp &x) noexcept
Count consecutive one bits from the most significant bit of each element.
Definition std_bit.hpp:102
constexpr auto popcount(const _Vp &x) noexcept
Count the one bits in each element.
Definition std_bit.hpp:133
constexpr _Up rotr(const _Up &u, const _Sp &s)
Rotate each unsigned element right by its corresponding offset. Bits rotated off one end reappear at ...
Definition std_bit.hpp:68
constexpr auto countr_zero(const _Vp &v) noexcept
Count consecutive zero bits from the least significant bit of each element.
Definition std_bit.hpp:109
constexpr _Vp::mask_type has_single_bit(const _Vp &x) noexcept
Identify elements that are integral powers of two.
Definition std_bit.hpp:146
constexpr _Vp bit_ceil(const _Vp &x) noexcept
Compute the smallest integral power of two not smaller than each element.
Definition std_bit.hpp:166
constexpr _Vp byteswap(const _Vp &v) noexcept
Reverse the bytes within each integral element.
Definition std_bit.hpp:226
constexpr _Up rotl(const _Up &u, const _Sp &s)
Rotate each unsigned element left by its corresponding offset. Bits rotated off one end reappear at t...
Definition std_bit.hpp:40
constexpr _Vp bit_reverse(const _Vp &x) noexcept
Reverse the bits within each element.
Definition std_bit.hpp:214
constexpr detail::RebindCast< _Up > rebind_cast
Rebinding CPO.
Definition std_rebind.hpp:55
constexpr _Up funnel_shift_left(const _Up &high, const _Up &low, const _Sp &s)
Funnel shift corresponding element pairs left. Conceptually concatenate each high element with its co...
Definition std_bit.hpp:295
constexpr _Up funnel_shift_right(const _Up &high, const _Up &low, const _Sp &s)
Funnel shift corresponding element pairs right. Conceptually concatenate each high element with its c...
Definition std_bit.hpp:265
constexpr basic_vec< _Tp, _Abi > popcount(x86_sse_tag, const basic_vec< _Tp, _Abi > &x) noexcept
}@
Definition x86_impl.hpp:1232
constexpr T funnel_shift_right(T high, T low, S s) noexcept
Definition compat.hpp:203
constexpr basic_vec< _Tp, _Abi > clz(x86_sse_tag, const basic_vec< _Tp, _Abi > &x) noexcept
Count the number of leading zero bits in each element.
Definition x86_impl.hpp:1303
constexpr auto has_single_bit(x86_avxsnc_tag, const basic_vec< _Tp, _Abi > &x) noexcept
Query whether each element has exactly one bit set.
Definition x86_impl.hpp:1294
constexpr T funnel_shift_left(T high, T low, S s) noexcept
Definition compat.hpp:217
constexpr basic_vec< _Tp, _Abi > bitreverse(x86_sse_tag, const basic_vec< _Tp, _Abi > &x) noexcept
Count the number of leading zero bits in each element.
Definition x86_impl.hpp:1413
Definition target_config.hpp:23