From 8e86332b6b6d1379bcf32508b4b1cc6f67a44b47 Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:40:08 -0400 Subject: [PATCH] simd constexpr vec: fix all the compile errors --- glm/detail/simd_constexpr/element.hpp | 77 +++---- glm/detail/simd_constexpr/simd_helpers.inl | 33 +-- glm/detail/simd_constexpr/vec.hpp | 240 +++++++++++---------- glm/detail/type_vec1.hpp | 3 +- glm/detail/type_vec2.hpp | 3 +- glm/detail/type_vec3.hpp | 4 +- glm/detail/type_vec4.hpp | 4 +- glm/detail/type_vec4.inl | 4 +- glm/glm.hpp | 4 + glm/matrix.hpp | 11 +- glm/simd_constexpr/vec.hpp | 2 +- 11 files changed, 208 insertions(+), 177 deletions(-) diff --git a/glm/detail/simd_constexpr/element.hpp b/glm/detail/simd_constexpr/element.hpp index 8c941a40..01908674 100644 --- a/glm/detail/simd_constexpr/element.hpp +++ b/glm/detail/simd_constexpr/element.hpp @@ -39,49 +39,49 @@ namespace glm::detail { return *this; } - constexpr decltype(auto) operator+=(auto a) requires requires (T first, decltype(rhs) r) { first + r; } + constexpr decltype(auto) operator+=(auto rhs) requires requires (T first, decltype(rhs) r) { first + r; } { return *this; } - constexpr decltype(auto) operator-=(auto a) requires requires (T first, decltype(rhs) r) { first - r; } + constexpr decltype(auto) operator-=(auto rhs) requires requires (T first, decltype(rhs) r) { first - r; } { return *this; } - constexpr decltype(auto) operator*=(auto a) requires requires (T first, decltype(rhs) r) { first * r; } + constexpr decltype(auto) operator*=(auto rhs) requires requires (T first, decltype(rhs) r) { first * r; } { return *this; } - constexpr decltype(auto) operator/=(auto a) requires requires (T first, decltype(rhs) r) { first / r; } + constexpr decltype(auto) operator/=(auto rhs) requires requires (T first, decltype(rhs) r) { first / r; } { return *this; } - constexpr decltype(auto) operator%=(auto a) requires requires (T first, decltype(rhs) r) { first % r; } + constexpr decltype(auto) operator%=(auto rhs) requires requires (T first, decltype(rhs) r) { first % r; } { return *this; } - constexpr decltype(auto) operator&=(auto a) requires requires (T first, decltype(rhs) r) { first & r; } + constexpr decltype(auto) operator&=(auto rhs) requires requires (T first, decltype(rhs) r) { first & r; } { return *this; } - constexpr decltype(auto) operator|=(auto a) requires requires (T first, decltype(rhs) r) { first | r; } + constexpr decltype(auto) operator|=(auto rhs) requires requires (T first, decltype(rhs) r) { first | r; } { return *this; } - constexpr decltype(auto) operator^=(auto a) requires requires (T first, decltype(rhs) r) { first ^ r; } + constexpr decltype(auto) operator^=(auto rhs) requires requires (T first, decltype(rhs) r) { first ^ r; } { return *this; } - constexpr decltype(auto) operator<<=(auto a) requires requires (T first, decltype(rhs) r) { first << r; } + constexpr decltype(auto) operator<<=(auto rhs) requires requires (T first, decltype(rhs) r) { first << r; } { return *this; } - constexpr decltype(auto) operator>>=(auto a) requires requires (T first, decltype(rhs) r) { first >> r; } + constexpr decltype(auto) operator>>=(auto rhs) requires requires (T first, decltype(rhs) r) { first >> r; } { return *this; } @@ -141,12 +141,12 @@ namespace glm::detail return false; } - constexpr decltype(auto) operator!(auto rhs) requires requires (T first) { !first; } + constexpr decltype(auto) operator!() requires requires (T first) { !first; } { return false; } - constexpr decltype(auto) operator bool() requires requires (T first) { !!first; } + constexpr operator bool() requires requires (T first) { !!first; } { return false; } @@ -161,7 +161,7 @@ namespace glm::detail return 0; } - constexpr decltype(auto) operator&(); requires requires (T first) { &first; } + constexpr decltype(auto) operator&() requires requires (T first) { &first; } { return nullptr; } @@ -181,6 +181,11 @@ namespace glm::detail { return t; } + + constexpr operator auto() const + { + return t; + } constexpr decltype(auto) operator=(auto thing) { t=(T)thing; @@ -219,60 +224,60 @@ namespace glm::detail operator--(); // prefix decrement return old; // return old value } - constexpr decltype(auto) operator+=(auto a) requires requires (T first, decltype(rhs) r) { first + r; } + constexpr decltype(auto) operator+=(auto rhs) requires requires (T first, decltype(rhs) r) { first + r; } { - t+=a; + t+=rhs; return *this; } - constexpr decltype(auto) operator-=(auto a) requires requires (T first, decltype(rhs) r) { first - r; } + constexpr decltype(auto) operator-=(auto rhs) requires requires (T first, decltype(rhs) r) { first - r; } { - t-=a; + t-=rhs; return *this; } - constexpr decltype(auto) operator*=(auto a) requires requires (T first, decltype(rhs) r) { first * r; } + constexpr decltype(auto) operator*=(auto rhs) requires requires (T first, decltype(rhs) r) { first * r; } { - t*=a; + t*=rhs; return *this; } - constexpr decltype(auto) operator/=(auto a) requires requires (T first, decltype(rhs) r) { first / r; } + constexpr decltype(auto) operator/=(auto rhs) requires requires (T first, decltype(rhs) r) { first / r; } { - t/=a; + t/=rhs; return *this; } - constexpr decltype(auto) operator%=(auto a) requires requires (T first, decltype(rhs) r) { first % r; } + constexpr decltype(auto) operator%=(auto rhs) requires requires (T first, decltype(rhs) r) { first % r; } { - t%=a; + t%=rhs; return *this; } - constexpr decltype(auto) operator&=(auto a) requires requires (T first, decltype(rhs) r) { first & r; } + constexpr decltype(auto) operator&=(auto rhs) requires requires (T first, decltype(rhs) r) { first & r; } { - t&=a; + t&=rhs; return *this; } - constexpr decltype(auto) operator|=(auto a) requires requires (T first, decltype(rhs) r) { first | r; } + constexpr decltype(auto) operator|=(auto rhs) requires requires (T first, decltype(rhs) r) { first | r; } { - t|=a; + t|=rhs; return *this; } - constexpr decltype(auto) operator^=(auto a) requires requires (T first, decltype(rhs) r) { first ^ r; } + constexpr decltype(auto) operator^=(auto rhs) requires requires (T first, decltype(rhs) r) { first ^ r; } { - t^=a; + t^=rhs; return *this; } - constexpr decltype(auto) operator<<=(auto a) requires requires (T first, decltype(rhs) r) { first << r; } + constexpr decltype(auto) operator<<=(auto rhs) requires requires (T first, decltype(rhs) r) { first << r; } { - t<<=a; + t<<=rhs; return *this; } - constexpr decltype(auto) operator>>=(auto a) requires requires (T first, decltype(rhs) r) { first >> r; } + constexpr decltype(auto) operator>>=(auto rhs) requires requires (T first, decltype(rhs) r) { first >> r; } { - t>>=a; + t>>=rhs; return *this; } @@ -363,7 +368,7 @@ namespace glm::detail return !lhs.t; } - constexpr decltype(auto) operator bool() requires requires (T first) { !!first; } + constexpr operator bool() requires requires (T first) { !!first; } { auto lhs = *this; return !!lhs.t; @@ -381,9 +386,9 @@ namespace glm::detail return -lhs.t; } - constexpr decltype(auto) operator&(); requires requires (T first) { &first; } + constexpr decltype(auto) operator&() requires requires (T first) { &first; } { - return &(this->t); + return &(t); } constexpr decltype(auto) operator<=>(auto rhs) requires requires (T first, decltype(rhs) r) { first <=> r; } diff --git a/glm/detail/simd_constexpr/simd_helpers.inl b/glm/detail/simd_constexpr/simd_helpers.inl index f2ace306..eb2a2710 100644 --- a/glm/detail/simd_constexpr/simd_helpers.inl +++ b/glm/detail/simd_constexpr/simd_helpers.inl @@ -3,11 +3,17 @@ namespace glm::detail template struct SimdHelpers { - using PaddedVec = PaddedGccVec; - using gcc_vec_t = PaddedVec::GccV; + template + struct GetFirstType + { + using FirstTx = Tx0; + }; + template + using PaddedVec = PaddedGccVec()>; + using gcc_vec_t = PaddedVec::GccV; using data_t = typename detail::storage::value>::type; static inline auto simd_ctor_scalar(arithmetic auto scalar) { - PaddedVec v = {}; + PaddedVec v = {}; v.gcc_vec = v.gcc_vec + ( (T)scalar ); return std::bit_cast(v); } @@ -15,38 +21,39 @@ namespace glm::detail template requires (Lx == L) static inline auto simd_ctor(::glm::vec v) { - using OtherPaddedVec = PaddedGccVec; + using OtherPaddedVec = PaddedVec; OtherPaddedVec o = std::bit_cast(v.data); - PaddedVec converted = {.gcc_vec=__builtin_convertvector(o.gcc_vec, gcc_vec_t)}; + PaddedVec converted = {.gcc_vec=__builtin_convertvector(o.gcc_vec, gcc_vec_t)}; return std::bit_cast(converted); } template requires (Lx != L && Lx < L) static inline auto simd_ctor(::glm::vec v) { - using OtherPaddedVec = PaddedGccVec; - using OurSizeTheirType = PaddedGccVec; + using OtherPaddedVec = PaddedVec; + using OurSizeTheirType = PaddedVec; OtherPaddedVec o = std::bit_cast(v.data); OurSizeTheirType oExpanded = {}; for (length_t i = 0; i < Lx; i++) { oExpanded.gcc_vec[i] = o.gcc_vec[i]; } - PaddedVec converted = {.gcc_vec=__builtin_convertvector(oExpanded.gcc_vec, gcc_vec_t)}; + PaddedVec converted = {.gcc_vec=__builtin_convertvector(oExpanded.gcc_vec, gcc_vec_t)}; return std::bit_cast(converted); } - static consteval bool isLengthOfVector(arithmetic auto... scalars) { - return sizeof...(scalars) == L; + template + static consteval bool isLengthOfVector() { + return sizeof...(A) == L; } template - static inline auto simd_ctor_multi_scalars(A... scalars) requires ( isLengthOfVector(scalars...) && SameArithmeticTypes()) + static inline auto simd_ctor_multi_scalars(A... scalars) requires ( isLengthOfVector() && SameArithmeticTypes()) { //assuming that number of scalars is always the same as the length of the to-be-constructed vector - using OtherPaddedVec = PaddedGccVec; + using OtherPaddedVec = PaddedVec::FirstTx, Q>; OtherPaddedVec o = {.gcc_vec={scalars...}}; - PaddedVec converted = {.gcc_vec=__builtin_convertvector(o, gcc_vec_t)}; + PaddedVec converted = {.gcc_vec=__builtin_convertvector(o.gcc_vec, gcc_vec_t)}; return std::bit_cast(converted); } }; diff --git a/glm/detail/simd_constexpr/vec.hpp b/glm/detail/simd_constexpr/vec.hpp index f1324848..217d0069 100644 --- a/glm/detail/simd_constexpr/vec.hpp +++ b/glm/detail/simd_constexpr/vec.hpp @@ -31,7 +31,7 @@ namespace glm } template consteval bool NotSameArithmeticTypes() { - return ( (!(std::is_integral_v || std::floating_point_v) || ...) || !(SameArithmeticTypes()) ); + return ( (!(std::is_integral_v || std::is_floating_point_v) || ...) || !(SameArithmeticTypes()) ); } namespace detail @@ -96,6 +96,8 @@ namespace glm } #include "element.hpp" #include "simd_helpers.inl" +#include "../compute_vector_relational.hpp" +#include "../compute_vector_decl.hpp" namespace glm { template @@ -117,26 +119,24 @@ namespace glm }; // -- Component Access -- - static constexpr length_t length(){ return L; } + static consteval length_t length(){ return L; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR decltype(auto) operator[](length_t i) + inline GLM_CONSTEXPR T& operator[](length_t i) { - if (std::is_constant_evaluated()) { - static_assert(i <= length()); - } else { - GLM_ASSERT_LENGTH(i, this->length()); + if (!std::is_constant_evaluated()) { + GLM_ASSERT_LENGTH(i, L); } - switch (i) + switch (std::max(i, length())) { default: case 0: return x; case 1: - return y; + return y.t; case 2: - return z; + return z.t; case 3: - return w; + return w.t; } } @@ -148,7 +148,7 @@ namespace glm union { struct { - union { E<1> x, r, s; }; + union { T x, r, s; }; GLM_N union { GLM_N E<2> y; GLM_N E<2> g; GLM_N E<2> t; }; GLM_N union { GLM_N E<3> z; GLM_N E<3> b; GLM_N E<3> p; }; GLM_N union { GLM_N E<4> w; GLM_N E<4> a; GLM_N E<4> q; }; @@ -205,9 +205,9 @@ namespace glm constexpr auto ctor(VecGetter vecGetter) { if (std::is_constant_evaluated()) { DataArray a = {}; - constexpr auto v = vecGetter(); + auto v = vecGetter(); constexpr length_t vL = v.length(); - using ArrX = VecDataArray; + using ArrX = VecDataArray; ArrX ax = std::bit_cast(v.data); for (length_t i = 0; i < v.length(); i++) { a.p[i] = (T)ax.p[i]; @@ -242,12 +242,13 @@ namespace glm } return var_t{RetPair{a, i}}; - } + }; - constexpr vec(arithmetic auto scalar) : data{ [scalar](){ auto s = [scalar](){ return scalar; }; return ctor_scalar(s); }() } {} + constexpr vec() : data{} {} + constexpr vec(arithmetic auto scalar) : data{ [scalar,this](){ auto s = [scalar](){ return scalar; }; return ctor_scalar(s); }() } {} template - constexpr vec(vec v) : data{ [v](){ auto vv = [v](){ return v; }; return ctor(vv); }() } {} + constexpr vec(vec v) : data{ [v, this](){ auto vv = [v](){ return v; }; return ctor(vv); }() } {} template requires (sizeof...(Scalar) == L) constexpr vec(Scalar... scalar) @@ -274,7 +275,7 @@ namespace glm length_t i = 0; using var_t = std::variant; for (auto var_vs : std::array{ vecOrScalar... } ) { - auto visitee = [i](auto&& arg) -> var_t { return ctor_mixed_constexpr_single(arg, i); }; + auto visitee = [i](auto&& arg) -> var_t { return ctor_mixed_constexpr_single.template operator()(arg, i); }; RetPair pair = std::get(std::visit(visitee, var_vs)); for (length_t j = pair.i; j < i+pair.i; j++) { a.p[j] = pair.a.p[j]; @@ -288,84 +289,84 @@ namespace glm // -- Unary arithmetic operators -- template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator=(vec v) + inline GLM_CONSTEXPR vec operator=(vec v) { *this = vec(v); return *this; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec& operator+=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec& operator+=(arithmetic auto scalar) { return (*this = detail::compute_vec_add::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator+=(vec<1, Tx, Q> v) + inline GLM_CONSTEXPR vec & operator+=(vec<1, Tx, Q> v) { return (*this = detail::compute_vec_add::value>::call(*this, vec(v.x))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator+=(vec v) + inline GLM_CONSTEXPR vec & operator+=(vec v) { - return (*this = detail::compute_vec_add::value>::call(*this, vec(v))); + return (*this = detail::compute_vec_add::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator-=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator-=(arithmetic auto scalar) { return (*this = detail::compute_vec_sub::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator-=(vec<1, Tx, Q> v) + inline GLM_CONSTEXPR vec & operator-=(vec<1, Tx, Q> v) { return (*this = detail::compute_vec_sub::value>::call(*this, vec(v.x))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator-=(vec v) + inline GLM_CONSTEXPR vec & operator-=(vec v) { return (*this = detail::compute_vec_sub::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator*=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator*=(arithmetic auto scalar) { return (*this = detail::compute_vec_mul::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator*=(vec<1, Tx, Q> v) + inline GLM_CONSTEXPR vec & operator*=(vec<1, Tx, Q> v) { return (*this = detail::compute_vec_mul::value>::call(*this, vec(v.x))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator*=(vec v) + inline GLM_CONSTEXPR vec & operator*=(vec v) { return (*this = detail::compute_vec_mul::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator/=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator/=(arithmetic auto scalar) { return (*this = detail::compute_vec_div::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator/=(vec<1, Tx, Q> v) + inline GLM_CONSTEXPR vec & operator/=(vec<1, Tx, Q> v) { return (*this = detail::compute_vec_div::value>::call(*this, vec(v.x))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator/=(vec v) + inline GLM_CONSTEXPR vec & operator/=(vec v) { return (*this = detail::compute_vec_div::value>::call(*this, vec(v))); } // -- Increment and decrement operators -- - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator++() + inline GLM_CONSTEXPR vec & operator++() { ++this->x; ++this->y; @@ -374,7 +375,7 @@ namespace glm return *this; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator--() + inline GLM_CONSTEXPR vec & operator--() { --this->x; --this->y; @@ -383,14 +384,14 @@ namespace glm return *this; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator++(int) + inline GLM_CONSTEXPR vec operator++(int) { vec Result(*this); ++*this; return Result; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator--(int) + inline GLM_CONSTEXPR vec operator--(int) { vec Result(*this); --*this; @@ -399,227 +400,227 @@ namespace glm // -- Unary bit operators -- - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator%=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator%=(arithmetic auto scalar) { return (*this = detail::compute_vec_mod::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator%=(vec<1, Tx, Q> v) + inline GLM_CONSTEXPR vec & operator%=(vec<1, Tx, Q> v) { return (*this = detail::compute_vec_mod::value>::call(*this, vec(v))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator%=(vec v) + inline GLM_CONSTEXPR vec & operator%=(vec v) { return (*this = detail::compute_vec_mod::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator&=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator&=(arithmetic auto scalar) { return (*this = detail::compute_vec_and::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator&=(vec<1, Tx, Q> v) + inline GLM_CONSTEXPR vec & operator&=(vec<1, Tx, Q> v) { return (*this = detail::compute_vec_and::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator&=(vec v) + inline GLM_CONSTEXPR vec & operator&=(vec v) { return (*this = detail::compute_vec_and::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator|=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator|=(arithmetic auto scalar) { return (*this = detail::compute_vec_or::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator|=(vec<1, Tx, Q> const& v) + inline GLM_CONSTEXPR vec & operator|=(vec<1, Tx, Q> const& v) { return (*this = detail::compute_vec_or::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator|=(vec const& v) + inline GLM_CONSTEXPR vec & operator|=(vec const& v) { return (*this = detail::compute_vec_or::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator^=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator^=(arithmetic auto scalar) { return (*this = detail::compute_vec_xor::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator^=(vec<1, Tx, Q> const& v) + inline GLM_CONSTEXPR vec & operator^=(vec<1, Tx, Q> const& v) { return (*this = detail::compute_vec_xor::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator^=(vec const& v) + inline GLM_CONSTEXPR vec & operator^=(vec const& v) { return (*this = detail::compute_vec_xor::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator<<=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator<<=(arithmetic auto scalar) { return (*this = detail::compute_vec_shift_left::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator<<=(vec<1, Tx, Q> const& v) + inline GLM_CONSTEXPR vec & operator<<=(vec<1, Tx, Q> const& v) { return (*this = detail::compute_vec_shift_left::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator<<=(vec const& v) + inline GLM_CONSTEXPR vec & operator<<=(vec const& v) { return (*this = detail::compute_vec_shift_left::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator>>=(arithmetic auto scalar) + inline GLM_CONSTEXPR vec & operator>>=(arithmetic auto scalar) { return (*this = detail::compute_vec_shift_right::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(scalar))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator>>=(vec<1, Tx, Q> const& v) + inline GLM_CONSTEXPR vec & operator>>=(vec<1, Tx, Q> const& v) { return (*this = detail::compute_vec_shift_right::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec & operator>>=(vec const& v) + inline GLM_CONSTEXPR vec & operator>>=(vec const& v) { return (*this = detail::compute_vec_shift_right::value, sizeof(T) * 8, detail::is_aligned::value>::call(*this, vec(v))); } // -- Unary constant operators -- - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator+() + inline GLM_CONSTEXPR vec operator+() { return *this; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator-() + inline GLM_CONSTEXPR vec operator-() { return vec(0) -= *this; } // -- Binary arithmetic operators -- - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator+(T scalar) + inline GLM_CONSTEXPR vec operator+(T scalar) { return vec(*this) += scalar; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator+(vec<1, T, Q> const& v2) + inline GLM_CONSTEXPR vec operator+(vec<1, T, Q> const& v2) { return vec(*this) += v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator+(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator+(T scalar, vec const& v) { return vec(v) += scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator+(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator+(vec<1, T, Q> const& v1, vec const& v2) { return vec(v2) += v1; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator+(vec v2) + inline GLM_CONSTEXPR vec operator+(vec v2) { return vec(*this) += v2; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator-(T scalar) + inline GLM_CONSTEXPR vec operator-(T scalar) { return vec(*this) -= scalar; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator-(vec<1, T, Q> const& v2) + inline GLM_CONSTEXPR vec operator-(vec<1, T, Q> const& v2) { return vec(*this) -= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator-(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator-(T scalar, vec const& v) { return vec(scalar) -= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator-(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator-(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) -= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator-(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator-(vec const& v1, vec const& v2) { return vec(v1) -= v2; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator*(T scalar) + inline GLM_CONSTEXPR vec operator*(T scalar) { return vec(*this) *= scalar; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator*(vec<1, T, Q> const& v2) + inline GLM_CONSTEXPR vec operator*(vec<1, T, Q> const& v2) { return vec(*this) *= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator*(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator*(T scalar, vec const& v) { return vec(v) *= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator*(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator*(vec<1, T, Q> const& v1, vec const& v2) { return vec(v2) *= v1; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator*(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator*(vec const& v1, vec const& v2) { return vec(v1) *= v2; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator/(T scalar) + inline GLM_CONSTEXPR vec operator/(T scalar) { return vec(*this) /= scalar; } - GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator/(vec<1, T, Q> const& v2) + inline GLM_CONSTEXPR vec operator/(vec<1, T, Q> const& v2) { return vec(*this) /= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator/(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator/(T scalar, vec const& v) { return vec(scalar) /= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator/(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator/(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) /= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator/(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator/(vec const& v1, vec const& v2) { return vec(v1) /= v2; } @@ -627,212 +628,213 @@ namespace glm // -- Binary bit operators -- - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator%(vec const& v, T scalar) + friend inline GLM_CONSTEXPR vec operator%(vec const& v, T scalar) { return vec(v) %= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator%(vec const& v1, vec<1, T, Q> const& v2) + friend inline GLM_CONSTEXPR vec operator%(vec const& v1, vec<1, T, Q> const& v2) { return vec(v1) %= v2.x; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator%(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator%(T scalar, vec const& v) { return vec(scalar) %= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator%(vec<1, T, Q> const& scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator%(vec<1, T, Q> const& scalar, vec const& v) { return vec(scalar.x) %= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator%(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator%(vec const& v1, vec const& v2) { return vec(v1) %= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator&(vec const& v, T scalar) + friend inline GLM_CONSTEXPR vec operator&(vec const& v, T scalar) { return vec(v) &= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator&(vec const& v, vec<1, T, Q> const& scalar) + friend inline GLM_CONSTEXPR vec operator&(vec const& v, vec<1, T, Q> const& scalar) { return vec(v) &= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator&(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator&(T scalar, vec const& v) { return vec(scalar) &= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator&(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator&(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) &= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator&(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator&(vec const& v1, vec const& v2) { return vec(v1) &= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator|(vec const& v, T scalar) + friend inline GLM_CONSTEXPR vec operator|(vec const& v, T scalar) { return vec(v) |= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator|(vec const& v1, vec<1, T, Q> const& v2) + friend inline GLM_CONSTEXPR vec operator|(vec const& v1, vec<1, T, Q> const& v2) { return vec(v1) |= v2.x; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator|(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator|(T scalar, vec const& v) { return vec(scalar) |= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator|(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator|(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) |= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator|(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator|(vec const& v1, vec const& v2) { return vec(v1) |= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator^(vec const& v, T scalar) + friend inline GLM_CONSTEXPR vec operator^(vec const& v, T scalar) { return vec(v) ^= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator^(vec const& v1, vec<1, T, Q> const& v2) + friend inline GLM_CONSTEXPR vec operator^(vec const& v1, vec<1, T, Q> const& v2) { return vec(v1) ^= v2.x; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator^(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator^(T scalar, vec const& v) { return vec(scalar) ^= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator^(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator^(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) ^= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator^(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator^(vec const& v1, vec const& v2) { return vec(v1) ^= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator<<(vec const& v, T scalar) + friend inline GLM_CONSTEXPR vec operator<<(vec const& v, T scalar) { return vec(v) <<= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator<<(vec const& v1, vec<1, T, Q> const& v2) + friend inline GLM_CONSTEXPR vec operator<<(vec const& v1, vec<1, T, Q> const& v2) { return vec(v1) <<= v2.x; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator<<(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator<<(T scalar, vec const& v) { return vec(scalar) <<= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator<<(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator<<(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) <<= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator<<(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator<<(vec const& v1, vec const& v2) { return vec(v1) <<= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator>>(vec const& v, T scalar) + friend inline GLM_CONSTEXPR vec operator>>(vec const& v, T scalar) { return vec(v) >>= scalar; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator>>(vec const& v1, vec<1, T, Q> const& v2) + friend inline GLM_CONSTEXPR vec operator>>(vec const& v1, vec<1, T, Q> const& v2) { return vec(v1) >>= v2.x; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator>>(T scalar, vec const& v) + friend inline GLM_CONSTEXPR vec operator>>(T scalar, vec const& v) { return vec(scalar) >>= v; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator>>(vec<1, T, Q> const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator>>(vec<1, T, Q> const& v1, vec const& v2) { return vec(v1.x) >>= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator>>(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR vec operator>>(vec const& v1, vec const& v2) { return vec(v1) >>= v2; } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator~(vec const& v) + friend inline GLM_CONSTEXPR vec operator~(vec const& v) { return detail::compute_vec_bitwise_not<4, T, Q, detail::is_int::value, sizeof(T) * 8, detail::is_aligned::value>::call(v); } // -- Boolean operators -- - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool operator==(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR bool operator==(vec const& v1, vec const& v2) { return detail::compute_vec_equal<4, T, Q, detail::is_int::value, sizeof(T) * 8, detail::is_aligned::value>::call(v1, v2); } - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool operator!=(vec const& v1, vec const& v2) + friend inline GLM_CONSTEXPR bool operator!=(vec const& v1, vec const& v2) { return detail::compute_vec_nequal<4, T, Q, detail::is_int::value, sizeof(T) * 8, detail::is_aligned::value>::call(v1, v2); } - - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator&&(vec const& v1, vec const& v2) - { - return vec(v1.x && v2.x, v1.y && v2.y, v1.z && v2.z, v1.w && v2.w); - } - - friend GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec operator||(vec const& v1, vec const& v2) - { - return vec(v1.x || v2.x, v1.y || v2.y, v1.z || v2.z, v1.w || v2.w); - } }; + + template requires (std::is_same_v) + inline GLM_CONSTEXPR vec operator&&(vec const& v1, vec const& v2) + { + return vec(v1.x && v2.x, v1.y && v2.y, v1.z && v2.z, v1.w && v2.w); + } + template requires (std::is_same_v) + inline GLM_CONSTEXPR vec operator||(vec const& v1, vec const& v2) + { + return vec(v1.x || v2.x, v1.y || v2.y, v1.z || v2.z, v1.w || v2.w); + } } \ No newline at end of file diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index 0cc7b5d4..27860146 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -1,6 +1,6 @@ /// @ref core /// @file glm/detail/type_vec1.hpp - +#if GLM_SIMD_CONSTEXPR == 0 #pragma once #include "qualifier.hpp" @@ -306,3 +306,4 @@ namespace glm #ifndef GLM_EXTERNAL_TEMPLATE #include "type_vec1.inl" #endif//GLM_EXTERNAL_TEMPLATE +#endif diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 66c6137c..44fbf838 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -1,6 +1,6 @@ /// @ref core /// @file glm/detail/type_vec2.hpp - +#if GLM_SIMD_CONSTEXPR == 0 #pragma once #include "qualifier.hpp" @@ -404,3 +404,4 @@ namespace glm #ifndef GLM_EXTERNAL_TEMPLATE #include "type_vec2.inl" #endif//GLM_EXTERNAL_TEMPLATE +#endif diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 90de2f8a..6da38c19 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -1,6 +1,6 @@ /// @ref core /// @file glm/detail/type_vec3.hpp - +#if GLM_SIMD_CONSTEXPR == 0 #pragma once #include "qualifier.hpp" @@ -445,3 +445,5 @@ namespace glm #ifndef GLM_EXTERNAL_TEMPLATE #include "type_vec3.inl" #endif//GLM_EXTERNAL_TEMPLATE + +#endif diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 9ba11229..5891f941 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -1,6 +1,6 @@ /// @ref core /// @file glm/detail/type_vec4.hpp - +#if GLM_SIMD_CONSTEXPR == 0 #pragma once #include "qualifier.hpp" @@ -512,3 +512,5 @@ namespace glm #ifndef GLM_EXTERNAL_TEMPLATE #include "type_vec4.inl" #endif//GLM_EXTERNAL_TEMPLATE + +#endif \ No newline at end of file diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 66539e30..d4947f77 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -1,5 +1,5 @@ /// @ref core - +#if GLM_SIMD_CONSTEXPR == 0 #include "compute_vector_relational.hpp" #include "compute_vector_decl.hpp" @@ -1128,3 +1128,5 @@ namespace glm { } #endif + +#endif diff --git a/glm/glm.hpp b/glm/glm.hpp index dee79747..a551e102 100644 --- a/glm/glm.hpp +++ b/glm/glm.hpp @@ -105,6 +105,10 @@ #define GLM_SIMD_CONSTEXPR 0 #endif +#if GLM_SIMD_CONSTEXPR == 1 +# define GLM_FORCE_INTRINSICS 1 +#endif + #include "detail/_fixes.hpp" #include "detail/setup.hpp" diff --git a/glm/matrix.hpp b/glm/matrix.hpp index 4584c92c..3d1a62b7 100644 --- a/glm/matrix.hpp +++ b/glm/matrix.hpp @@ -15,9 +15,14 @@ // Dependencies #include "detail/qualifier.hpp" #include "detail/setup.hpp" -#include "vec2.hpp" -#include "vec3.hpp" -#include "vec4.hpp" +#if GLM_SIMD_CONSTEXPR == 0 +# include "vec2.hpp" +# include "vec3.hpp" +# include "vec4.hpp" +#else +# include"simd_constexpr/vec.hpp" +#endif + #include "mat2x2.hpp" #include "mat2x3.hpp" #include "mat2x4.hpp" diff --git a/glm/simd_constexpr/vec.hpp b/glm/simd_constexpr/vec.hpp index b37f14ca..bff1b2e8 100644 --- a/glm/simd_constexpr/vec.hpp +++ b/glm/simd_constexpr/vec.hpp @@ -24,4 +24,4 @@ namespace glm typedef vec<3, bool, defaultp> bvec3; typedef vec<4, bool, defaultp> bvec4; } -#include "../detail/simd_constexpr/type_vec.hpp" +#include "../detail/simd_constexpr/vec.hpp"