Kaynağa Gözat

Added vec4 SIMD contructor specialization

Christophe Riccio 9 yıl önce
ebeveyn
işleme
a9fefc7300

+ 22 - 4
glm/detail/type_vec4.inl

@@ -125,7 +125,25 @@ namespace detail
 	};
 
 	template <typename T, precision P, int IsInt, std::size_t Size>
-	struct compute_vec4_logical_not
+	struct compute_vec4_equal
+	{
+		static bool call(tvec4<T, P> const & v1, tvec4<T, P> const & v2)
+		{
+			return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z) && (v1.w == v2.w);
+		}
+	};
+
+	template <typename T, precision P, int IsInt, std::size_t Size>
+	struct compute_vec4_nequal
+	{
+		static bool call(tvec4<T, P> const & v1, tvec4<T, P> const & v2)
+		{
+			return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z) || (v1.w != v2.w);
+		}
+	};
+
+	template <typename T, precision P, int IsInt, std::size_t Size>
+	struct compute_vec4_bitwise_not
 	{
 		static tvec4<T, P> call(tvec4<T, P> const & v)
 		{
@@ -922,7 +940,7 @@ namespace detail
 	template <typename T, precision P> 
 	GLM_FUNC_QUALIFIER tvec4<T, P> operator~(tvec4<T, P> const & v)
 	{
-		return detail::compute_vec4_logical_not<T, P, detail::is_int<T>::value, sizeof(T) * 8>::call(v);
+		return detail::compute_vec4_bitwise_not<T, P, detail::is_int<T>::value, sizeof(T) * 8>::call(v);
 	}
 
 	// -- Boolean operators --
@@ -930,13 +948,13 @@ namespace detail
 	template <typename T, precision P>
 	GLM_FUNC_QUALIFIER bool operator==(tvec4<T, P> const & v1, tvec4<T, P> const & v2)
 	{
-		return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z) && (v1.w == v2.w);
+		return detail::compute_vec4_equal<T, P, detail::is_int<T>::value, sizeof(T) * 8>::call(v1, v2);
 	}
 
 	template <typename T, precision P>
 	GLM_FUNC_QUALIFIER bool operator!=(tvec4<T, P> const & v1, tvec4<T, P> const & v2)
 	{
-		return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z) || (v1.w != v2.w);
+		return detail::compute_vec4_nequal<T, P, detail::is_int<T>::value, sizeof(T) * 8>::call(v1, v2);
 	}
 
 	template <precision P>

+ 88 - 2
glm/detail/type_vec4_simd.inl

@@ -182,7 +182,7 @@ namespace detail
 #	endif
 
 	template <typename T, precision P>
-	struct compute_vec4_logical_not<T, P, true, 32>
+	struct compute_vec4_bitwise_not<T, P, true, 32>
 	{
 		static tvec4<T, P> call(tvec4<T, P> const & v)
 		{
@@ -194,7 +194,7 @@ namespace detail
 
 #	if GLM_ARCH & GLM_ARCH_AVX2
 	template <typename T, precision P>
-	struct compute_vec4_logical_not<T, P, true, 64>
+	struct compute_vec4_bitwise_not<T, P, true, 64>
 	{
 		static tvec4<T, P> call(tvec4<T, P> 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<double, lowp>::tvec4(double s) :
+		data(_mm256_set1_pd(s))
+	{}
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<double, mediump>::tvec4(double s) :
+		data(_mm256_set1_pd(s))
+	{}
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<double, highp>::tvec4(double s) :
+		data(_mm256_set1_pd(s))
+	{}
+#	endif
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<int32, lowp>::tvec4(int32 s) :
+		data(_mm_set1_epi32(s))
+	{}
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<int32, mediump>::tvec4(int32 s) :
+		data(_mm_set1_epi32(s))
+	{}
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<int32, highp>::tvec4(int32 s) :
+		data(_mm_set1_epi32(s))
+	{}
+
+#	if GLM_ARCH & GLM_ARCH_AVX2
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<int64, lowp>::tvec4(int64 s) :
+		data(_mm256_set1_epi64x(s))
+	{}
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<int64, mediump>::tvec4(int64 s) :
+		data(_mm256_set1_epi64x(s))
+	{}
+
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<int64, highp>::tvec4(int64 s) :
+		data(_mm256_set1_epi64x(s))
+	{}
+#	endif
+
 	template <>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4<float, lowp>::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<float, highp>::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<int32, lowp>::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<int32, mediump>::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<int32, highp>::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<float, lowp>::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<float, mediump>::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<float, highp>::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

+ 4 - 2
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