diff --git a/include/simdify/impl/array_of_vectors.hpp b/include/simdify/impl/array_of_vectors.hpp index 2570f44..268a7e9 100644 --- a/include/simdify/impl/array_of_vectors.hpp +++ b/include/simdify/impl/array_of_vectors.hpp @@ -22,7 +22,7 @@ namespace simd { static_assert(std::is_trivial::value, "array_of_vectors_impl: e_t not trivial"); using value_type = named_array; - using value_type_vector = named_array; + using value_type_vector = named_array, Ids...>; using reference = named_array>, Ids...>; using const_reference = named_array>, Ids...>; using reference_vector = value_type_vector&; @@ -112,29 +112,6 @@ namespace simd { SIMDIFY_CONTAINERS_COMMON_POP_BACK("structure_of_arrays"); - template - struct vector_iterator : std::iterator { - vector_iterator(const self_t& self, std::size_t idx) : - m_ptr(self.data_as_value_vector_type_ptr() + (idx / W)) {} - - vector_iterator& operator=(const vector_iterator& rhs) = default; - - vector_iterator& operator++() { ++m_ptr; return *this; } - vector_iterator& operator--() { --m_ptr; return *this; } - vector_iterator& operator+=(std::ptrdiff_t add) { m_ptr += add; return *this; } - std::ptrdiff_t operator-(const vector_iterator& rhs) { return m_ptr - rhs.m_ptr; } - bool operator<(const vector_iterator& rhs) const { return m_ptr < rhs.m_ptr; } - bool operator<=(const vector_iterator& rhs) const { return m_ptr <= rhs.m_ptr; } - bool operator==(const vector_iterator& rhs) const { return m_ptr == rhs.m_ptr; } - Val& operator*() { return *m_ptr; } - Val* operator->() { return m_ptr; } - - SIMDIFY_CONTAINERS_COMMON_ITERATOR_FACILITIES(vector_iterator); - - private: - Val* m_ptr; - }; - template struct scalar_iterator : std::iterator, Ref> { scalar_iterator(const self_t& self, std::size_t idx) { @@ -194,11 +171,25 @@ namespace simd { using iterator = scalar_iterator; using const_iterator = scalar_iterator; - using iterator_vector = vector_iterator; - using const_iterator_vector = vector_iterator; + using iterator_vector = value_type_vector*; + using const_iterator_vector = const value_type_vector*; + + SIMDIFY_INL iterator_vector begin_overspan() { return data_as_value_vector_type_ptr(); } + SIMDIFY_INL iterator_vector end_overspan() { return data_as_value_vector_type_ptr() + (size_overspan() / W); } + SIMDIFY_INL iterator_vector begin_body() { return data_as_value_vector_type_ptr(); } + SIMDIFY_INL iterator_vector end_body() { return data_as_value_vector_type_ptr() + (size_body() / W); } + + SIMDIFY_INL const_iterator_vector begin_overspan() const { return cbegin_overspan(); } + SIMDIFY_INL const_iterator_vector end_overspan() const { return cend_overspan(); } + SIMDIFY_INL const_iterator_vector begin_body() const { return cbegin_body(); } + SIMDIFY_INL const_iterator_vector end_body() const { return cend_body(); } + + SIMDIFY_INL const_iterator_vector cbegin_overspan() const { return data_as_value_vector_type_ptr(); } + SIMDIFY_INL const_iterator_vector cend_overspan() const { return data_as_value_vector_type_ptr() + (size_overspan() / W); } + SIMDIFY_INL const_iterator_vector cbegin_body() const { return data_as_value_vector_type_ptr(); } + SIMDIFY_INL const_iterator_vector cend_body() const { return data_as_value_vector_type_ptr() + (size_body() / W); } SIMDIFY_CONTAINERS_COMMON_ITERATION_SCALAR; - SIMDIFY_CONTAINERS_COMMON_ITERATION_VECTOR; private: value_type_vector* data_as_value_vector_type_ptr() const { diff --git a/include/simdify/impl/storage.hpp b/include/simdify/impl/storage.hpp index 3a217e4..020c89b 100644 --- a/include/simdify/impl/storage.hpp +++ b/include/simdify/impl/storage.hpp @@ -108,6 +108,8 @@ namespace simd { template struct storage::value>::type> { using stored_t = E_t; + using e_t = E_t; + using data_t = E_t; SIMDIFY_INL constexpr storage() = default; SIMDIFY_INL constexpr storage(const storage&) = default; @@ -122,12 +124,14 @@ namespace simd { SIMDIFY_INL E_t* data() { return &m_data; } SIMDIFY_INL const E_t* data() const { return &m_data; } + SIMDIFY_INL e_t& operator[](std::size_t i) { return m_data; } + SIMDIFY_INL const e_t& operator[](std::size_t i) const { return m_data; } // implicit conversion to E_t SIMDIFY_INL operator E_t() const { return m_data; } // data - E_t m_data; + data_t m_data; }; // @@ -190,6 +194,7 @@ namespace simd { template struct reference { using referred_t = typename Storage::stored_t; + using e_t = typename Storage::e_t; SIMDIFY_INL constexpr reference() = default; SIMDIFY_INL constexpr reference(const reference&) = default; @@ -221,6 +226,8 @@ namespace simd { SIMDIFY_INL Storage* reset(void* ptr) { m_data = static_cast(ptr); return m_data; } SIMDIFY_INL Storage*& ptr() { return m_data; } SIMDIFY_INL Storage* ptr() const { return m_data; } + SIMDIFY_INL e_t& operator[](std::size_t i) { return (*m_data)[i]; } + SIMDIFY_INL const e_t& operator[](std::size_t i) const { return (*m_data)[i]; } SIMDIFY_INL void swap(reference& rhs) { using std::swap; @@ -245,6 +252,7 @@ namespace simd { template struct const_reference { using referred_t = typename Storage::stored_t; + using e_t = typename Storage::e_t; SIMDIFY_INL constexpr const_reference() = default; SIMDIFY_INL constexpr const_reference(const const_reference&) = default; @@ -267,6 +275,7 @@ namespace simd { SIMDIFY_INL const Storage* reset(const void* ptr) { m_data = static_cast(ptr); return m_data; } SIMDIFY_INL const Storage*& ptr() { return m_data; } SIMDIFY_INL const Storage* ptr() const { return m_data; } + SIMDIFY_INL const e_t& operator[](std::size_t i) const { return (*m_data)[i]; } // implicit conversion to const referred_t SIMDIFY_INL operator const referred_t() const { return referred_t(*m_data); }