From d950f21404f6b77cde150ebae5a4d3962cd0dc6e Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:25:21 -0400 Subject: [PATCH] constexpr simd vec: fix more runtime issues --- glm/detail/simd_constexpr/element.hpp | 6 ++++-- glm/detail/simd_constexpr/vec.hpp | 11 ++++++----- test/core/core_c++20_simd_constexpr.cpp | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/glm/detail/simd_constexpr/element.hpp b/glm/detail/simd_constexpr/element.hpp index 01908674..43df13c5 100644 --- a/glm/detail/simd_constexpr/element.hpp +++ b/glm/detail/simd_constexpr/element.hpp @@ -3,8 +3,10 @@ namespace glm::detail { consteval bool NotEmpty(length_t I, length_t L) { return I <= L; } - template - struct Element + template + struct Element; + template requires (!NotEmpty(I, L)) + struct Element { constexpr operator auto() { return 0; diff --git a/glm/detail/simd_constexpr/vec.hpp b/glm/detail/simd_constexpr/vec.hpp index 093cb9bc..a3cb2e7b 100644 --- a/glm/detail/simd_constexpr/vec.hpp +++ b/glm/detail/simd_constexpr/vec.hpp @@ -189,17 +189,18 @@ namespace glm // -- Data -- #define GLM_N [[no_unique_address]] +#define GLM_MA __attribute__((__may_alias__)) template using E = detail::Element; union { - struct { + GLM_MA struct { 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; }; + union { GLM_N E<2> y GLM_MA; GLM_N E<2> g; GLM_N E<2> t; }; + union { GLM_N E<3> z GLM_MA; GLM_N E<3> b; GLM_N E<3> p; }; + union { GLM_N E<4> w GLM_MA; GLM_N E<4> a; GLM_N E<4> q; }; }; - data_t data; + GLM_MA data_t data; }; #undef GLM_N # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR diff --git a/test/core/core_c++20_simd_constexpr.cpp b/test/core/core_c++20_simd_constexpr.cpp index 9d8ad8d3..f4394faa 100644 --- a/test/core/core_c++20_simd_constexpr.cpp +++ b/test/core/core_c++20_simd_constexpr.cpp @@ -31,7 +31,8 @@ int main() v1.x; avec4 vfin = glm::max(v1, v2) + v3; static_assert(sizeof(vfin)>0); + double w = v3.w; printf("vfin = %f %f %f %f\n", vfin[0], vfin[1], vfin[2], vfin[3]); - printf("v3 = %f %f %f %f\n", v3[0], v3[1], v3[2], v3[3]); + printf("v3 = %f %f %f %f\n", v3[0], v3[1], v3.y, w); return 0; }