Skip to content

Commit

Permalink
Fix 1-element ec ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
GagaLP committed Jan 27, 2025
1 parent bf7fe2a commit 98dc3b6
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions include/simsycl/sycl/vec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../detail/check.hh"
#include "../detail/utils.hh"

#include <concepts>
#include <cstdint>
#include <cstdlib>
#include <type_traits>
Expand Down Expand Up @@ -234,8 +235,9 @@ class swizzled_vec {
swizzled_vec &operator=(const swizzled_vec &) = delete;
swizzled_vec &operator=(swizzled_vec &&) = delete;

swizzled_vec &operator=(const value_type &rhs)
requires(allow_assign)
template<typename T>
swizzled_vec &operator=(const T &rhs)
requires(allow_assign && std::convertible_to<T, value_type>)
{
for(size_t i = 0; i < num_elements; ++i) { m_elems[indices[i]] = rhs; }
return *this;
Expand Down Expand Up @@ -540,7 +542,10 @@ class alignas(detail::vec_alignment_v<DataT, NumElements>) vec {
vec(const vec &) = default;
vec &operator=(const vec &rhs) = default;

vec &operator=(const DataT &rhs) {
template<typename T>
vec &operator=(const T &rhs)
requires(std::convertible_to<T, DataT>)
{
for(int i = 0; i < NumElements; ++i) { m_elems[i] = rhs; }
return *this;
}
Expand Down Expand Up @@ -755,15 +760,17 @@ class alignas(detail::vec_alignment_v<DataT, NumElements>) vec {
for(int i = 0; i < NumElements; ++i) { result.m_elems[i] = lhs.m_elems[i] op rhs.m_elems[i]; } \
return result; \
} \
friend vec operator op(const vec &lhs, const DataT &rhs) \
requires(enable_if) \
template<typename T> \
friend vec operator op(const vec &lhs, const T &rhs) \
requires(enable_if && std::convertible_to<T, DataT>) \
{ \
vec result; \
for(int i = 0; i < NumElements; ++i) { result.m_elems[i] = lhs.m_elems[i] op rhs; } \
return result; \
} \
friend vec operator op(const DataT &lhs, const vec &rhs) \
requires(enable_if) \
template<typename T> \
friend vec operator op(const T &lhs, const vec &rhs) \
requires(enable_if && std::convertible_to<T, DataT>) \
{ \
vec result; \
for(int i = 0; i < NumElements; ++i) { result.m_elems[i] = lhs op rhs.m_elems[i]; } \
Expand Down Expand Up @@ -797,8 +804,9 @@ class alignas(detail::vec_alignment_v<DataT, NumElements>) vec {
for(int i = 0; i < NumElements; ++i) { lhs.m_elems[i] op rhs.m_elems[rhs.indices[i]]; } \
return lhs; \
} \
friend vec &operator op(vec & lhs, const DataT & rhs) \
requires(enable_if) \
template<typename T> \
friend vec &operator op(vec & lhs, const T & rhs) \
requires(enable_if && std::convertible_to<T, DataT>) \
{ \
for(int i = 0; i < NumElements; ++i) { lhs.m_elems[i] op rhs; } \
return lhs; \
Expand Down Expand Up @@ -866,12 +874,18 @@ class alignas(detail::vec_alignment_v<DataT, NumElements>) vec {
for(int i = 0; i < NumElements; ++i) { result.m_elems[i] = lhs.m_elems[i] op rhs.m_elems[i]; } \
return result; \
} \
friend vec<decltype(DataT {} op DataT{}), NumElements> operator op(const vec & lhs, const DataT & rhs) { \
template<typename T> \
friend vec<decltype(DataT {} op DataT{}), NumElements> operator op(const vec & lhs, const T & rhs) \
requires(std::convertible_to<T, DataT>) \
{ \
vec<decltype(DataT {} op DataT{}), NumElements> result; \
for(int i = 0; i < NumElements; ++i) { result.m_elems[i] = lhs.m_elems[i] op rhs; } \
return result; \
} \
friend vec<decltype(DataT {} op DataT{}), NumElements> operator op(const DataT & lhs, const vec & rhs) { \
template<typename T> \
friend vec<decltype(DataT {} op DataT{}), NumElements> operator op(const T & lhs, const vec & rhs) \
requires(std::convertible_to<T, DataT>) \
{ \
vec<decltype(DataT {} op DataT{}), NumElements> result; \
for(int i = 0; i < NumElements; ++i) { result.m_elems[i] = lhs op rhs.m_elems[i]; } \
return result; \
Expand Down

0 comments on commit 98dc3b6

Please sign in to comment.