Skip to content

Commit 7baae55

Browse files
mattkretztkoeppe
authored andcommitted
P2933R4 Extend <bit> header function with overloads for std::simd
1 parent 0d4cceb commit 7baae55

File tree

2 files changed

+202
-1
lines changed

2 files changed

+202
-1
lines changed

source/numerics.tex

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16125,6 +16125,11 @@
1612516125

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

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

@@ -18438,6 +18480,165 @@
1843818480
\tcode{ret.first}.
1843918481
\end{itemdescr}
1844018482

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

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

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@
798798
#define @\defnlibxname{cpp_lib_shared_ptr_weak_type}@ 201606L // also in \libheader{memory}
799799
#define @\defnlibxname{cpp_lib_shared_timed_mutex}@ 201402L // also in \libheader{shared_mutex}
800800
#define @\defnlibxname{cpp_lib_shift}@ 202202L // also in \libheader{algorithm}
801-
#define @\defnlibxname{cpp_lib_simd}@ 202411L // also in \libheader{simd}
801+
#define @\defnlibxname{cpp_lib_simd}@ 202502L // also in \libheader{simd}
802802
#define @\defnlibxname{cpp_lib_smart_ptr_for_overwrite}@ 202002L // also in \libheader{memory}
803803
#define @\defnlibxname{cpp_lib_smart_ptr_owner_equality}@ 202306L // also in \libheader{memory}
804804
#define @\defnlibxname{cpp_lib_source_location}@ 201907L // freestanding, also in \libheader{source_location}

0 commit comments

Comments
 (0)