@@ -59,8 +59,8 @@ namespace vamp
5959 inline static constexpr std::size_t num_rows = Sig::num_rows;
6060 using DataT = typename Sig::DataT;
6161
62- inline constexpr auto
63- to_array () const noexcept -> std::array<typename S::ScalarT, num_scalars_rounded>
62+ inline constexpr auto to_array () const noexcept
63+ -> std::array<typename S::ScalarT, num_scalars_rounded>
6464 {
6565 alignas (S::Alignment) std::array<typename S::ScalarT, num_scalars_rounded> result = {};
6666 to_array (result);
@@ -718,9 +718,10 @@ namespace vamp
718718 return S::template constant<0 >(s);
719719 }
720720
721+ template <bool is_aligned = true >
721722 inline constexpr void pack (const typename S::ScalarT *const scalar_data) noexcept
722723 {
723- load_vector (scalar_data, std::make_index_sequence<num_vectors>());
724+ load_vector<is_aligned> (scalar_data, std::make_index_sequence<num_vectors>());
724725 }
725726
726727 template <auto fn, std::size_t stride = 1 , std::size_t ... I>
@@ -737,13 +738,21 @@ namespace vamp
737738 (..., fn (base + I * stride, std::get<I>(data)));
738739 }
739740
740- template <std::size_t ... I>
741+ template <bool is_aligned, std::size_t ... I>
741742 inline constexpr void
742743 load_vector (const typename S::ScalarT *const scalar_array, std::index_sequence<I...>) noexcept
743744 {
744745 // TODO: This might segfault if we had to over-allocate vectors and the scalar data isn't
745746 // full for the over-allocated size
746- (..., (std::get<I>(d ()->data ) = S::template load<0 >(scalar_array + I * S::VectorWidth)));
747+ if constexpr (is_aligned)
748+ {
749+ (..., (std::get<I>(d ()->data ) = S::template load<0 >(scalar_array + I * S::VectorWidth)));
750+ }
751+ else
752+ {
753+ (...,
754+ (std::get<I>(d ()->data ) = S::template load_unaligned<0 >(scalar_array + I * S::VectorWidth)));
755+ }
747756 }
748757
749758 template <std::size_t ... I>
@@ -815,6 +824,20 @@ namespace vamp
815824 {
816825 }
817826
827+ // TODO: Enable unaligned load for other constructors too
828+ constexpr Vector (const typename S::ScalarT *const scalar_data, bool is_aligned) noexcept
829+ {
830+ // NOTE: assumes that scalar_data is a multiple of VectorWidth of valid data
831+ if (is_aligned)
832+ {
833+ Interface::pack (scalar_data);
834+ }
835+ else
836+ {
837+ Interface::pack<false >(scalar_data);
838+ }
839+ }
840+
818841 constexpr Vector (const typename S::ScalarT *const scalar_data) noexcept
819842 {
820843 // NOTE: assumes that scalar_data is a multiple of VectorWidth of valid data
0 commit comments