25#ifndef _GLIBCXX_SIMD_BIT_H
26#define _GLIBCXX_SIMD_BIT_H 1
29#pragma GCC system_header
32#if __cplusplus >= 202400L
37#pragma GCC diagnostic push
38#pragma GCC diagnostic ignored "-Wpsabi"
41namespace std _GLIBCXX_VISIBILITY(default)
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
46 template<__simd_
integral _Vp>
47 [[__gnu__::__always_inline__]]
49 byteswap(
const _Vp& __v)
noexcept
51 if constexpr (
sizeof(
typename _Vp::value_type) == 1)
54 return _Vp([&](
int __i) {
return std::byteswap(__v[__i]); });
57 template<__simd_
unsigned_
integer _Vp>
58 [[__gnu__::__always_inline__]]
60 bit_ceil(
const _Vp& __v)
62 using _Tp =
typename _Vp::value_type;
63 constexpr _Tp __max = _Tp(1) << (
sizeof(_Tp) * __CHAR_BIT__ - 1);
64 __glibcxx_simd_precondition(all_of(__v <= __max),
"bit_ceil result is not representable");
65 return _Vp([&](
int __i) {
return std::bit_ceil(__v[__i]); });
68 template<__simd_
unsigned_
integer _Vp>
69 [[__gnu__::__always_inline__]]
71 bit_floor(
const _Vp& __v)
noexcept
72 {
return _Vp([&](
int __i) {
return std::bit_floor(__v[__i]); }); }
74 template<__simd_
unsigned_
integer _Vp>
75 [[__gnu__::__always_inline__]]
76 constexpr typename _Vp::mask_type
77 has_single_bit(
const _Vp& __v)
noexcept
78 {
return typename _Vp::mask_type([&](
int __i) {
return std::has_single_bit(__v[__i]); }); }
80 template<__simd_
unsigned_
integer _V0, __simd_
integral _V1>
81 requires (_V0::size() == _V1::size())
82 && (
sizeof(
typename _V0::value_type) ==
sizeof(
typename _V1::value_type))
83 [[__gnu__::__always_inline__]]
85 rotl(
const _V0& __v,
const _V1& __s)
noexcept
86 {
return _V0([&](
int __i) {
return std::rotl(__v[__i], __s[__i]); }); }
88 template<__simd_
unsigned_
integer _Vp>
89 [[__gnu__::__always_inline__]]
91 rotl(
const _Vp& __v,
int __s)
noexcept
92 {
return _Vp([&](
int __i) {
return std::rotl(__v[__i], __s); }); }
94 template<__simd_
unsigned_
integer _V0, __simd_
integral _V1>
95 requires (_V0::size() == _V1::size())
96 && (
sizeof(
typename _V0::value_type) ==
sizeof(
typename _V1::value_type))
97 [[__gnu__::__always_inline__]]
99 rotr(
const _V0& __v,
const _V1& __s)
noexcept
100 {
return _V0([&](
int __i) {
return std::rotr(__v[__i], __s[__i]); }); }
102 template<__simd_
unsigned_
integer _Vp>
103 [[__gnu__::__always_inline__]]
105 rotr(
const _Vp& __v,
int __s)
noexcept
106 {
return _Vp([&](
int __i) {
return std::rotr(__v[__i], __s); }); }
108 template<__simd_
unsigned_
integer _Vp>
109 [[__gnu__::__always_inline__]]
110 constexpr rebind_t<make_signed_t<typename _Vp::value_type>, _Vp>
111 bit_width(
const _Vp& __v)
noexcept
114 return rebind_t<_Ip, _Vp>([&](
int __i) {
115 return static_cast<_Ip
>(std::bit_width(__v[__i]));
119 template<__simd_
unsigned_
integer _Vp>
120 [[__gnu__::__always_inline__]]
121 constexpr rebind_t<make_signed_t<typename _Vp::value_type>, _Vp>
122 countl_zero(
const _Vp& __v)
noexcept
125 return rebind_t<_Ip, _Vp>([&](
int __i) {
126 return static_cast<_Ip
>(std::countl_zero(__v[__i]));
130 template<__simd_
unsigned_
integer _Vp>
131 [[__gnu__::__always_inline__]]
132 constexpr rebind_t<make_signed_t<typename _Vp::value_type>, _Vp>
133 countl_one(
const _Vp& __v)
noexcept
136 return rebind_t<_Ip, _Vp>([&](
int __i) {
137 return static_cast<_Ip
>(std::countl_one(__v[__i]));
141 template<__simd_
unsigned_
integer _Vp>
142 [[__gnu__::__always_inline__]]
143 constexpr rebind_t<make_signed_t<typename _Vp::value_type>, _Vp>
144 countr_zero(
const _Vp& __v)
noexcept
147 return rebind_t<_Ip, _Vp>([&](
int __i) {
148 return static_cast<_Ip
>(std::countr_zero(__v[__i]));
152 template<__simd_
unsigned_
integer _Vp>
153 [[__gnu__::__always_inline__]]
154 constexpr rebind_t<make_signed_t<typename _Vp::value_type>, _Vp>
155 countr_one(
const _Vp& __v)
noexcept
158 return rebind_t<_Ip, _Vp>([&](
int __i) {
159 return static_cast<_Ip
>(std::countr_one(__v[__i]));
163 template<__simd_
unsigned_
integer _Vp>
164 [[__gnu__::__always_inline__]]
165 constexpr rebind_t<make_signed_t<typename _Vp::value_type>, _Vp>
166 popcount(
const _Vp& __v)
noexcept
169 return rebind_t<_Ip, _Vp>([&](
int __i) {
170 return static_cast<_Ip
>(std::popcount(__v[__i]));
175 using simd::byteswap;
176 using simd::bit_ceil;
177 using simd::bit_floor;
178 using simd::has_single_bit;
181 using simd::bit_width;
182 using simd::countl_zero;
183 using simd::countl_one;
184 using simd::countr_zero;
185 using simd::countr_one;
186 using simd::popcount;
187_GLIBCXX_END_NAMESPACE_VERSION
190#pragma GCC diagnostic pop
typename make_signed< _Tp >::type make_signed_t
Alias template for make_signed.
ISO C++ entities toplevel namespace is std.