diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 8d9bee3a..87e05e8a 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -698,7 +698,7 @@ #if GLM_HAS_CONSTEXPR || GLM_HAS_CONSTEXPR_PARTIAL # define GLM_CONSTEXPR constexpr -# if ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER <= GLM_COMPILER_VC14)) // Visual C++ has a bug #594 https://github.com/g-truc/glm/issues/594 +# if GLM_COMPILER & GLM_COMPILER_VC // Visual C++ has a bug #594 https://github.com/g-truc/glm/issues/594 # define GLM_CONSTEXPR_CTOR # else # define GLM_CONSTEXPR_CTOR constexpr @@ -714,6 +714,12 @@ # define GLM_RELAXED_CONSTEXPR const #endif +#if GLM_ARCH == GLM_ARCH_PURE +# define GLM_CONSTEXPR_SIMD GLM_CONSTEXPR_CTOR +#else +# define GLM_CONSTEXPR_SIMD +#endif + #ifdef GLM_FORCE_EXPLICIT_CTOR # define GLM_EXPLICIT explicit #else diff --git a/glm/detail/type_mat2x2.inl b/glm/detail/type_mat2x2.inl index 0c26ed40..9cda74a2 100644 --- a/glm/detail/type_mat2x2.inl +++ b/glm/detail/type_mat2x2.inl @@ -38,7 +38,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER mat<2, 2, T, P>::mat + GLM_FUNC_QUALIFIER mat<2, 2, T, P>::mat ( T const & x0, T const & y0, T const & x1, T const & y1 diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 9e64ca4c..b512365a 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -89,21 +89,21 @@ namespace glm // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT; - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<4, T, P> const& v) GLM_DEFAULT; + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec() GLM_DEFAULT; + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, P> const& v) GLM_DEFAULT; template - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<4, T, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, Q> const& v); // -- Explicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(T scalar); - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(T x, T y, T z, T w); + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD explicit vec(T scalar); + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(T x, T y, T z, T w); // -- Conversion scalar constructors -- /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) template - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, Y _y, Z _z, W _w); + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(X _x, Y _y, Z _z, W _w); template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, P> const& _x, vec<1, Y, P> const& _Y, vec<1, Z, P> const& _z, vec<1, W, P> const& _w); diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index f82a505d..8ff34cfe 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -156,32 +156,32 @@ namespace detail # if !GLM_HAS_DEFAULTED_FUNCTIONS template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, P>::vec() + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec() {} # endif//!GLM_HAS_DEFAULTED_FUNCTIONS # if !GLM_HAS_DEFAULTED_FUNCTIONS template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, P>::vec(vec<4, T, P> const & v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec(vec<4, T, P> const & v) : x(v.x), y(v.y), z(v.z), w(v.w) {} # endif//!GLM_HAS_DEFAULTED_FUNCTIONS template template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, P>::vec(vec<4, T, Q> const & v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec(vec<4, T, Q> const & v) : x(v.x), y(v.y), z(v.z), w(v.w) {} // -- Explicit basic constructors -- template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, P>::vec(T scalar) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec(T scalar) : x(scalar), y(scalar), z(scalar), w(scalar) {} template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, P>::vec(T _x, T _y, T _z, T _w) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec(T _x, T _y, T _z, T _w) : x(_x), y(_y), z(_z), w(_w) {} @@ -189,7 +189,7 @@ namespace detail template template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, P>::vec(X _x, Y _y, Z _z, W _w) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec(X _x, Y _y, Z _z, W _w) : x(static_cast(_x)) , y(static_cast(_y)) , z(static_cast(_z)) diff --git a/glm/detail/type_vec4_simd.inl b/glm/detail/type_vec4_simd.inl index 83f2c814..8b045a52 100644 --- a/glm/detail/type_vec4_simd.inl +++ b/glm/detail/type_vec4_simd.inl @@ -339,118 +339,132 @@ namespace detail }; }//namespace detail +# if !GLM_HAS_DEFAULTED_FUNCTIONS + template<> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_lowp>::vec() + {} + + template<> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_mediump>::vec() + {} + + template<> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_highp>::vec() + {} +# endif//!GLM_HAS_DEFAULTED_FUNCTIONS + template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_lowp>::vec(float _s) - : data(_mm_set1_ps(_s)) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_lowp>::vec(float _s) : + data(_mm_set1_ps(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_mediump>::vec(float _s) - : data(_mm_set1_ps(_s)) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_mediump>::vec(float _s) : + data(_mm_set1_ps(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_highp>::vec(float _s) - : data(_mm_set1_ps(_s)) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_highp>::vec(float _s) : + data(_mm_set1_ps(_s)) {} # if GLM_ARCH & GLM_ARCH_AVX_BIT template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, double, aligned_lowp>::vec(double _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, double, aligned_lowp>::vec(double _s) : data(_mm256_set1_pd(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, double, aligned_mediump>::vec(double _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, double, aligned_mediump>::vec(double _s) : data(_mm256_set1_pd(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, double, aligned_highp>::vec(double _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, double, aligned_highp>::vec(double _s) : data(_mm256_set1_pd(_s)) {} # endif template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int32, aligned_lowp>::vec(int32 _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int32, aligned_lowp>::vec(int32 _s) : data(_mm_set1_epi32(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int32, aligned_mediump>::vec(int32 _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int32, aligned_mediump>::vec(int32 _s) : data(_mm_set1_epi32(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int32, aligned_highp>::vec(int32 _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int32, aligned_highp>::vec(int32 _s) : data(_mm_set1_epi32(_s)) {} # if GLM_ARCH & GLM_ARCH_AVX2_BIT template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int64, aligned_lowp>::vec(int64 _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int64, aligned_lowp>::vec(int64 _s) : data(_mm256_set1_epi64x(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int64, aligned_mediump>::vec(int64 _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int64, aligned_mediump>::vec(int64 _s) : data(_mm256_set1_epi64x(_s)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int64, aligned_highp>::vec(int64 _s) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int64, aligned_highp>::vec(int64 _s) : data(_mm256_set1_epi64x(_s)) {} # endif template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_lowp>::vec(float _x, float _y, float _z, float _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_lowp>::vec(float _x, float _y, float _z, float _w) : data(_mm_set_ps(_w, _z, _y, _x)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_mediump>::vec(float _x, float _y, float _z, float _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_mediump>::vec(float _x, float _y, float _z, float _w) : data(_mm_set_ps(_w, _z, _y, _x)) {} template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_highp>::vec(float _x, float _y, float _z, float _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_highp>::vec(float _x, float _y, float _z, float _w) : data(_mm_set_ps(_w, _z, _y, _x)) {} template<> template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int32, aligned_lowp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int32, aligned_lowp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : data(_mm_set_epi32(_w, _z, _y, _x)) {} template<> template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int32, aligned_mediump>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int32, aligned_mediump>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : data(_mm_set_epi32(_w, _z, _y, _x)) {} template<> template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, int32, aligned_highp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, int32, aligned_highp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : data(_mm_set_epi32(_w, _z, _y, _x)) {} template<> template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_lowp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_lowp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : data(_mm_castsi128_ps(_mm_set_epi32(_w, _z, _y, _x))) {} template<> template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_mediump>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_mediump>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : data(_mm_castsi128_ps(_mm_set_epi32(_w, _z, _y, _x))) {} template<> template<> - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, float, aligned_highp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, float, aligned_highp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) : data(_mm_castsi128_ps(_mm_set_epi32(_w, _z, _y, _x))) {} }//namespace glm diff --git a/readme.md b/readme.md index 983aa061..45b22e06 100644 --- a/readme.md +++ b/readme.md @@ -91,7 +91,6 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Fixed integer pow from GTX_integer with null exponent #658 - Fixed quat normalize build error #656 - Fixed Visual C++ 2017.2 warning regarding __has_feature definision #655 -- Fixed vec4 SIMD constexpr #653 #### Deprecation: - Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler diff --git a/test/core/core_type_mat2x2.cpp b/test/core/core_type_mat2x2.cpp index 35064e5c..60ae1b1c 100644 --- a/test/core/core_type_mat2x2.cpp +++ b/test/core/core_type_mat2x2.cpp @@ -61,7 +61,7 @@ int test_ctr() #if GLM_HAS_INITIALIZER_LISTS glm::mat2x2 m0( - glm::vec2(0, 1), + glm::vec2(0, 1), glm::vec2(2, 3)); glm::mat2x2 m1{0, 1, 2, 3}; diff --git a/test/core/core_type_vec1.cpp b/test/core/core_type_vec1.cpp index 884e44c7..2657c2cb 100644 --- a/test/core/core_type_vec1.cpp +++ b/test/core/core_type_vec1.cpp @@ -38,10 +38,6 @@ int test_vec1_ctor() { int Error = 0; -# if GLM_HAS_CONSTEXPR - constexpr glm::vec1 v(0); -# endif - # if GLM_HAS_TRIVIAL_QUERIES // Error += std::is_trivially_default_constructible::value ? 0 : 1; // Error += std::is_trivially_copy_assignable::value ? 0 : 1; diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index f51295be..551220b8 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -199,10 +199,6 @@ int test_vec2_ctor() { int Error = 0; -# if GLM_HAS_CONSTEXPR - constexpr glm::vec2 v(0); -# endif - { glm::vec2 A(1); glm::vec2 B(A); diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index abdeb2c2..bbbd1841 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -15,10 +15,6 @@ int test_vec3_ctor() { int Error = 0; -# if GLM_HAS_CONSTEXPR - constexpr glm::vec3 v(0); -# endif - # if GLM_HAS_TRIVIAL_QUERIES // Error += std::is_trivially_default_constructible::value ? 0 : 1; // Error += std::is_trivially_copy_assignable::value ? 0 : 1; @@ -263,7 +259,7 @@ int test_vec3_swizzle3_2() int Error = 0; glm::vec3 v(1, 2, 3); - glm::vec2 u(0); + glm::vec2 u; # if(GLM_LANG & GLM_LANG_CXXMS_FLAG) // Can not assign a vec3 swizzle to a vec2 @@ -326,7 +322,7 @@ int test_vec3_swizzle3_3() int Error = 0; glm::vec3 v(1, 2, 3); - glm::vec3 u(0); + glm::vec3 u; # if(GLM_LANG & GLM_LANG_CXXMS_FLAG) u = v; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1; @@ -352,7 +348,7 @@ int test_vec3_swizzle_operators() { int Error = 0; - glm::vec3 q(0), u, v; + glm::vec3 q, u, v; u = glm::vec3(1, 2, 3); v = glm::vec3(10, 20, 30); @@ -409,9 +405,9 @@ int test_vec3_swizzle_functions() r = glm::dot(glm::vec2(a.xy()), glm::vec2(b.yy())); Error += (int(r) == 60) ? 0 : 1; // vec3 - glm::vec3 q(0); - glm::vec3 u = glm::vec3(1, 2, 3); - glm::vec3 v = glm::vec3(10, 20, 30); + glm::vec3 q, u, v; + u = glm::vec3(1, 2, 3); + v = glm::vec3(10, 20, 30); r = glm::dot(u, v); Error += (int(r) == 140) ? 0 : 1; r = glm::dot(u.xyz(), v.zyz()); Error += (int(r) == 160) ? 0 : 1; r = glm::dot(u, v.zyx()); Error += (int(r) == 100) ? 0 : 1; @@ -419,8 +415,9 @@ int test_vec3_swizzle_functions() r = glm::dot(u.xy(), v.xy()); Error += (int(r) == 50) ? 0 : 1; // vec4 - glm::vec4 s = glm::vec4(1, 2, 3, 4); - glm::vec4 t = glm::vec4(10, 20, 30, 40); + glm::vec4 s, t; + s = glm::vec4(1, 2, 3, 4); + t = glm::vec4(10, 20, 30, 40); r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1; r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1; r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1; @@ -486,6 +483,9 @@ int main() { int Error = 0; + glm::vec3 v; + assert(v.length() == 3); + Error += test_vec3_ctor(); Error += test_vec3_operators(); Error += test_vec3_size(); diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 55b8b477..79c62c04 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -37,10 +37,6 @@ int test_vec4_ctor() { int Error = 0; -# if GLM_HAS_CONSTEXPR - constexpr glm::vec4 v(0.0f); -# endif - { glm::ivec4 A(1, 2, 3, 4); glm::ivec4 B(A); @@ -550,6 +546,8 @@ int main() printf("GNI\n"); } */ + glm::vec4 v; + assert(v.length() == 4); # ifdef NDEBUG std::size_t const Size(1000000);