Skip to content

Commit 5afb6c7

Browse files
authored
Merge 2025-02 LWG Motion 13
P2933R4 Extend <bit> header function with overloads for std::simd
2 parents 7221de8 + 868ad5d commit 5afb6c7

File tree

2 files changed

+202
-1
lines changed

2 files changed

+202
-1
lines changed

source/numerics.tex

+201
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>> &&
@@ -16743,6 +16748,43 @@
1674316748
template<@\exposconcept{math-floating-point}@ V>
1674416749
@\exposid{deduced-simd-t}@<V>
1674516750
sph_neumann(const rebind_simd_t<unsigned, @\exposid{deduced-simd-t}@<V>>& n, const V& x);
16751+
16752+
// \ref{simd.bit}, Bit manipulation
16753+
template<@\exposconcept{simd-type}@ V> constexpr V byteswap(const V& v) noexcept;
16754+
template<@\exposconcept{simd-type}@ V> constexpr V bit_ceil(const V& v) noexcept;
16755+
template<@\exposconcept{simd-type}@ V> constexpr V bit_floor(const V& v) noexcept;
16756+
16757+
template<@\exposconcept{simd-type}@ V>
16758+
constexpr typename V::mask_type has_single_bit(const V& v) noexcept;
16759+
16760+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
16761+
constexpr V0 rotl(const V0& v, const V1& s) noexcept;
16762+
template<@\exposconcept{simd-type}@ V>
16763+
constexpr V rotl(const V& v, int s) noexcept;
16764+
16765+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
16766+
constexpr V0 rotr(const V0& v, const V1& s) noexcept;
16767+
template<@\exposconcept{simd-type}@ V>
16768+
constexpr V rotr(const V& v, int s) noexcept;
16769+
16770+
template<@\exposconcept{simd-type}@ V>
16771+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16772+
bit_width(const V& v) noexcept;
16773+
template<@\exposconcept{simd-type}@ V>
16774+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16775+
countl_zero(const V& v) noexcept;
16776+
template<@\exposconcept{simd-type}@ V>
16777+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16778+
countl_one(const V& v) noexcept;
16779+
template<@\exposconcept{simd-type}@ V>
16780+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16781+
countr_zero(const V& v) noexcept;
16782+
template<@\exposconcept{simd-type}@ V>
16783+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16784+
countr_one(const V& v) noexcept;
16785+
template<@\exposconcept{simd-type}@ V>
16786+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
16787+
popcount(const V& v) noexcept;
1674616788
}
1674716789
\end{codeblock}
1674816790

@@ -18471,6 +18513,165 @@
1847118513
\tcode{ret.first}.
1847218514
\end{itemdescr}
1847318515

18516+
\rSec3[simd.bit]{\tcode{basic_simd} bit library}
18517+
18518+
\begin{itemdecl}
18519+
template<@\exposconcept{simd-type}@ V> constexpr V byteswap(const V& v) noexcept;
18520+
\end{itemdecl}
18521+
18522+
\begin{itemdescr}
18523+
\pnum
18524+
\constraints
18525+
The type \tcode{V::value_type} models \tcode{integral}.
18526+
18527+
\pnum
18528+
\returns
18529+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18530+
the result of \tcode{std::byteswap(v[$i$])} for all $i$ in the range
18531+
\range{0}{V::size()}.
18532+
\end{itemdescr}
18533+
18534+
\begin{itemdecl}
18535+
template<@\exposconcept{simd-type}@ V> constexpr V bit_ceil(const V& v) noexcept;
18536+
\end{itemdecl}
18537+
18538+
\begin{itemdescr}
18539+
\pnum
18540+
\constraints
18541+
The type \tcode{V::value_type} is an unsigned integer type\iref{basic.fundamental}.
18542+
18543+
\pnum
18544+
\expects
18545+
For every $i$ in the range \range{0}{V::size()}, the smallest power of 2
18546+
greater than or equal to \tcode{v[$i$]} is representable as a value of type
18547+
\tcode{V::value_type}.
18548+
18549+
\pnum
18550+
\returns
18551+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18552+
the result of \tcode{std::bit_ceil(v[$i$])} for all $i$ in the range
18553+
\range{0}{V::size()}.
18554+
18555+
\pnum
18556+
\remarks
18557+
A function call expression that violates the precondition in the \expects
18558+
element is not a core constant expression\iref{expr.const}.
18559+
\end{itemdescr}
18560+
18561+
\begin{itemdecl}
18562+
template<@\exposconcept{simd-type}@ V> constexpr V bit_floor(const V& v) noexcept;
18563+
\end{itemdecl}
18564+
18565+
\begin{itemdescr}
18566+
\pnum
18567+
\constraints
18568+
The type \tcode{V::value_type} is an unsigned integer type\iref{basic.fundamental}.
18569+
18570+
\pnum
18571+
\returns
18572+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18573+
the result of \tcode{std::bit_floor(v[$i$])} for all $i$ in the range
18574+
\range{0}{V::size()}.
18575+
\end{itemdescr}
18576+
18577+
\begin{itemdecl}
18578+
template<@\exposconcept{simd-type}@ V>
18579+
constexpr typename V::mask_type has_single_bit(const V& v) noexcept;
18580+
\end{itemdecl}
18581+
18582+
\begin{itemdescr}
18583+
\pnum
18584+
\constraints
18585+
The type \tcode{V::value_type} is an unsigned integer type\iref{basic.fundamental}.
18586+
18587+
\pnum
18588+
\returns
18589+
A \tcode{basic_simd_mask} object where the $i^\text{th}$ element is initialized
18590+
to the result of \tcode{std::has_single_bit(v[$i$])} for all $i$ in the range
18591+
\range{0}{V::size()}.
18592+
\end{itemdescr}
18593+
18594+
\begin{itemdecl}
18595+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
18596+
constexpr V0 rotl(const V0& v0, const V1& v1) noexcept;
18597+
template<@\exposconcept{simd-type}@ V0, @\exposconcept{simd-type}@ V1>
18598+
constexpr V0 rotr(const V0& v0, const V1& v1) noexcept;
18599+
\end{itemdecl}
18600+
18601+
\begin{itemdescr}
18602+
\pnum
18603+
\constraints
18604+
\begin{itemize}
18605+
\item
18606+
The type \tcode{V0::value_type} is an unsigned integer type\iref{basic.fundamental},
18607+
\item
18608+
the type \tcode{V1::value_type} models \tcode{integral},
18609+
\item
18610+
\tcode{V0::size() == V1::size()} is \tcode{true}, and
18611+
\item
18612+
\tcode{sizeof(typename V0::value_type) == sizeof(typename V1::value_type)} is \tcode{true}.
18613+
\end{itemize}
18614+
18615+
\pnum
18616+
\returns
18617+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18618+
the result of \tcode{\placeholder{bit-func}(v0[$i$],
18619+
static_cast<int>(v1[$i$]))} for all $i$ in the range \range{0}{V0::size()},
18620+
where \placeholder{bit-func} is the corresponding scalar function from \libheader{bit}.
18621+
\end{itemdescr}
18622+
18623+
\begin{itemdecl}
18624+
template<@\exposconcept{simd-type}@ V> constexpr V rotl(const V& v, int s) noexcept;
18625+
template<@\exposconcept{simd-type}@ V> constexpr V rotr(const V& v, int s) 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$], s)} for all $i$ in the
18637+
range \range{0}{V::size()}, where \placeholder{bit-func} is the corresponding
18638+
scalar function from \libheader{bit}.
18639+
\end{itemdescr}
18640+
18641+
\begin{itemdecl}
18642+
template<@\exposconcept{simd-type}@ V>
18643+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18644+
bit_width(const V& v) noexcept;
18645+
template<@\exposconcept{simd-type}@ V>
18646+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18647+
countl_zero(const V& v) noexcept;
18648+
template<@\exposconcept{simd-type}@ V>
18649+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18650+
countl_one(const V& v) noexcept;
18651+
template<@\exposconcept{simd-type}@ V>
18652+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18653+
countr_zero(const V& v) noexcept;
18654+
template<@\exposconcept{simd-type}@ V>
18655+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18656+
countr_one(const V& v) noexcept;
18657+
template<@\exposconcept{simd-type}@ V>
18658+
constexpr rebind_simd_t<make_signed_t<typename V::value_type>, V>
18659+
popcount(const V& v) noexcept;
18660+
\end{itemdecl}
18661+
18662+
\begin{itemdescr}
18663+
\pnum
18664+
\constraints
18665+
The type \tcode{V::value_type} is an unsigned integer type\iref{basic.fundamental}
18666+
18667+
\pnum
18668+
\returns
18669+
A \tcode{basic_simd} object where the $i^\text{th}$ element is initialized to
18670+
the result of \tcode{\placeholder{bit-func}(v[$i$])} for all $i$ in the range
18671+
\range{0}{V::size()}, where \placeholder{bit-func} is the corresponding scalar
18672+
function from \libheader{bit}.
18673+
\end{itemdescr}
18674+
1847418675
\rSec2[simd.mask.class]{Class template \tcode{basic_simd_mask}}
1847518676

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

source/support.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@
799799
#define @\defnlibxname{cpp_lib_shared_ptr_weak_type}@ 201606L // also in \libheader{memory}
800800
#define @\defnlibxname{cpp_lib_shared_timed_mutex}@ 201402L // also in \libheader{shared_mutex}
801801
#define @\defnlibxname{cpp_lib_shift}@ 202202L // also in \libheader{algorithm}
802-
#define @\defnlibxname{cpp_lib_simd}@ 202411L // also in \libheader{simd}
802+
#define @\defnlibxname{cpp_lib_simd}@ 202502L // also in \libheader{simd}
803803
#define @\defnlibxname{cpp_lib_smart_ptr_for_overwrite}@ 202002L // also in \libheader{memory}
804804
#define @\defnlibxname{cpp_lib_smart_ptr_owner_equality}@ 202306L // also in \libheader{memory}
805805
#define @\defnlibxname{cpp_lib_source_location}@ 201907L // freestanding, also in \libheader{source_location}

0 commit comments

Comments
 (0)