Skip to content

Commit 38d1808

Browse files
committed
P2933R4 Extend <bit> header function with overloads for std::simd
1 parent 805aac8 commit 38d1808

File tree

2 files changed

+203
-1
lines changed

2 files changed

+203
-1
lines changed

source/numerics.tex

+202
Original file line numberDiff line numberDiff line change
@@ -16123,6 +16123,11 @@
1612316123

1612416124
template<class V, class T> using @\exposidnc{make-compatible-simd-t} = \seebelownc@; // \expos
1612516125

16126+
template<class V>
16127+
concept @\defexposconceptnc{simd-type}@ = // \expos
16128+
@\libconcept{same_as}@<V, basic_simd<typename V::value_type, typename V::abi_type>> &&
16129+
is_default_constructible_v<V>;
16130+
1612616131
template<class V>
1612716132
concept @\defexposconceptnc{simd-floating-point}@ = // \expos
1612816133
@\libconcept{same_as}@<V, basic_simd<typename V::value_type, typename V::abi_type>> &&
@@ -16736,6 +16741,43 @@
1673616741
template<@\exposconcept{math-floating-point}@ V>
1673716742
@\exposid{deduced-simd-t}@<V>
1673816743
sph_neumann(const rebind_simd_t<unsigned, @\exposid{deduced-simd-t}@<V>>& n, const V& x);
16744+
16745+
// \ref{simd.bit}, Bit manipulation
16746+
template<@\exposconcept{simd-type}@ V> constexpr V byteswap(const V& v) noexcept;
16747+
template<@\exposconcept{simd-type}@ V> constexpr V bit_ceil(const V& v) noexcept;
16748+
template<@\exposconcept{simd-type}@ V> constexpr V bit_floor(const V& v) noexcept;
16749+
16750+
template<@\exposconcept{simd-type}@ V>
16751+
constexpr typename V::mask_type has_single_bit(const V& v) noexcept;
16752+
16753+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
16754+
constexpr V0 rotl(const V0& v, const V1& s) noexcept;
16755+
template<@\exposconcept{simd-type}@ V>
16756+
constexpr V rotl(const V& v, int s) noexcept;
16757+
16758+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
16759+
constexpr V0 rotr(const V0& v, const V1& s) noexcept;
16760+
template<@\exposconcept{simd-type}@ V>
16761+
constexpr V rotr(const V& v, int s) noexcept;
16762+
16763+
template<@\exposconcept{simd-type}@ V>
16764+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16765+
bit_width(const V& v) noexcept;
16766+
template<@\exposconcept{simd-type}@ V>
16767+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16768+
countl_zero(const V& v) noexcept;
16769+
template<@\exposconcept{simd-type}@ V>
16770+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16771+
countl_one(const V& v) noexcept;
16772+
template<@\exposconcept{simd-type}@ V>
16773+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16774+
countr_zero(const V& v) noexcept;
16775+
template<@\exposconcept{simd-type}@ V>
16776+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16777+
countr_one(const V& v) noexcept;
16778+
template<@\exposconcept{simd-type}@ V>
16779+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16780+
popcount(const V& v) noexcept;
1673916781
}
1674016782
\end{codeblock}
1674116783

@@ -18436,6 +18478,166 @@
1843618478
\tcode{ret.first}.
1843718479
\end{itemdescr}
1843818480

18481+
\rSec3[simd.bit]{\tcode{basic_simd} bit library}
18482+
18483+
\begin{itemdecl}
18484+
template<@\exposconcept{simd-type}@ V> constexpr V byteswap(const V& v) noexcept;
18485+
\end{itemdecl}
18486+
18487+
\begin{itemdescr}
18488+
\pnum
18489+
\constraints
18490+
The type \tcode{V::value_type} models \tcode{integral}.
18491+
18492+
\pnum
18493+
\returns
18494+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18495+
the result of \tcode{std::byteswap(v[$i$])} for all $i$ in the range
18496+
\range{0}{V::size()}.
18497+
\end{itemdescr}
18498+
18499+
\begin{itemdecl}
18500+
template<@\exposconcept{simd-type}@ V> constexpr V bit_ceil(const V& v) noexcept;
18501+
\end{itemdecl}
18502+
18503+
\begin{itemdescr}
18504+
\pnum
18505+
\constraints
18506+
The type \tcode{V::value_type} is an unsigned integer type
18507+
\iref{basic.fundamental}.
18508+
18509+
\pnum
18510+
\expects
18511+
For every $i$ in the range \range{0}{V::size()}, the smallest power of 2
18512+
greater than or equal to \tcode{v[$i$]} is representable as a value of type
18513+
\tcode{V::value_type}.
18514+
18515+
\pnum
18516+
\returns
18517+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18518+
the result of \tcode{std::bit_ceil(v[$i$])} for all $i$ in the range
18519+
\range{0}{V::size()}.
18520+
18521+
\pnum
18522+
\remarks
18523+
A function call expression that violates the precondition in the \expects
18524+
element is not a core constant expression \iref{expr.const}.
18525+
\end{itemdescr}
18526+
18527+
\begin{itemdecl}
18528+
template<@\exposconcept{simd-type}@ V> constexpr V bit_floor(const V& v) noexcept;
18529+
\end{itemdecl}
18530+
18531+
\begin{itemdescr}
18532+
\pnum
18533+
\constraints
18534+
The type \tcode{V::value_type} is an unsigned integer type \iref{basic.fundamental}.
18535+
18536+
\pnum
18537+
\returns
18538+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18539+
the result of \tcode{std::bit_floor(v[$i$])} for all $i$ in the range
18540+
\range{0}{V::size()}.
18541+
\end{itemdescr}
18542+
18543+
\begin{itemdecl}
18544+
template<@\exposconcept{simd-type}@ V>
18545+
constexpr typename V::mask_type has_single_bit(const V& v) noexcept;
18546+
\end{itemdecl}
18547+
18548+
\begin{itemdescr}
18549+
\pnum
18550+
\constraints
18551+
The type \tcode{V::value_type} is an unsigned integer type \iref{basic.fundamental}.
18552+
18553+
\pnum
18554+
\returns
18555+
A \tcode{basic_simd_mask} object where the $i^\text{th}$ element is initialized
18556+
to the result of \tcode{std::has_single_bit(v[$i$])} for all $i$ in the range
18557+
\range{0}{V::size()}.
18558+
\end{itemdescr}
18559+
18560+
\begin{itemdecl}
18561+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
18562+
constexpr V0 rotl(const V0& v0, const V1& v1) noexcept;
18563+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
18564+
constexpr V0 rotr(const V0& v0, const V1& v1) noexcept;
18565+
\end{itemdecl}
18566+
18567+
\begin{itemdescr}
18568+
\pnum
18569+
\constraints
18570+
\begin{itemize}
18571+
\item
18572+
The type \tcode{V0::value_type} is an unsigned integer type \iref{basic.fundamental},
18573+
\item
18574+
the type \tcode{V1::value_type} models \tcode{integral},
18575+
\item
18576+
\tcode{V0::size() == V1::size()} is \tcode{true}, and
18577+
\item
18578+
\tcode{sizeof(typename V0::value_type) == sizeof(typename V1::value_type)} is \tcode{true}.
18579+
\end{itemize}
18580+
18581+
\pnum
18582+
\returns
18583+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18584+
the result of \tcode{\placeholder{bit-func}(v0[$i$],
18585+
static_cast<int>(v1[$i$]))} for all $i$ in the range \range{0}{V0::size()},
18586+
where \placeholder{bit-func} is the corresponding scalar function from \tcode{<bit>}.
18587+
\end{itemdescr}
18588+
18589+
\begin{itemdecl}
18590+
template<@\exposconcept{simd-type}@ V> constexpr V rotl(const V& v, int s) noexcept;
18591+
template<@\exposconcept{simd-type}@ V> constexpr V rotr(const V& v, int s) noexcept;
18592+
\end{itemdecl}
18593+
18594+
\begin{itemdescr}
18595+
\pnum
18596+
\constraints
18597+
The type \tcode{V::value_type} is an unsigned integer type \iref{basic.fundamental}
18598+
18599+
\pnum
18600+
\returns
18601+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18602+
the result of \tcode{\placeholder{bit-func}(v[$i$], s)} for all $i$ in the
18603+
range \range{0}{V::size()}, where \placeholder{bit-func} is the corresponding
18604+
scalar function from \tcode{<bit>}.
18605+
\end{itemdescr}
18606+
18607+
\begin{itemdecl}
18608+
template<@\exposconcept{simd-type}@ V>
18609+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18610+
bit_width(const V& v) noexcept;
18611+
template<@\exposconcept{simd-type}@ V>
18612+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18613+
countl_zero(const V& v) noexcept;
18614+
template<@\exposconcept{simd-type}@ V>
18615+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18616+
countl_one(const V& v) noexcept;
18617+
template<@\exposconcept{simd-type}@ V>
18618+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18619+
countr_zero(const V& v) noexcept;
18620+
template<@\exposconcept{simd-type}@ V>
18621+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18622+
countr_one(const V& v) noexcept;
18623+
template<@\exposconcept{simd-type}@ V>
18624+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18625+
popcount(const V& v) noexcept;
18626+
\end{itemdecl}
18627+
18628+
\begin{itemdescr}
18629+
\pnum
18630+
\constraints
18631+
The type \tcode{V::value_type} is an unsigned integer type \iref{basic.fundamental}
18632+
18633+
\pnum
18634+
\returns
18635+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18636+
the result of \tcode{\placeholder{bit-func}(v[$i$])} for all $i$ in the range
18637+
\range{0}{V::size()}, where \placeholder{bit-func} is the corresponding scalar
18638+
function from \tcode{<bit>}.
18639+
\end{itemdescr}
18640+
1843918641
\rSec2[simd.mask.class]{Class template \tcode{basic_simd_mask}}
1844018642

1844118643
\rSec3[simd.mask.overview]{Class template \tcode{basic_simd_mask} overview}

source/support.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@
782782
#define @\defnlibxname{cpp_lib_shared_ptr_weak_type}@ 201606L // also in \libheader{memory}
783783
#define @\defnlibxname{cpp_lib_shared_timed_mutex}@ 201402L // also in \libheader{shared_mutex}
784784
#define @\defnlibxname{cpp_lib_shift}@ 202202L // also in \libheader{algorithm}
785-
#define @\defnlibxname{cpp_lib_simd}@ 202411L // also in \libheader{simd}
785+
#define @\defnlibxname{cpp_lib_simd}@ 202502L // also in \libheader{simd}
786786
#define @\defnlibxname{cpp_lib_smart_ptr_for_overwrite}@ 202002L // also in \libheader{memory}
787787
#define @\defnlibxname{cpp_lib_smart_ptr_owner_equality}@ 202306L // also in \libheader{memory}
788788
#define @\defnlibxname{cpp_lib_source_location}@ 201907L // freestanding, also in \libheader{source_location}

0 commit comments

Comments
 (0)