diff --git a/glm/detail/simd_constexpr/simd_helpers.inl b/glm/detail/simd_constexpr/simd_helpers.inl index 3728dabe..b6b6e2b6 100644 --- a/glm/detail/simd_constexpr/simd_helpers.inl +++ b/glm/detail/simd_constexpr/simd_helpers.inl @@ -45,7 +45,7 @@ namespace glm::detail return gcc_vec_to_data(converted); } - template requires (Lx != L && Lx < L) + template requires (Lx != L) static inline auto __attribute__((always_inline)) simd_ctor(::glm::vec v) { using OurSizeTheirType = GccVec; @@ -58,7 +58,7 @@ namespace glm::detail gcc_vec_t converted = __builtin_convertvector(oExpanded, gcc_vec_t); return gcc_vec_to_data(converted); } - + template static consteval bool isLengthOfVector() { return sizeof...(A) == L; diff --git a/glm/detail/simd_constexpr/vec.hpp b/glm/detail/simd_constexpr/vec.hpp index 5e526472..9c3b21aa 100644 --- a/glm/detail/simd_constexpr/vec.hpp +++ b/glm/detail/simd_constexpr/vec.hpp @@ -141,7 +141,8 @@ namespace glm using detail::ElementCollection::q; using SimdHlp = detail::SimdHelpers; - using DataArray = VecDataArray; + static constexpr length_t data_len = (Q == aligned && L == 3) ? 4 : L; + using DataArray = VecDataArray; using data_t = typename detail::storage::value>::type; // -- Implementation detail -- @@ -259,7 +260,7 @@ namespace glm template static constexpr auto ctor_scalar(ScalarGetter scalar) { if (std::is_constant_evaluated()) { - DataArray a; + DataArray a{}; for (length_t i = 0; i < L; i++) { a.p[i]=scalar(); } @@ -277,7 +278,7 @@ namespace glm constexpr length_t vL = v.length(); using ArrX = VecDataArray; ArrX ax = std::bit_cast(v.data); - for (length_t i = 0; i < v.length(); i++) { + for (length_t i = 0; i < std::min(L, v.length()); i++) { a.p[i] = (T)ax.p[i]; } @@ -323,9 +324,11 @@ namespace glm template requires (Lx == 1 && NotVec1) constexpr vec(vec v) : EC{.data= [d=std::bit_cast>(v.data)](){ auto s = [scalar=d.p[0]](){ return scalar; }; return ctor_scalar(s); }() } {} - template requires (L == 1 || Lx != 1) + template requires (Lx != 1) constexpr vec(vec v) : EC{.data= [v](){ auto vv = [v](){ return v; }; return ctor(vv); }() } {} + //template requires (Lx != 1) + constexpr vec(__m128 d) : EC{ .data = std::bit_cast>(d) } {} template requires (sizeof...(Scalar) == L) constexpr vec(Scalar... scalar) : EC @@ -375,23 +378,13 @@ namespace glm return std::bit_cast(destArr); }() } {} - - // -- Unary arithmetic operators -- - template - inline GLM_CONSTEXPR vec operator=(vecconst& v) - { - *this = vec(v); - return *this; - } - + inline GLM_CONSTEXPR vec& operator+=(arithmetic auto scalar) { if constexpr (L < 3) { this->data += scalar; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { x+scalar, y+scalar, z+scalar }); } else return (*this = detail::compute_vec_add::value>::call(*this, vec(scalar))); } @@ -402,8 +395,6 @@ namespace glm if constexpr (L < 3) { this->data += v.data; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { x+v.x, y+v.x, z+v.x }); } else return (*this = detail::compute_vec_add::value>::call(*this, vec(v.x))); } @@ -414,11 +405,6 @@ namespace glm if constexpr (L < 3) { this->data += v.data; return *this; - } else if constexpr (L == 3) { - x+=v.x; - y+=v.y; - z+=v.z; - return *this; } else return (*this = detail::compute_vec_add::value>::call(*this, vec(v))); } @@ -428,11 +414,6 @@ namespace glm if constexpr (L < 3) { this->data -= scalar; return *this; - } else if constexpr (L == 3) { - x-=scalar; - y-=scalar; - z-=scalar; - return *this; } else return (*this = detail::compute_vec_sub::value>::call(*this, vec(scalar))); } @@ -443,8 +424,6 @@ namespace glm if constexpr (L < 3) { this->data -= v.data; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { vec<2, T, Q>(x, y)-v.x, z-v.x }); } else return (*this = detail::compute_vec_sub::value>::call(*this, vec(v.x))); } @@ -455,11 +434,6 @@ namespace glm if constexpr (L < 3) { this->data -= v.data; return *this; - } else if constexpr (L == 3) { - x-=v.x; - y-=v.y; - z-=v.z; - return *this; } else return (*this = detail::compute_vec_sub::value>::call(*this, vec(v))); } @@ -469,8 +443,6 @@ namespace glm if constexpr (L < 3) { this->data *= scalar; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { x*scalar, y*scalar, z*scalar }); } else return (*this = detail::compute_vec_mul::value>::call(*this, vec(scalar))); } @@ -481,8 +453,6 @@ namespace glm if constexpr (L < 3) { this->data *= v.data; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { x*v.x, y*v.x, z*v.x }); } else return (*this = detail::compute_vec_mul::value>::call(*this, vec(v.x))); } @@ -493,11 +463,6 @@ namespace glm if constexpr (L < 3) { this->data *= v.data; return *this; - } else if constexpr (L == 3) { - x*=v.x; - y*=v.y; - z*=v.z; - return *this; } else return (*this = detail::compute_vec_mul::value>::call(*this, vec(v))); } @@ -507,8 +472,6 @@ namespace glm if constexpr (L < 3) { this->data /= scalar; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { x/scalar, y/scalar, z/scalar }); } else return (*this = detail::compute_vec_div::value>::call(*this, vec(scalar))); } @@ -519,8 +482,6 @@ namespace glm if constexpr (L < 3) { this->data /= v.data; return *this; - } else if constexpr (L == 3) { - return (*this = vec<3, T, Q> { x/v.x, y/v.x, z/v.x }); } else return (*this = detail::compute_vec_div::value>::call(*this, vec(v.x))); } @@ -531,11 +492,6 @@ namespace glm if constexpr (L < 3) { this->data /= v.data; return *this; - } else if (L == 3) { - x/=v.x; - y/=v.y; - z/=v.z; - return *this; } else return (*this = detail::compute_vec_div::value>::call(*this, vec(v))); }