From a9fefc7300800570e42dde9ca6754aa55baf3922 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 28 May 2016 01:33:29 +0200 Subject: [PATCH] Added vec4 SIMD contructor specialization --- glm/detail/type_vec4.inl | 26 ++++++++-- glm/detail/type_vec4_simd.inl | 90 ++++++++++++++++++++++++++++++++++- test/core/core_type_ctor.cpp | 6 ++- 3 files changed, 114 insertions(+), 8 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index a6857be7..61a73b17 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -125,7 +125,25 @@ namespace detail }; template - struct compute_vec4_logical_not + struct compute_vec4_equal + { + static bool call(tvec4 const & v1, tvec4 const & v2) + { + return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z) && (v1.w == v2.w); + } + }; + + template + struct compute_vec4_nequal + { + static bool call(tvec4 const & v1, tvec4 const & v2) + { + return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z) || (v1.w != v2.w); + } + }; + + template + struct compute_vec4_bitwise_not { static tvec4 call(tvec4 const & v) { @@ -922,7 +940,7 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 operator~(tvec4 const & v) { - return detail::compute_vec4_logical_not::value, sizeof(T) * 8>::call(v); + return detail::compute_vec4_bitwise_not::value, sizeof(T) * 8>::call(v); } // -- Boolean operators -- @@ -930,13 +948,13 @@ namespace detail template GLM_FUNC_QUALIFIER bool operator==(tvec4 const & v1, tvec4 const & v2) { - return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z) && (v1.w == v2.w); + return detail::compute_vec4_equal::value, sizeof(T) * 8>::call(v1, v2); } template GLM_FUNC_QUALIFIER bool operator!=(tvec4 const & v1, tvec4 const & v2) { - return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z) || (v1.w != v2.w); + return detail::compute_vec4_nequal::value, sizeof(T) * 8>::call(v1, v2); } template diff --git a/glm/detail/type_vec4_simd.inl b/glm/detail/type_vec4_simd.inl index 3096913c..608b6861 100644 --- a/glm/detail/type_vec4_simd.inl +++ b/glm/detail/type_vec4_simd.inl @@ -182,7 +182,7 @@ namespace detail # endif template - struct compute_vec4_logical_not + struct compute_vec4_bitwise_not { static tvec4 call(tvec4 const & v) { @@ -194,7 +194,7 @@ namespace detail # if GLM_ARCH & GLM_ARCH_AVX2 template - struct compute_vec4_logical_not + struct compute_vec4_bitwise_not { static tvec4 call(tvec4 const & v) { @@ -230,6 +230,55 @@ namespace detail data(_mm_set1_ps(s)) {} +# if GLM_ARCH & GLM_ARCH_AVX + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(double s) : + data(_mm256_set1_pd(s)) + {} + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(double s) : + data(_mm256_set1_pd(s)) + {} + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(double s) : + data(_mm256_set1_pd(s)) + {} +# endif + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 s) : + data(_mm_set1_epi32(s)) + {} + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 s) : + data(_mm_set1_epi32(s)) + {} + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 s) : + data(_mm_set1_epi32(s)) + {} + +# if GLM_ARCH & GLM_ARCH_AVX2 + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int64 s) : + data(_mm256_set1_epi64x(s)) + {} + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int64 s) : + data(_mm256_set1_epi64x(s)) + {} + + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int64 s) : + data(_mm256_set1_epi64x(s)) + {} +# endif + template <> GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(float a, float b, float c, float d) : data(_mm_set_ps(d, c, b, a)) @@ -244,6 +293,43 @@ namespace detail GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(float a, float b, float c, float d) : data(_mm_set_ps(d, c, b, a)) {} + + template <> + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : + data(_mm_set_epi32(d, c, b, a)) + {} + + template <> + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : + data(_mm_set_epi32(d, c, b, a)) + {} + + template <> + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : + data(_mm_set_epi32(d, c, b, a)) + {} +/* + template <> + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : + data(_mm_castsi128_ps(_mm_set_epi32(d, c, b, a))) + {} + + template <> + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : + data(_mm_castsi128_ps(_mm_set_epi32(d, c, b, a))) + {} + + template <> + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : + data(_mm_castsi128_ps(_mm_set_epi32(d, c, b, a))) + {} +*/ }//namespace glm #endif//GLM_ARCH & GLM_ARCH_SSE2 diff --git a/test/core/core_type_ctor.cpp b/test/core/core_type_ctor.cpp index f9f43e6e..683f19eb 100644 --- a/test/core/core_type_ctor.cpp +++ b/test/core/core_type_ctor.cpp @@ -193,10 +193,12 @@ int test_mat2x4_ctor() } A, B; A.f = glm::mat2x4(0); - Error += glm::all(glm::equal(A.i[0], glm::vec4(0))) ? 0 : 1; + glm::vec4 const C(0, 0, 0, 0); + Error += glm::all(glm::equal(A.i[0], C)) ? 0 : 1; B.f = glm::mat2x4(1); - Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0))) ? 0 : 1; + glm::vec4 const D(1, 0, 0, 0); + Error += glm::all(glm::equal(B.i[0], D)) ? 0 : 1; } # endif//GLM_HAS_DEFAULTED_FUNCTIONS