@@ -9,47 +9,53 @@ namespace glm::detail
99 using FirstTx = Tx0;
1010 };
1111 template <length_t Lx, typename Tx, qualifier Qx>
12- using PaddedVec = PaddedGccVec<Lx, Tx, Qx, detail::BVecNeedsPadding <Lx, Tx, Qx>()> ;
13- using gcc_vec_t = PaddedVec <L, T, Q>::GccV ;
12+ using GccVec = typename detail::GccVExt <Lx, Tx, Qx>::GccV ;
13+ using gcc_vec_t = GccVec <L, T, Q>;
1414 using data_t = typename detail::storage<L, T, detail::is_aligned<Q>::value>::type;
1515
16- static inline auto __attribute__ ((always_inline)) gcc_vec_to_data(PaddedVec<L, T, Q> v) {
17- if constexpr (L == 3 && !BIsAlignedQ<Q>()) {
16+ static inline auto __attribute__ ((always_inline)) gcc_vec_to_data(auto v) {
17+ static constexpr auto size = std::min (sizeof (v), sizeof (data_t ));
18+ static constexpr auto biggerSize = std::max (sizeof (v), sizeof (data_t ));
19+ if constexpr (size == biggerSize) {
20+ return std::bit_cast<data_t >(v);
21+ } else {
1822 data_t d;
19- std::memcpy (&d, &v, sizeof (d) );
23+ std::memcpy (&d, &v, size );
2024 return d;
21- } else {
22- return std::bit_cast<data_t >(v);
2325 }
2426 }
2527
2628 static inline auto __attribute__ ((always_inline)) simd_ctor_scalar(arithmetic auto scalar) {
27- PaddedVec<L, T, Q> v = {};
28- v.gcc_vec = v.gcc_vec + ( (T)scalar );
29+ gcc_vec_t v = gcc_vec_t {} + ( (T)scalar );
30+ using Tx = decltype (scalar);
31+ scalar.Tx ::~Tx ();
2932 return gcc_vec_to_data (v);
3033 }
3134
3235 template <length_t Lx, typename Tx, qualifier Qx> requires (Lx == L)
3336 static inline auto __attribute__((always_inline)) simd_ctor(::glm::vec<Lx, Tx, Qx> v)
3437 {
35- using OtherPaddedVec = PaddedVec<Lx, Tx, Qx>;
36- OtherPaddedVec o = std::bit_cast<OtherPaddedVec>(v.data );
37- PaddedVec<L, T, Q> converted = {.gcc_vec =__builtin_convertvector (o.gcc_vec , gcc_vec_t )};
38+ using OtherVec = GccVec<Lx, Tx, Qx>;
39+ OtherVec o;
40+ static constexpr auto size = std::min (sizeof (v.data ), sizeof (o));
41+ std::memcpy (&o, &(v.data ), size);
42+ using o_vec_t = decltype (v);
43+ v.o_vec_t ::~o_vec_t ();
44+ gcc_vec_t converted = __builtin_convertvector (o, gcc_vec_t );
3845 return gcc_vec_to_data (converted);
3946 }
4047
4148 template <length_t Lx, typename Tx, qualifier Qx> requires (Lx != L && Lx < L)
4249 static inline auto __attribute__((always_inline)) simd_ctor(::glm::vec<Lx, Tx, Qx> v)
4350 {
44- using OtherPaddedVec = PaddedVec<Lx, Tx, Qx>;
45- using OurSizeTheirType = PaddedVec<L, Tx, Qx>;
46- OtherPaddedVec o = std::bit_cast<OtherPaddedVec>(v.data );
47- OurSizeTheirType oExpanded = {};
48- for (length_t i = 0 ; i < Lx; i++) {
49- oExpanded.gcc_vec [i] = o.gcc_vec [i];
50- }
51+ using OurSizeTheirType = GccVec<L, Tx, Qx>;
52+ static constexpr auto size = std::min (sizeof (OurSizeTheirType), sizeof (v.data ));
53+ OurSizeTheirType oExpanded;
54+ std::memcpy (&oExpanded, &(v.data ), size);
55+ using o_vec_t = decltype (v);
56+ v.o_vec_t ::~o_vec_t ();
5157
52- PaddedVec<L, T, Q> converted = {. gcc_vec = __builtin_convertvector (oExpanded. gcc_vec , gcc_vec_t )} ;
58+ gcc_vec_t converted = __builtin_convertvector (oExpanded, gcc_vec_t );
5359 return gcc_vec_to_data (converted);
5460 }
5561
@@ -62,11 +68,13 @@ namespace glm::detail
6268 static inline auto __attribute__ ((always_inline)) simd_ctor_multi_scalars(A... scalars) requires ( isLengthOfVector<A...>() && SameArithmeticTypes<A...>())
6369 {
6470 // assuming that number of scalars is always the same as the length of the to-be-constructed vector
65- using Tx = typename GetFirstType<A...>::FirstTx;
66- using OtherPaddedVec = PaddedVec<L, Tx, Q>;
67- typename OtherPaddedVec::GccV o = {Tx (scalars)...};
68- PaddedVec<L, T, Q> converted = {.gcc_vec =__builtin_convertvector (o, gcc_vec_t )};
69- return gcc_vec_to_data (converted);
71+ gcc_vec_t v;
72+ std::array<T, sizeof ...(scalars)> pack{scalars...};
73+ for (int i = 0 ; i != sizeof ...(scalars); i++ ) {
74+ v[i] = pack[i];
75+ pack[i].T ::~T ();
76+ }
77+ return gcc_vec_to_data (v);
7078 }
7179 };
7280}
0 commit comments