From 7144171b20361fe3991121b0af17232e3e1f2d1d Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:24:12 -0400 Subject: [PATCH] simd constexpr vec: more improvement --- glm/detail/simd_constexpr/element.hpp | 14 +++++++------- glm/detail/simd_constexpr/simd_helpers.inl | 2 +- glm/detail/simd_constexpr/vec.hpp | 20 +++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/glm/detail/simd_constexpr/element.hpp b/glm/detail/simd_constexpr/element.hpp index 4a0483f1..5bfa8e6a 100644 --- a/glm/detail/simd_constexpr/element.hpp +++ b/glm/detail/simd_constexpr/element.hpp @@ -3,19 +3,19 @@ namespace glm::detail { consteval bool NotEmpty(length_t I, length_t L) { return I <= L; } struct Empty {}; - struct RowTwo { + struct GLM_TRIVIAL RowTwo { [[no_unique_address]] Empty y; [[no_unique_address]] Empty g; [[no_unique_address]] Empty t; }; - struct RowThree { + struct GLM_TRIVIAL RowThree { [[no_unique_address]] Empty z; [[no_unique_address]] Empty b; [[no_unique_address]] Empty p; }; - struct RowFour { + struct GLM_TRIVIAL RowFour { [[no_unique_address]] Empty w; [[no_unique_address]] Empty a; [[no_unique_address]] Empty q; }; template struct ElementCollection; template - struct ElementCollection { + struct GLM_TRIVIAL ElementCollection { using data_t = typename detail::storage<4, T, detail::is_aligned::value>::type; union { @@ -31,7 +31,7 @@ namespace glm::detail template - struct ElementCollection : RowFour { + struct GLM_TRIVIAL ElementCollection : RowFour { using data_t = typename detail::storage<3, T, detail::is_aligned::value>::type; using RowFour::w; using RowFour::a; @@ -47,7 +47,7 @@ namespace glm::detail }; }; template - struct ElementCollection : RowThree, RowFour { + struct GLM_TRIVIAL ElementCollection : RowThree, RowFour { using data_t = typename detail::storage<2, T, detail::is_aligned::value>::type; using RowThree::z; using RowThree::b; @@ -65,7 +65,7 @@ namespace glm::detail }; }; template - struct ElementCollection : RowTwo, RowThree, RowFour { + struct GLM_TRIVIAL ElementCollection : RowTwo, RowThree, RowFour { using data_t = typename detail::storage<1, T, detail::is_aligned::value>::type; using RowTwo::y; using RowTwo::g; diff --git a/glm/detail/simd_constexpr/simd_helpers.inl b/glm/detail/simd_constexpr/simd_helpers.inl index 3652cc50..3728dabe 100644 --- a/glm/detail/simd_constexpr/simd_helpers.inl +++ b/glm/detail/simd_constexpr/simd_helpers.inl @@ -69,7 +69,7 @@ namespace glm::detail { //assuming that number of scalars is always the same as the length of the to-be-constructed vector gcc_vec_t v; - std::array pack{scalars...}; + std::array pack{static_cast(scalars)...}; for (int i = 0; i != sizeof...(scalars); i++ ) { v[i] = pack[i]; pack[i].T::~T(); diff --git a/glm/detail/simd_constexpr/vec.hpp b/glm/detail/simd_constexpr/vec.hpp index df638510..65f420b8 100644 --- a/glm/detail/simd_constexpr/vec.hpp +++ b/glm/detail/simd_constexpr/vec.hpp @@ -16,6 +16,11 @@ #include namespace glm { +#ifdef __clang__ +#define GLM_TRIVIAL __attribute__((trivial_abi)) +#else +#define GLM_TRIVIAL +#endif template concept NotVec1 = !std::is_same_v, std::integral_constant>; template @@ -119,7 +124,7 @@ namespace glm template using EC = detail::ElementCollection; template - struct vec : detail::ElementCollection + struct GLM_TRIVIAL vec : detail::ElementCollection { // -- Data -- using detail::ElementCollection::x; @@ -282,7 +287,7 @@ namespace glm } } template - using RetArr = T[len]; + using RetArr = std::array; template static constexpr length_t ctor_mixed_constexpr_single_get_length() @@ -353,19 +358,16 @@ namespace glm const auto params = std::tuple{vecOrScalar...}; const auto arr = ctor_mixed_constexpr_single(std::get<0>(params)); - if (arr) [[likely]] - std::memcpy(aa.a.p.begin()+i, arr, sizeof(T)*lengths[0]); + std::ranges::copy(arr.cbegin(), aa.a.p.begin()+i, aa.a.p.begin()+i + sizeof(T)*lengths[0]); constexpr auto i2 = i + lengths[0]; if constexpr (sizeof...(VecOrScalar) > 1) { const auto arr2 = ctor_mixed_constexpr_single(std::get<1>(params)); - if (arr2) [[likely]] - std::memcpy(aa.a.p.begin()+i2, arr2, sizeof(T)*lengths[1]); + std::ranges::copy(arr2.cbegin(), aa.a.p.begin()+i2, aa.a.p.begin()+i2 + sizeof(T)*lengths[1]); constexpr auto i3 = i2 + lengths[1]; if constexpr (sizeof...(VecOrScalar) > 2) { const auto arr3 = ctor_mixed_constexpr_single(std::get<2>(params)); - if (arr3) [[likely]] - std::memcpy(aa.a.p.begin()+i3, arr3, sizeof(T)*lengths[2]); + std::ranges::copy(arr3.cbegin(), aa.a.p.begin()+i3, aa.a.p.begin()+i3 + sizeof(T)*lengths[2]); } } @@ -460,7 +462,7 @@ namespace glm } template - inline GLM_CONSTEXPR vec & operator*=(vec const& __restrict__ v) __restrict__ + inline GLM_CONSTEXPR vec & operator*=(vec const& __restrict__ v) { if constexpr (L < 3) { this->data *= v.data;