1. Motivation
[P1928R4] introduced data parallel types to C++. It mostly provided operators
which worked on or with
types, but it also included overloads of
useful functions from other parts of C++ (e.g., sin, cos, abs).
Furthermore, in [P0543R2] a proposal is made to provide saturating operation support for
some basic arithmetic operations and casts. In particular,
,
,
and
are provided. These perform saturating arithmetic
operations which are effectively performed in infinite precision, and will
return the smallest or largest value when it is too large to be represented in
that type. In addition,
is also provided to convert to a new
type, and to saturate to the range of that type if required.
These saturating functions should be provided in
as element-wise operations.
2. Wording
Below, substitute the � character with a number the editor finds appropriate for the table, paragraph, section or sub-section.
2.1. Add new section [simd.numeric]
�
numeric library [simd.numeric]
basic_simd template < typename T , typename Abi > constexpr basic_simd < T , Abi > add_sat ( const basic_simd < T , Abi >& x , const basic_simd < T , Abi >& y ) noexcept ; template < typename T , typename Abi > constexpr basic_simd < T , Abi > sub_sat ( const basic_simd < T , Abi >& x , const basic_simd < T , Abi >& y ) noexcept ; template < typename T , typename Abi > constexpr basic_simd < T , Abi > mul_sat ( const basic_simd < T , Abi >& x , const basic_simd < T , Abi >& y ) noexcept ; template < typename T , typename Abi > constexpr basic_simd < T , Abi > div_sat ( const basic_simd < T , Abi >& x , const basic_simd < T , Abi >& y ) noexcept ; Constraints:
is a signed or unsigned integral.
T Any constraints that apply to
for the equivalent scalar operation will also apply here.
T Preconditions:
Any preconditions that apply to
for the equivalent scalar operation will also apply here.
T Returns:
A
value with the same type or size, where every value in the range
basic_simd is formed by performing the given operation on the ith values of the input. If the result is not representable, either the largest or smallest representable value of type
[ 0. . size ) , whichever is closer the actual result of that operation, will be returned.
T Remarks:
The arithmetic operation is performed as a mathematical operation with infinite range and then it is determined whether the mathematical result fits into the result type.
template < typename T , typename Abi , typename U > constexpr simd < T , basic_simd < U , Abi >:: size () > saturate_cast ( const basic_simd < U , Abi >& v ) noexcept ; Constraints:
is a signed or unsigned integral.
T Returns:
A
value with the same size as the input, but of the new element type
basic_simd . For every element of the return value, the ith element will be a copy of the ith element of v, otherwise it will be the largest or smallest value of type
U , whichever is closer to the original value of that element.
U