29 Numerics library [numerics]

29.10 Data-parallel types [simd]

29.10.6 Class template basic_simd [simd.class]

29.10.6.1 Class template basic_simd overview [simd.overview]

namespace std { template<class T, class Abi> class basic_simd { public: using value_type = T; using mask_type = basic_simd_mask<sizeof(T), Abi>; using abi_type = Abi; static constexpr integral_constant<simd-size-type, simd-size-v<T, Abi>> size {}; constexpr basic_simd() noexcept = default; // [simd.ctor], basic_simd constructors template<class U> constexpr basic_simd(U&& value) noexcept; template<class U, class UAbi> constexpr explicit(see below) basic_simd(const basic_simd<U, UAbi>&) noexcept; template<class G> constexpr explicit basic_simd(G&& gen) noexcept; template<class R, class... Flags> constexpr basic_simd(R&& range, simd_flags<Flags...> = {}); template<class R, class... Flags> constexpr basic_simd(R&& range, const mask_type& mask, simd_flags<Flags...> = {}); // [simd.subscr], basic_simd subscript operators constexpr value_type operator[](simd-size-type) const; // [simd.unary], basic_simd unary operators constexpr basic_simd& operator++() noexcept; constexpr basic_simd operator++(int) noexcept; constexpr basic_simd& operator--() noexcept; constexpr basic_simd operator--(int) noexcept; constexpr mask_type operator!() const noexcept; constexpr basic_simd operator~() const noexcept; constexpr basic_simd operator+() const noexcept; constexpr basic_simd operator-() const noexcept; // [simd.binary], basic_simd binary operators friend constexpr basic_simd operator+(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator-(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator*(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator/(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator%(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator&(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator|(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator^(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator<<(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator>>(const basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd operator<<(const basic_simd&, simd-size-type) noexcept; friend constexpr basic_simd operator>>(const basic_simd&, simd-size-type) noexcept; // [simd.cassign], basic_simd compound assignment friend constexpr basic_simd& operator+=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator-=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator*=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator/=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator%=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator&=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator|=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator^=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator<<=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator>>=(basic_simd&, const basic_simd&) noexcept; friend constexpr basic_simd& operator<<=(basic_simd&, simd-size-type) noexcept; friend constexpr basic_simd& operator>>=(basic_simd&, simd-size-type) noexcept; // [simd.comparison], basic_simd compare operators friend constexpr mask_type operator==(const basic_simd&, const basic_simd&) noexcept; friend constexpr mask_type operator!=(const basic_simd&, const basic_simd&) noexcept; friend constexpr mask_type operator>=(const basic_simd&, const basic_simd&) noexcept; friend constexpr mask_type operator<=(const basic_simd&, const basic_simd&) noexcept; friend constexpr mask_type operator>(const basic_simd&, const basic_simd&) noexcept; friend constexpr mask_type operator<(const basic_simd&, const basic_simd&) noexcept; // [simd.cond], basic_simd exposition only conditional operators friend constexpr basic_simd simd-select-impl( // exposition only const mask_type&, const basic_simd&, const basic_simd&) noexcept; }; template<class R, class... Ts> basic_simd(R&& r, Ts...) -> see below; }
Every specialization of basic_simd is a complete type.
The specialization of basic_simd<T, Abi> is
  • enabled, if T is a vectorizable type, and there exists value N in the range [1, 64], such that Abi is deduce-abi-t<T, N>,
  • otherwise, disabled, if T is not a vectorizable type,
  • otherwise, it is implementation-defined if such a specialization is enabled.
If basic_simd<T, Abi> is disabled, the specialization has a deleted default constructor, deleted destructor, deleted copy constructor, and deleted copy assignment.
In addition only the value_type, abi_type, and mask_type members are present.
If basic_simd<T, Abi> is enabled, basic_simd<T, Abi> is trivially copyable.
Recommended practice: Implementations should support explicit conversions between specializations of basic_simd and appropriate implementation-defined types.
[Note 1: 
Appropriate types are non-standard vector types which are available in the implementation.
— end note]

29.10.6.2 basic_simd constructors [simd.ctor]

template<class U> constexpr basic_simd(U&&) noexcept;
Let From denote the type remove_cvref_t<U>.
Constraints: From satisfies convertible_to<value_type>, and either
Effects: Initializes each element to the value of the argument after conversion to value_type.
template<class U, class UAbi> constexpr explicit(see below) basic_simd(const basic_simd<U, UAbi>& x) noexcept;
Constraints: simd-size-v<U, UAbi> == size() is true.
Effects: Initializes the element with static_cast<T>(x[i]) for all i in the range of [0, size()).
Remarks: The expression inside explicit evaluates to true if either
  • the conversion from U to value_type is not value-preserving, or
  • both U and value_type are integral types and the integer conversion rank ([conv.rank]) of U is greater than the integer conversion rank of value_type, or
  • both U and value_type are floating-point types and the floating-point conversion rank ([conv.rank]) of U is greater than the floating-point conversion rank of value_type.
template<class G> constexpr explicit basic_simd(G&& gen) noexcept;
Let From denote the type decltype(gen(integral_constant<simd-size-type, i>())).
Constraints: From satisfies convertible_to<value_type> for all i in the range of [0, size()).
In addition, for all i in the range of [0, size()), if From is an arithmetic type, conversion from From to value_type is value-preserving.
Effects: Initializes the element with static_cast<value_type>(gen(integral_constant<simd-​size-​type, i>())) for all i in the range of [0, size()).
Remarks: The calls to gen are unsequenced with respect to each other.
Vectorization-unsafe ([algorithms.parallel.defns]) standard library functions may not be invoked by gen.
gen is invoked exactly once for each i.
template<class R, class... Flags> constexpr basic_simd(R&& r, simd_flags<Flags...> = {}); template<class R, class... Flags> constexpr basic_simd(R&& r, const mask_type& mask, simd_flags<Flags...> = {});
Let mask be mask_type(true) for the overload with no mask parameter.
Constraints:
  • R models ranges​::​contiguous_range and ranges​::​sized_range,
  • ranges​::​size(r) is a constant expression, and
  • ranges​::​size(r) is equal to size().
Mandates:
  • ranges​::​range_value_t<R> is a vectorizable type, and
  • if the template parameter pack Flags does not contain convert-flag, then the conversion from ranges​::​range_value_t<R> to value_type is value-preserving.
Preconditions:
  • If the template parameter pack Flags contains aligned-flag, ranges​::​data(range) points to storage aligned by simd_alignment_v<basic_simd, ranges​::​range_value_t<R>>.
  • If the template parameter pack Flags contains overaligned-flag<N>, ranges​::​data(range) points to storage aligned by N.
Effects: Initializes the element with mask[i] ? static_cast<T>(​ranges​::​​data(range)[i]) : T() for all i in the range of [0, size()).
template<class R, class... Ts> basic_simd(R&& r, Ts...) -> see below;
Constraints:
  • R models ranges​::​contiguous_range and ranges​::​sized_range, and
  • ranges​::​size(r) is a constant expression.
Remarks: The deduced type is equivalent to simd<ranges​::​range_value_t<R>, ranges​::​size(r)>.

29.10.6.3 basic_simd subscript operator [simd.subscr]

constexpr value_type operator[](simd-size-type i) const;
Preconditions: i >= 0 && i < size() is true.
Returns: The value of the element.
Throws: Nothing.

29.10.6.4 basic_simd unary operators [simd.unary]

Effects in [simd.unary] are applied as unary element-wise operations.
constexpr basic_simd& operator++() noexcept;
Constraints: requires (value_type a) { ++a; } is true.
Effects: Increments every element by one.
Returns: *this.
constexpr basic_simd operator++(int) noexcept;
Constraints: requires (value_type a) { a++; } is true.
Effects: Increments every element by one.
Returns: A copy of *this before incrementing.
constexpr basic_simd& operator--() noexcept;
Constraints: requires (value_type a) { --a; } is true.
Effects: Decrements every element by one.
Returns: *this.
constexpr basic_simd operator--(int) noexcept;
Constraints: requires (value_type a) { a--; } is true.
Effects: Decrements every element by one.
Returns: A copy of *this before decrementing.
constexpr mask_type operator!() const noexcept;
Constraints: requires (const value_type a) { !a; } is true.
Returns: A basic_simd_mask object with the element set to !operator[](i) for all i in the range of [0, size()).
constexpr basic_simd operator~() const noexcept;
Constraints: requires (const value_type a) { ~a; } is true.
Returns: A basic_simd object with the element set to ~operator[](i) for all i in the range of [0, size()).
constexpr basic_simd operator+() const noexcept;
Constraints: requires (const value_type a) { +a; } is true.
Returns: *this.
constexpr basic_simd operator-() const noexcept;
Constraints: requires (const value_type a) { -a; } is true.
Returns: A basic_simd object where the element is initialized to -operator[](i) for all i in the range of [0, size()).