Skip to content

Commit

Permalink
Vector: add constructor taking an element reference
Browse files Browse the repository at this point in the history
Fixes #256
  • Loading branch information
amyspark committed Aug 12, 2021
1 parent 93ac07e commit 348637b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Vc/avx/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ template <typename T> class Vector<T, VectorAbi::Avx>
explicit Vector(U &&x) Vc_INTRINSIC_R;
#endif

Vc_INTRINSIC explicit Vector(reference a) : Vector(static_cast<EntryType>(a)) {}

///////////////////////////////////////////////////////////////////////////////////////////
// broadcast
Vc_INTRINSIC Vector(EntryType a) : d(Detail::avx_broadcast(a)) {}
Expand Down
1 change: 1 addition & 0 deletions Vc/common/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ template<typename T, typename Abi = VectorAbi::Best<T>> class Vector
template <typename U>
inline Vector(U a, enable_if<std::is_same<U, int>::value &&
!std::is_same<U, EntryType>::value> = nullarg);
inline explicit Vector(reference a);
///@}

/**
Expand Down
2 changes: 2 additions & 0 deletions Vc/scalar/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ template <typename T> class Vector<T, VectorAbi::Scalar>
}
#endif

Vc_INTRINSIC explicit Vector(reference a) : Vector(static_cast<EntryType>(a)) {}

///////////////////////////////////////////////////////////////////////////////////////////
// broadcast
Vc_INTRINSIC Vector(EntryType a) : m_data(a) {}
Expand Down
2 changes: 2 additions & 0 deletions Vc/sse/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ template <typename T> class Vector<T, VectorAbi::Sse>
{
}

Vc_INTRINSIC explicit Vector(reference a) : Vector(static_cast<EntryType>(a)) {}

#include "../common/loadinterface.h"
#include "../common/storeinterface.h"

Expand Down
11 changes: 11 additions & 0 deletions tests/casts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,17 @@ TEST(fullConversion)/*{{{*/
}/*}}}*/
#endif // Vc_DEFAULT_TYPES

TEST(referenceConstruction)
{
float_v a = float_v::Random();

Vc::float_v r = a[2];

for (size_t i = 0; i < float_v::Size; ++i) {
COMPARE(r[i], static_cast<float>(a[2])) << "i = " << i;
}
}

#if 0
/*{{{*/
template<typename T> constexpr bool may_overflow() { return std::is_integral<T>::value && std::is_unsigned<T>::value; }
Expand Down

0 comments on commit 348637b

Please sign in to comment.