29 Numerics library [numerics]

29.10 Data-parallel types [simd]

29.10.7 Class template basic_vec [simd.class]

29.10.7.1 Class template basic_vec overview [simd.overview]

namespace std::simd { template<class T, class Abi> class basic_vec { public: using value_type = T; using mask_type = basic_mask<sizeof(T), Abi>; using abi_type = Abi; using iterator = simd-iterator<basic_vec>; using const_iterator = simd-iterator<const basic_vec>; constexpr iterator begin() noexcept { return {*this, 0}; } constexpr const_iterator begin() const noexcept { return {*this, 0}; } constexpr const_iterator cbegin() const noexcept { return {*this, 0}; } constexpr default_sentinel_t end() const noexcept { return {}; } constexpr default_sentinel_t cend() const noexcept { return {}; } static constexpr integral_constant<simd-size-type, simd-size-v<T, Abi>> size {}; constexpr basic_vec() noexcept = default; // [simd.ctor], basic_vec constructors template<class U> constexpr explicit(see below) basic_vec(U&& value) noexcept; template<class U, class UAbi> constexpr explicit(see below) basic_vec(const basic_vec<U, UAbi>&) noexcept; template<class G> constexpr explicit basic_vec(G&& gen) noexcept; template<class R, class... Flags> constexpr basic_vec(R&& range, flags<Flags...> = {}); template<class R, class... Flags> constexpr basic_vec(R&& range, const mask_type& mask, flags<Flags...> = {}); template<simd-floating-point V> constexpr explicit(see below) basic_vec(const V& reals, const V& imags = {}) noexcept; // [simd.subscr], basic_vec subscript operators constexpr value_type operator[](simd-size-type) const; template<simd-integral I> constexpr resize_t<I::size(), basic_vec> operator[](const I& indices) const; // [simd.unary], basic_vec unary operators constexpr basic_vec& operator++() noexcept; constexpr basic_vec operator++(int) noexcept; constexpr basic_vec& operator--() noexcept; constexpr basic_vec operator--(int) noexcept; constexpr mask_type operator!() const noexcept; constexpr basic_vec operator~() const noexcept; constexpr basic_vec operator+() const noexcept; constexpr basic_vec operator-() const noexcept; // [simd.binary], basic_vec binary operators friend constexpr basic_vec operator+(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator-(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator*(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator/(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator%(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator&(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator|(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator^(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator<<(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator>>(const basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec operator<<(const basic_vec&, simd-size-type) noexcept; friend constexpr basic_vec operator>>(const basic_vec&, simd-size-type) noexcept; // [simd.cassign], basic_vec compound assignment friend constexpr basic_vec& operator+=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator-=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator*=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator/=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator%=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator&=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator|=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator^=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator<<=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator>>=(basic_vec&, const basic_vec&) noexcept; friend constexpr basic_vec& operator<<=(basic_vec&, simd-size-type) noexcept; friend constexpr basic_vec& operator>>=(basic_vec&, simd-size-type) noexcept; // [simd.comparison], basic_vec compare operators friend constexpr mask_type operator==(const basic_vec&, const basic_vec&) noexcept; friend constexpr mask_type operator!=(const basic_vec&, const basic_vec&) noexcept; friend constexpr mask_type operator>=(const basic_vec&, const basic_vec&) noexcept; friend constexpr mask_type operator<=(const basic_vec&, const basic_vec&) noexcept; friend constexpr mask_type operator>(const basic_vec&, const basic_vec&) noexcept; friend constexpr mask_type operator<(const basic_vec&, const basic_vec&) noexcept; // [simd.complex.access], basic_vec complex-value accessors constexpr auto real() const noexcept; constexpr auto imag() const noexcept; template<simd-floating-point V> constexpr void real(const V& v) noexcept; template<simd-floating-point V> constexpr void imag(const V& v) noexcept; // [simd.cond], basic_vec exposition only conditional operators friend constexpr basic_vec simd-select-impl( // exposition only const mask_type&, const basic_vec&, const basic_vec&) noexcept; }; template<class R, class... Ts> basic_vec(R&& r, Ts...) -> see below; }
Every specialization of basic_vec is a complete type.
The specialization of basic_vec<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_vec<T, Abi> is disabled, then 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_vec<T, Abi> is enabled, then basic_vec<T, Abi> is trivially copyable, default-initialization of an object of such a type default-initializes all elements, and value-initialization value-initializes all elements ([dcl.init.general]).
Recommended practice: Implementations should support implicit conversions between specializations of basic_vec and appropriate implementation-defined types.
[Note 1: 
Appropriate types are non-standard vector types which are available in the implementation.
— end note]

29.10.7.2 basic_vec constructors [simd.ctor]

template<class U> constexpr explicit(see below) basic_vec(U&& value) noexcept;
Let From denote the type remove_cvref_t<U>.
Constraints: value_type satisfies constructible_from<U>.
Effects: Initializes each element to the value of the argument after conversion to value_type.
Remarks: The expression inside explicit evaluates to false if and only if U satisfies convertible_to<value_type>, and either
template<class U, class UAbi> constexpr explicit(see below) basic_vec(const basic_vec<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_vec(G&& gen);
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: gen is invoked exactly once for each i, in increasing order of i.
template<class R, class... Flags> constexpr basic_vec(R&& r, flags<Flags...> = {}); template<class R, class... Flags> constexpr basic_vec(R&& r, const mask_type& mask, flags<Flags...> = {});
Let mask be mask_type(true) for the overload with no mask parameter.
Constraints:
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(r) points to storage aligned by alignment_v<basic_vec, ranges​::​range_value_t<R>>.
  • If the template parameter pack Flags contains overaligned-flag<N>, ranges​::​data(r) points to storage aligned by N.
Effects: Initializes the element with mask[i] ? static_cast<T>(​ranges​::​​data(r)[i]) : T() for all i in the range of [0, size()).
template<class R, class... Ts> basic_vec(R&& r, Ts...) -> see below;
Constraints:
Remarks: The deduced type is equivalent to vec<ranges​::​range_value_t<R>, ranges​::​size(r)>.
template<simd-floating-point V> constexpr explicit(see below) basic_vec(const V& reals, const V& imags = {}) noexcept;
Constraints:
Effects: Initializes the element with value_type(reals[i], imags[i]) for all i in the range [0, size()).
Remarks: The expression inside explicit evaluates to false if and only if the floating-point conversion rank of T​::​value_type is greater than or equal to the floating-point conversion rank of V​::​value_type.

29.10.7.3 basic_vec 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.
template<simd-integral I> constexpr resize_t<I::size(), basic_vec> operator[](const I& indices) const;
Effects: Equivalent to: return permute(*this, indices);

29.10.7.4 basic_vec unary operators [simd.unary]

Effects in [simd.unary] are applied as unary element-wise operations.
constexpr basic_vec& operator++() noexcept;
Constraints: requires (value_type a) { ++a; } is true.
Effects: Increments every element by one.
Returns: *this.
constexpr basic_vec 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_vec& operator--() noexcept;
Constraints: requires (value_type a) { --a; } is true.
Effects: Decrements every element by one.
Returns: *this.
constexpr basic_vec 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_mask object with the element set to !operator[](i) for all i in the range of [0, size()).
constexpr basic_vec operator~() const noexcept;
Constraints: requires (const value_type a) { ~a; } is true.
Returns: A basic_vec object with the element set to ~operator[](i) for all i in the range of [0, size()).
constexpr basic_vec operator+() const noexcept;
Constraints: requires (const value_type a) { +a; } is true.
Returns: *this.
constexpr basic_vec operator-() const noexcept;
Constraints: requires (const value_type a) { -a; } is true.
Returns: A basic_vec object where the element is initialized to -operator[](i) for all i in the range of [0, size()).