From 8387847c42d1e7aca22f660336c0828cae37aed4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 31 Jan 2011 12:38:48 +0000 Subject: [PATCH] Improved simd cast and added duplicated values function with smind instructions --- glm/gtx/simd_mat4.hpp | 5 +++++ glm/gtx/simd_mat4.inl | 13 +++++++++++++ glm/gtx/simd_vec4.hpp | 23 ++++++++++++++++++---- glm/gtx/simd_vec4.inl | 40 +++++++++++++++++++++++++------------- test/gtx/gtx-simd-vec4.cpp | 4 ++-- 5 files changed, 65 insertions(+), 20 deletions(-) diff --git a/glm/gtx/simd_mat4.hpp b/glm/gtx/simd_mat4.hpp index 254fa636..f48df975 100644 --- a/glm/gtx/simd_mat4.hpp +++ b/glm/gtx/simd_mat4.hpp @@ -134,6 +134,11 @@ namespace glm { typedef detail::fmat4x4SIMD simdMat4; + //! Convert a simdMat4 to a mat4. + //! (From GLM_GTX_simd_mat4 extension) + detail::tmat4x4 mat4_cast( + detail::fmat4x4SIMD const & x); + //! Multiply matrix x by matrix y component-wise, i.e., //! result[i][j] is the scalar product of x[i][j] and y[i][j]. //! (From GLM_GTX_simd_mat4 extension). diff --git a/glm/gtx/simd_mat4.inl b/glm/gtx/simd_mat4.inl index abcb849c..59d1065e 100644 --- a/glm/gtx/simd_mat4.inl +++ b/glm/gtx/simd_mat4.inl @@ -237,6 +237,19 @@ namespace detail namespace gtx{ namespace simd_mat4 { + inline detail::tmat4x4 mat4_cast + ( + detail::fmat4x4SIMD const & x + ) + { + detail::tmat4x4 Result; + _mm_store_ps(&Result[0][0], x.Data[0].Data); + _mm_store_ps(&Result[1][0], x.Data[1].Data); + _mm_store_ps(&Result[2][0], x.Data[2].Data); + _mm_store_ps(&Result[3][0], x.Data[3].Data); + return Result; + } + inline detail::fmat4x4SIMD simdMatrixCompMult ( detail::fmat4x4SIMD const & x, diff --git a/glm/gtx/simd_vec4.hpp b/glm/gtx/simd_vec4.hpp index 4a8e5313..da2736ed 100644 --- a/glm/gtx/simd_vec4.hpp +++ b/glm/gtx/simd_vec4.hpp @@ -51,10 +51,6 @@ namespace glm fvec4SIMD(__m128 const & Data); fvec4SIMD(fvec4SIMD const & v); - fvec4SIMD(tvec4 const & v); - //operator detail::tvec4(); - //operator detail::tvec4 const(); - ////////////////////////////////////// // Explicit basic constructors @@ -67,6 +63,8 @@ namespace glm float const & y, float const & z, float const & w); + explicit fvec4SIMD( + tvec4 const & v); //////////////////////////////////////// //// Convertion vector constructors @@ -129,18 +127,35 @@ namespace glm float simdLength( detail::fvec4SIMD const & x); + //! Returns the length of x, i.e., sqrt(x * x). + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdLength4( + detail::fvec4SIMD const & x); + //! Returns the distance betwwen p0 and p1, i.e., length(p0 - p1). //! (From GLM_GTX_simd_vec4 extension, geometry functions) float simdDistance( detail::fvec4SIMD const & p0, detail::fvec4SIMD const & p1); + //! Returns the distance betwwen p0 and p1, i.e., length(p0 - p1). + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdDistance4( + detail::fvec4SIMD const & p0, + detail::fvec4SIMD const & p1); + //! Returns the dot product of x and y, i.e., result = x * y. //! (From GLM_GTX_simd_vec4 extension, geometry functions) float simdDot( detail::fvec4SIMD const & x, detail::fvec4SIMD const & y); + //! Returns the dot product of x and y, i.e., result = x * y. + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdDot4( + detail::fvec4SIMD const & x, + detail::fvec4SIMD const & y); + //! Returns the cross product of x and y. //! (From GLM_GTX_simd_vec4 extension, geometry functions) detail::fvec4SIMD simdCross( diff --git a/glm/gtx/simd_vec4.inl b/glm/gtx/simd_vec4.inl index de4f40a4..e38d3199 100644 --- a/glm/gtx/simd_vec4.inl +++ b/glm/gtx/simd_vec4.inl @@ -35,20 +35,6 @@ namespace glm Data(_mm_set_ps(v.w, v.z, v.y, v.x)) {} - inline fvec4SIMD::operator detail::tvec4() - { - detail::tvec4 Result; - _mm_store_ps(&Result[0], this->Data); - return Result; - } - - //inline fvec4SIMD::operator detail::tvec4 const() - //{ - // detail::tvec4 Result; - // _mm_store_ps(&Result[0], this->Data); - // return Result; - //} - ////////////////////////////////////// // Explicit basic constructors @@ -304,6 +290,14 @@ namespace glm return Result; } + inline detail::fvec4SIMD simdLength4 + ( + detail::fvec4SIMD const & x + ) + { + return detail::sse_len_ps(x.Data); + } + inline float simdDistance ( detail::fvec4SIMD const & p0, @@ -315,6 +309,15 @@ namespace glm return Result; } + inline detail::fvec4SIMD simdDistance4 + ( + detail::fvec4SIMD const & p0, + detail::fvec4SIMD const & p1 + ) + { + return detail::sse_dst_ps(p0.Data, p1.Data); + } + inline float simdDot ( detail::fvec4SIMD const & x, @@ -326,6 +329,15 @@ namespace glm return Result; } + inline detail::fvec4SIMD simdDot4 + ( + detail::fvec4SIMD const & x, + detail::fvec4SIMD const & y + ) + { + return detail::sse_dot_ss(x.Data, y.Data); + } + inline detail::fvec4SIMD simdCross ( detail::fvec4SIMD const & x, diff --git a/test/gtx/gtx-simd-vec4.cpp b/test/gtx/gtx-simd-vec4.cpp index 56e2bd14..d5df3ada 100644 --- a/test/gtx/gtx-simd-vec4.cpp +++ b/test/gtx/gtx-simd-vec4.cpp @@ -17,8 +17,8 @@ int main() glm::simdVec4 B1(0.4f, 0.5f, 0.6f, 0.7f); glm::simdVec4 C1 = A1 + B1; glm::simdVec4 D1 = A1.swizzle(); - glm::simdVec4 E1 = glm::vec4(1.0f); - glm::vec4 F1 = E1; + glm::simdVec4 E1(glm::vec4(1.0f)); + glm::vec4 F1 = glm::vec4_cast(E1); //glm::vec4 G1(E1); //printf("A1(%2.3f, %2.3f, %2.3f, %2.3f)\n", A1.x, A1.y, A1.z, A1.w);