From 07a1abdfb3be43c6ea16c15103d2d928d09a6fef Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Dec 2013 13:03:26 +0100 Subject: [PATCH] Added vec4 SSE2 specializations --- glm/detail/type_vec4.hpp | 10 +- glm/detail/type_vec4.inl | 230 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 224 insertions(+), 16 deletions(-) diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 6fc0039c..2bc1ca59 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -255,9 +255,17 @@ namespace detail // Unary arithmetic operators GLM_FUNC_DECL tvec4 & operator= (tvec4 const & v); + GLM_FUNC_DECL tvec4 & operator+=(T s); + GLM_FUNC_DECL tvec4 & operator+=(tvec4 const & v); + GLM_FUNC_DECL tvec4 & operator-=(T s); + GLM_FUNC_DECL tvec4 & operator-=(tvec4 const & v); + GLM_FUNC_DECL tvec4 & operator*=(T s); + GLM_FUNC_DECL tvec4 & operator*=(tvec4 const & v); + GLM_FUNC_DECL tvec4 & operator/=(T s); + GLM_FUNC_DECL tvec4 & operator/=(tvec4 const & v); + template GLM_FUNC_DECL tvec4 & operator= (tvec4 const & v); - template GLM_FUNC_DECL tvec4 & operator+=(U s); template diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index d6688a2e..ed26032c 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -63,6 +63,18 @@ namespace detail w(0) {} +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4() : + data(_mm_setzero_ps()) + {} + + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4() : + data(_mm_setzero_ps()) + {} +#endif + template GLM_FUNC_QUALIFIER tvec4::tvec4(tvec4 const & v) : x(v.x), @@ -71,6 +83,18 @@ namespace detail w(v.w) {} +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4(tvec4 const & v) : + data(v.data) + {} + + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4(tvec4 const & v) : + data(v.data) + {} +#endif + template template GLM_FUNC_QUALIFIER tvec4::tvec4(tvec4 const & v) : @@ -80,6 +104,20 @@ namespace detail w(v.w) {} +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + template + GLM_FUNC_QUALIFIER tvec4::tvec4(tvec4 const & v) : + data(_mm_set_ps(w, z, y, x)) + {} + + template <> + template + GLM_FUNC_QUALIFIER tvec4::tvec4(tvec4 const & v) : + data(_mm_set_ps(w, z, y, x)) + {} +#endif + #if(GLM_HAS_INITIALIZER_LISTS) template template @@ -108,35 +146,64 @@ namespace detail w(s) {} +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4(float const & s) : + data(_mm_set1_ps(s)) + {} + + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4(float const & s) : + data(_mm_set1_ps(s)) + {} +#endif + template - GLM_FUNC_QUALIFIER tvec4::tvec4 - ( - T const & s1, - T const & s2, - T const & s3, - T const & s4 - ) : - x(s1), - y(s2), - z(s3), - w(s4) + GLM_FUNC_QUALIFIER tvec4::tvec4(T const & a, T const & b, T const & c, T const & d) : + x(a), + y(b), + z(c), + w(d) {} +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4(float const & a, float const & b, float const & c, float const & d) : + data(_mm_set_ps(d, c, b, a)) + {} + + template <> + GLM_FUNC_QUALIFIER tvec4::tvec4(float const & a, float const & b, float const & c, float const & d) : + data(_mm_set_ps(d, c, b, a)) + {} +#endif + ////////////////////////////////////// // Conversion scalar constructors template template - GLM_FUNC_QUALIFIER tvec4::tvec4 - ( - U const & x - ) : + GLM_FUNC_QUALIFIER tvec4::tvec4(U const & x) : x(static_cast(x)), y(static_cast(x)), z(static_cast(x)), w(static_cast(x)) {} +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + template + GLM_FUNC_QUALIFIER tvec4::tvec4(U const & x) : + data(_mm_set_ps(static_cast(x), static_cast(x), static_cast(x), static_cast(x))) + {} + + template <> + template + GLM_FUNC_QUALIFIER tvec4::tvec4(U const & x) : + data(_mm_set_ps(static_cast(x), static_cast(x), static_cast(x), static_cast(x))) + {} +#endif + template template GLM_FUNC_QUALIFIER tvec4::tvec4 @@ -261,6 +328,121 @@ namespace detail return *this; } +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator= (tvec4 const & v) + { + this->data = v.data; + return *this; + } + + template <> + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator= (tvec4 const & v) + { + this->data = v.data; + return *this; + } +#endif + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (T s) + { + this->x += s; + this->y += s; + this->z += s; + this->w += s; + return *this; + } + +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (float s) + { + this->data = _mm_add_ps(this->data, _mm_set_ps1(s)); + return *this; + } + + template <> + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (float s) + { + this->data = _mm_add_ps(this->data, _mm_set_ps1(s)); + return *this; + } +#endif + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (tvec4 const & v) + { + this->x += v.x; + this->y += v.y; + this->z += v.z; + this->w += v.w; + return *this; + } + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-= (T s) + { + this->x -= s; + this->y -= s; + this->z -= s; + this->w -= s; + return *this; + } + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-= (tvec4 const & v) + { + this->x -= v.x; + this->y -= v.y; + this->z -= v.z; + this->w -= v.w; + return *this; + } + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*= (T s) + { + this->x *= s; + this->y *= s; + this->z *= s; + this->w *= s; + return *this; + } + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*= (tvec4 const & v) + { + this->x *= v.x; + this->y *= v.y; + this->z *= v.z; + this->w *= v.w; + return *this; + } + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/= (T s) + { + this->x /= s; + this->y /= s; + this->z /= s; + this->w /= s; + return *this; + } + + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/= (tvec4 const & v) + { + this->x /= v.x; + this->y /= v.y; + this->z /= v.z; + this->w /= v.w; + return *this; + } + + + + template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator= (tvec4 const & v) @@ -283,6 +465,24 @@ namespace detail return *this; } +#if((GLM_HAS_UNRESTRICTED_UNIONS) && (GLM_ARCH & GLM_ARCH_SSE2)) + template <> + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (U s) + { + this->data = _mm_add_ps(this->data, _mm_set_ps1(static_cast(s))); + return *this; + } + + template <> + template + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (U s) + { + this->data = _mm_add_ps(this->data, _mm_set_ps1(static_cast(s))); + return *this; + } +#endif + template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+= (tvec4 const & v)