From bc5c6727f49251771be6ac4aa402d9c4430cb8c0 Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:30:57 -0400 Subject: [PATCH] simd constexpr vec: fix errors when building w/ gcc --- glm/detail/simd_constexpr/simd_helpers.inl | 19 +++++++++++++++---- glm/detail/simd_constexpr/vec.hpp | 20 +++++++++++--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/glm/detail/simd_constexpr/simd_helpers.inl b/glm/detail/simd_constexpr/simd_helpers.inl index eb2a2710..083d64b7 100644 --- a/glm/detail/simd_constexpr/simd_helpers.inl +++ b/glm/detail/simd_constexpr/simd_helpers.inl @@ -12,10 +12,21 @@ namespace glm::detail using PaddedVec = PaddedGccVec()>; using gcc_vec_t = PaddedVec::GccV; using data_t = typename detail::storage::value>::type; + + static inline auto gcc_vec_to_data(PaddedVec v) { + if constexpr (L == 3 && !BIsAlignedQ()) { + data_t d; + std::memcpy(&d, &v, sizeof(d)); + return d; + } else { + return std::bit_cast(v); + } + } + static inline auto simd_ctor_scalar(arithmetic auto scalar) { PaddedVec v = {}; v.gcc_vec = v.gcc_vec + ( (T)scalar ); - return std::bit_cast(v); + return gcc_vec_to_data(v); } template requires (Lx == L) @@ -24,7 +35,7 @@ namespace glm::detail using OtherPaddedVec = PaddedVec; OtherPaddedVec o = std::bit_cast(v.data); PaddedVec converted = {.gcc_vec=__builtin_convertvector(o.gcc_vec, gcc_vec_t)}; - return std::bit_cast(converted); + return gcc_vec_to_data(converted); } template requires (Lx != L && Lx < L) @@ -39,7 +50,7 @@ namespace glm::detail } PaddedVec converted = {.gcc_vec=__builtin_convertvector(oExpanded.gcc_vec, gcc_vec_t)}; - return std::bit_cast(converted); + return gcc_vec_to_data(converted); } template @@ -54,7 +65,7 @@ namespace glm::detail using OtherPaddedVec = PaddedVec::FirstTx, Q>; OtherPaddedVec o = {.gcc_vec={scalars...}}; PaddedVec converted = {.gcc_vec=__builtin_convertvector(o.gcc_vec, gcc_vec_t)}; - return std::bit_cast(converted); + return gcc_vec_to_data(converted); } }; } \ No newline at end of file diff --git a/glm/detail/simd_constexpr/vec.hpp b/glm/detail/simd_constexpr/vec.hpp index 2cde999b..27bc45fc 100644 --- a/glm/detail/simd_constexpr/vec.hpp +++ b/glm/detail/simd_constexpr/vec.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace glm { template @@ -37,35 +38,36 @@ namespace glm namespace detail { template - using ArrT = T[L]; + using _ArrT = T[L]; template using _data_t = typename detail::storage::value>::type; template - using GccV = T __attribute__(( vector_size(sizeof(T)*L), aligned(alignof(_data_t)) )); - + struct GccVExt { + typedef T GccV __attribute__(( vector_size(sizeof(T)*L), aligned(alignof(_data_t)) )); + }; template consteval bool BDataNeedsPadding() { - return sizeof(_data_t) > sizeof(ArrT); + return sizeof(_data_t) > sizeof(_ArrT); } template consteval bool BVecNeedsPadding() { - return sizeof(_data_t) > sizeof(GccV); + return sizeof(_data_t) > sizeof(typename GccVExt::GccV); } template struct VecDataArray; template struct VecDataArray { - using ArrT = ArrT; + using ArrT = _ArrT; using data_t = _data_t; ArrT p; std::byte padding[sizeof(data_t) - sizeof(ArrT)]; }; template struct VecDataArray { - using ArrT = ArrT; + using ArrT = _ArrT; ArrT p; }; @@ -74,7 +76,7 @@ namespace glm template struct PaddedGccVec { - using GccV = GccV; + using GccV = typename GccVExt::GccV; using data_t = _data_t; GccV gcc_vec; std::byte padding[sizeof(data_t) - sizeof(GccV)]; @@ -82,7 +84,7 @@ namespace glm template struct PaddedGccVec { - using GccV = GccV; + using GccV = typename GccVExt::GccV; GccV gcc_vec; }; }