34#include <xvec/detail/config.hpp>
35#include <xvec/detail/compat.hpp>
37#include <xvec/detail/target_config.hpp>
39#include <xvec/detail/core.hpp>
41#include <xvec/detail/std_limits.hpp>
42#include <xvec/detail/std_rebind.hpp>
44#include <xvec/generic/generic_impl.hpp>
45#include <xvec/detail/iterator.hpp>
48#if defined(__SSE__) and !defined(_XVEC_FORCE_SCALAR)
49#include <xvec/x86/intrin.hpp>
50#include <xvec/x86/x86_impl.hpp>
54#include <xvec/detail/operators.hpp>
56#include <xvec/detail/mask.hpp>
58#ifdef _XVEC_DEFINE_OUTPUT_OPERATORS
62namespace _XVEC_NAMESPACE::simd
161template <
typename _Tp,
typename _Abi>
class basic_vec {
174 std::conditional_t<vec_complex<basic_vec>,
175 rebind_t<detail::complex_element_type<_Tp>, basic_vec>,
struct invalid>;
177 using builtin_type =
typename traits::builtin_type;
187 static constexpr auto size = size_constant<simd_size_v<_Tp, _Abi>>{};
204 constexpr basic_vec(
const basic_vec&) =
default;
205 constexpr basic_vec(basic_vec&&) noexcept = default;
206 constexpr basic_vec& operator=(const basic_vec&) = default;
207 constexpr basic_vec& operator=(basic_vec&&) noexcept = default;
218 constexpr basic_vec(const builtin_type& v) noexcept : data(v) {}
228 requires (!std::is_convertible_v<register_type, const builtin_type&>)
229 : data(
traits::from_register(r)) {}
241 template<
typename _InputSpan,
typename... _Flags>
243 detail::span_extent_v<_InputSpan> == size &&
247 if (std::is_constant_evaluated())
248 return basic_vec([=](
auto i) {
return static_cast<value_type
>(in_span[i]); });
250 return detail::load<basic_vec>(target, std::span(in_span), detail::add_unchecked_flag(f));
257 template<
typename _InputSpan,
typename... _Flags>
258 requires (!vec_type<_InputSpan> &&
259 detail::span_extent_v<_InputSpan> == size &&
260 detail::explicitly_convertible_to<detail::span_element_type<_InputSpan>, _Tp>)
263 if (std::is_constant_evaluated())
266 return detail::load_masked<basic_vec>(target, std::span(in_span), m, detail::add_unchecked_flag(f));
271 template<detail::broadcast_constructible<_Tp> _Up = _Tp>
289 template<vec_type _Vp>
290 requires (!(vec_complex<basic_vec> ^ vec_complex<_Vp>) &&
291 (_Vp::size() == size()) &&
292 detail::explicitly_convertible_to<typename _Vp::value_type, _Tp> &&
293 detail::needs_explicit_conversion<typename _Vp::value_type, _Tp>)
299 template<vec_type _Vp>
301 (_Vp::size() == size()) &&
321 constexpr const_iterator
begin() const noexcept {
return {*
this, 0}; }
324 constexpr const_iterator
cbegin() const noexcept {
return {*
this, 0}; }
327 constexpr std::default_sentinel_t
end() const noexcept {
return {}; }
330 constexpr std::default_sentinel_t
cend() const noexcept {
return {}; }
350 static constexpr basic_vec
from_builtin(
const builtin_type& v)
noexcept {
return basic_vec(v); }
372 {
return detail::select_if_else(target, m, if_true, if_false); }
379 requires requires (
value_type a) { {!a} -> std::same_as<bool>; }
393 constexpr basic_vec
operator+() const noexcept {
return *
this; }
396 constexpr basic_vec&
operator++() noexcept requires requires (basic_vec v) { v + basic_vec(_Tp(1)); }
397 { *
this = *
this +
basic_vec(_Tp(1));
return *
this; }
400 constexpr basic_vec
operator++(
int)
noexcept requires requires (basic_vec v) { v + basic_vec(_Tp(1)); }
401 {
const auto original = *
this; *
this = *
this +
basic_vec(_Tp(1));
return original; }
404 constexpr basic_vec&
operator--() noexcept requires requires (basic_vec v) { v - basic_vec(_Tp(1)); }
405 { *
this = *
this -
basic_vec(_Tp(1));
return *
this; }
408 constexpr basic_vec
operator--(
int)
noexcept requires requires (basic_vec v) { v - basic_vec(_Tp(1)); }
409 {
const auto original = *
this; *
this = *
this -
basic_vec(_Tp(1));
return original; }
454 friend constexpr basic_vec
operator*(
const basic_vec& lhs,
const detail::complex_element_type<_Tp>& rhs)
noexcept
458 return std::bit_cast<basic_vec>(t);
462 friend constexpr basic_vec
operator*(
const detail::complex_element_type<_Tp>& lhs,
const basic_vec& rhs)
noexcept
464 {
return rhs * lhs; }
468 { lhs = lhs * rhs;
return lhs; }
486 friend constexpr mask_type operator< (
const basic_vec& lhs,
const basic_vec& rhs)
noexcept
496 friend constexpr mask_type operator> (
const basic_vec& lhs,
const basic_vec& rhs)
noexcept
511 friend constexpr basic_vec&
operator+=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
513 { lhs = lhs + rhs;
return lhs; }
516 friend constexpr basic_vec&
operator-=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
518 { lhs = lhs - rhs;
return lhs; }
521 friend constexpr basic_vec&
operator*=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
523 { lhs = lhs * rhs;
return lhs; }
526 friend constexpr basic_vec&
operator/=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
528 { lhs = lhs / rhs;
return lhs; }
531 friend constexpr basic_vec&
operator%=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
533 { lhs = lhs % rhs;
return lhs; }
536 friend constexpr basic_vec&
operator&=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
538 { lhs = lhs & rhs;
return lhs; }
541 friend constexpr basic_vec&
operator|=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
543 { lhs = lhs | rhs;
return lhs; }
546 friend constexpr basic_vec&
operator^=(basic_vec& lhs,
const basic_vec& rhs)
noexcept
548 { lhs = lhs ^ rhs;
return lhs; }
576 friend constexpr basic_vec&
operator<<=(basic_vec& lhs,
const basic_vec& shift)
noexcept
578 { lhs = lhs << shift;
return lhs; }
581 friend constexpr basic_vec&
operator>>=(basic_vec& lhs,
const basic_vec& shift)
noexcept
583 { lhs = lhs >> shift;
return lhs; }
586 friend constexpr basic_vec&
operator<<=(basic_vec& lhs, simd_size_type shift)
noexcept
588 { lhs = lhs << shift;
return lhs; }
591 friend constexpr basic_vec&
operator>>=(basic_vec& lhs, simd_size_type shift)
noexcept
593 { lhs = lhs >> shift;
return lhs; }
604 return permute<size>(e, [](simd_size_type idx) {
return idx * 2; });
611 return permute<size>(e, [](simd_size_type idx) {
return idx * 2 + 1; });
617 { *
this = basic_vec(new_reals,
imag()); }
622 { *
this = basic_vec(
real(), new_imags); }
626#ifdef _XVEC_DEFINE_OUTPUT_OPERATORS
630 friend std::ostream &operator<<(std::ostream& stream,
basic_vec value) {
636 stream <<
'[' << ri <<
"]:" << value[ri];
647template <
typename _Span,
class... Ts>
648requires (detail::span_extent_v<std::remove_cvref_t<_Span>>
649 <= detail::max_fixed_size<detail::span_element_type<std::remove_cvref_t<_Span>>>)
655#include <xvec/detail/named_permute.hpp>
656#include <xvec/detail/loadstore.hpp>
657#include <xvec/detail/invoke.hpp>
658#include <xvec/detail/permute.hpp>
659#include <xvec/detail/split_concat.hpp>
660#include <xvec/detail/std_algorithm.hpp>
661#include <xvec/detail/std_bit.hpp>
662#include <xvec/detail/std_math.hpp>
663#include <xvec/detail/std_complex.hpp>
664#include <xvec/detail/reduce.hpp>
665#include <xvec/detail/std_numeric.hpp>
666#include <xvec/detail/std_utility.hpp>
A mask containing boolean elements.
Definition mask.hpp:121
Vector of elements sharing an element type and ABI.
Definition simd:161
value_type & reference_type
Definition simd:167
static constexpr auto size
Definition simd:187
_Abi abi_type
Definition simd:168
detail::vec_traits< target_tag, _Tp, _Abi::num_elements > traits
Definition simd:164
typename traits::register_type register_type
Definition simd:180
_Tp value_type
Definition simd:166
simd_iterator< basic_vec > iterator
Definition simd:169
std::conditional_t< vec_complex< basic_vec >, rebind_t< detail::complex_element_type< _Tp >, basic_vec >, struct invalid > real_type
Definition simd:173
constexpr basic_vec(const _Vp &v) noexcept
Convert a vector implicitly when its element conversion permits it.
Definition simd:304
xvec implementation of the exposition-only SIMD iterator.
Definition iterator.hpp:32
Detect whether a given type is std::complex.
Definition utilities.hpp:53
constexpr auto select(const _M &m, const _T &if_true, const _U &if_false) noexcept -> decltype(simd_select_impl(m, if_true, if_false))
Select between corresponding elements according to a mask.
Definition std_algorithm.hpp:88
friend constexpr basic_vec operator&(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the bitwise AND of corresponding elements.
Definition simd:437
friend constexpr basic_vec operator/(const basic_vec &lhs, const basic_vec &rhs) noexcept
Divide corresponding elements.
Definition simd:429
friend constexpr basic_vec operator>>(const basic_vec &lhs, simd_size_type rhs) noexcept
Shift every element right by a shared amount.
Definition simd:568
friend constexpr basic_vec operator*(const basic_vec &lhs, const basic_vec &rhs) noexcept
Multiply corresponding elements.
Definition simd:425
friend constexpr basic_vec operator|(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the bitwise OR of corresponding elements.
Definition simd:441
friend constexpr basic_vec operator+(const basic_vec &lhs, const basic_vec &rhs) noexcept
Add corresponding elements.
Definition simd:417
friend constexpr basic_vec operator<<(const basic_vec &lhs, const basic_vec &rhs) noexcept
Shift elements left by corresponding element-wise amounts.
Definition simd:556
friend constexpr basic_vec operator-(const basic_vec &lhs, const basic_vec &rhs) noexcept
Subtract corresponding elements.
Definition simd:421
friend constexpr basic_vec operator>>(const basic_vec &lhs, const basic_vec &rhs) noexcept
Shift elements right by corresponding element-wise amounts.
Definition simd:560
friend constexpr basic_vec operator%(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the remainder for corresponding elements.
Definition simd:433
friend constexpr basic_vec operator<<(const basic_vec &lhs, simd_size_type rhs) noexcept
Shift every element left by a shared amount.
Definition simd:564
friend constexpr basic_vec operator^(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the bitwise XOR of corresponding elements.
Definition simd:445
friend constexpr basic_vec & operator*=(basic_vec &lhs, const basic_vec &rhs) noexcept
Multiply corresponding elements and assign the result.
Definition simd:521
friend constexpr basic_vec & operator>>=(basic_vec &lhs, const basic_vec &shift) noexcept
Shift elements right by element-wise amounts and assign the result.
Definition simd:581
friend constexpr basic_vec & operator-=(basic_vec &lhs, const basic_vec &rhs) noexcept
Subtract corresponding elements and assign the result.
Definition simd:516
friend constexpr basic_vec & operator/=(basic_vec &lhs, const basic_vec &rhs) noexcept
Divide corresponding elements and assign the result.
Definition simd:526
friend constexpr basic_vec & operator>>=(basic_vec &lhs, simd_size_type shift) noexcept
Shift every element right by a shared amount and assign the result.
Definition simd:591
friend constexpr basic_vec & operator<<=(basic_vec &lhs, const basic_vec &shift) noexcept
Shift elements left by element-wise amounts and assign the result.
Definition simd:576
friend constexpr basic_vec & operator^=(basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the element-wise bitwise XOR and assign the result.
Definition simd:546
friend constexpr basic_vec & operator%=(basic_vec &lhs, const basic_vec &rhs) noexcept
Compute element-wise remainders and assign the result.
Definition simd:531
friend constexpr basic_vec & operator<<=(basic_vec &lhs, simd_size_type shift) noexcept
Shift every element left by a shared amount and assign the result.
Definition simd:586
friend constexpr basic_vec & operator&=(basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the element-wise bitwise AND and assign the result.
Definition simd:536
friend constexpr basic_vec & operator|=(basic_vec &lhs, const basic_vec &rhs) noexcept
Compute the element-wise bitwise OR and assign the result.
Definition simd:541
friend constexpr basic_vec & operator+=(basic_vec &lhs, const basic_vec &rhs) noexcept
Add corresponding elements and assign the result.
Definition simd:511
friend constexpr mask_type operator==(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compare corresponding elements for equality.
Definition simd:476
friend constexpr mask_type operator<=(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compare corresponding elements using less-than-or-equal.
Definition simd:491
friend constexpr mask_type operator!=(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compare corresponding elements for inequality.
Definition simd:481
friend constexpr mask_type operator>=(const basic_vec &lhs, const basic_vec &rhs) noexcept
Compare corresponding elements using greater-than-or-equal.
Definition simd:501
constexpr real_type real() const noexcept
Return the real components of the complex elements.
Definition simd:602
constexpr void imag(const real_type &new_imags) noexcept
Replace the imaginary component of each complex element.
Definition simd:621
constexpr real_type imag() const noexcept
Return the imaginary components of the complex elements.
Definition simd:609
constexpr void real(const real_type &new_reals) noexcept
Replace the real component of each complex element.
Definition simd:616
friend constexpr basic_vec simd_select_impl(const mask_type &m, const basic_vec &if_true, const basic_vec &if_false) noexcept
Implementation of element-wise vector selection.
Definition simd:371
constexpr basic_vec(detail::generator_invocable< value_type, size > auto &&fn)
Construct a vector by generating each element from its index.
Definition simd:310
constexpr basic_vec(_Up &&v) noexcept
Create a basic_vec value in which every element is set to the single value provided.
Definition simd:272
constexpr basic_vec(const _Vp &v) noexcept
Explicitly convert a vector with the same number of elements. Both element types must be complex or n...
Definition simd:294
constexpr basic_vec(const _InputSpan &in_span, flags< _Flags... > f={})
Constructs a basic_vec by reading the contents of an object with the same number of elements (e....
Definition simd:245
constexpr basic_vec(const real_type &r, const real_type &i={}) noexcept
Construct a complex vector from real and imaginary component vectors. Each complex element combines t...
Definition simd:279
constexpr basic_vec(const _InputSpan &in_span, const mask_type &m, flags< _Flags... > f={})
Construct a vector from selected elements of a span-like object.
Definition simd:261
constexpr std::default_sentinel_t cend() const noexcept
Return the end sentinel.
Definition simd:330
constexpr const_iterator begin() const noexcept
Return a const iterator to the first element.
Definition simd:321
constexpr const_iterator cbegin() const noexcept
Return a const iterator to the first element.
Definition simd:324
constexpr iterator begin() noexcept
Return an iterator to the first element.
Definition simd:318
constexpr std::default_sentinel_t end() const noexcept
Return the end sentinel.
Definition simd:327
constexpr auto permute(const _Vp &v, detail::index_generator_function auto &&fn)
Permute the elements in a vec value using a generator function to compute the indexing.
Definition permute.hpp:94
constexpr auto operator[](const vec_integral auto &indexes) const
Select vector elements using an integral index vector.
Definition simd:364
constexpr value_type operator[](simd_size_type pos) const
Access the element at the specified position.
Definition simd:359
constexpr basic_vec & operator--() noexcept
Decrement each element and return the updated vector.
Definition simd:404
constexpr mask_type operator!() const noexcept
Apply logical not to each vector element to produce a mask.
Definition simd:378
constexpr basic_vec operator--(int) noexcept
Decrement each element and return the original vector.
Definition simd:408
constexpr basic_vec operator+() const noexcept
Return a copy of the vector.
Definition simd:393
constexpr basic_vec operator++(int) noexcept
Increment each element and return the original vector.
Definition simd:400
constexpr basic_vec operator-() const noexcept
Negate each vector element.
Definition simd:388
constexpr basic_vec & operator++() noexcept
Increment each element and return the updated vector.
Definition simd:396
constexpr basic_vec operator~() const noexcept
Apply bitwise not to each vector element.
Definition simd:383
constexpr auto zip(const _Sps &...simds)
Definition named_permute.hpp:283
static constexpr basic_vec from_builtin(const builtin_type &v) noexcept
Construct a vector from its builtin representation.
Definition simd:350
constexpr builtin_type to_builtin() const
Return the builtin value.
Definition simd:347
constexpr traits::register_type to_register() const
Definition simd:344
constexpr basic_vec(register_type r) noexcept
Definition simd:227
friend constexpr basic_vec operator*(const basic_vec &lhs, const detail::complex_element_type< _Tp > &rhs) noexcept
Multiply each complex element by a real scalar.
Definition simd:454
friend constexpr basic_vec & operator*=(basic_vec &lhs, const detail::complex_element_type< _Tp > &rhs) noexcept
Multiply each complex element by a real scalar and assign the result.
Definition simd:467
constexpr auto simd_bit_cast(const _From &v) noexcept
A simd-generic version of simd_bit_cast which directly invokes std::bit_cast.
Definition core.hpp:585
friend constexpr basic_vec operator*(const detail::complex_element_type< _Tp > &lhs, const basic_vec &rhs) noexcept
Multiply a real scalar by each complex element.
Definition simd:462
Detect a scoped enum. This will be provided in C++23 onwards.
Definition compat.hpp:27
constexpr auto do_operator(const _Vp &first, const _Vps &... rest) noexcept
Definition operators.hpp:136
constexpr _To convert_operator(const _From &v) noexcept
Conversion operator for basic_vec. All gate-keeping has been done, just do the convert.
Definition operators.hpp:163
decltype(detail::get_register_type< builtin_type >()) register_type
Definition core.hpp:474
static constexpr register_type to_register(builtin_type v)
Definition core.hpp:488
An implementation ABI type which is used to specify a simd::vec with a fixed number of elements.
Definition core.hpp:34