From 2173dba0fd9348b35c3f1715b6d8f84b6851d132 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 29 Jan 2011 17:51:44 +0000 Subject: [PATCH] Updated SIMD implementation --- glm/gtx/simd_mat4.hpp | 38 ++++++++++++++++++++ glm/gtx/simd_vec4.hpp | 54 ++++++++++++++++++++++++++++ glm/gtx/simd_vec4.inl | 82 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) diff --git a/glm/gtx/simd_mat4.hpp b/glm/gtx/simd_mat4.hpp index b91c0e7c..44f65931 100644 --- a/glm/gtx/simd_mat4.hpp +++ b/glm/gtx/simd_mat4.hpp @@ -146,6 +146,44 @@ namespace glm //! (From GLM_GTX_simd_mat4 extension). detail::fmat4x4SIMD simd_inverse(detail::fmat4x4SIMD const & m); + }//namespace simd_mat4 + namespace simd_mat4 + { + //! 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). + template + matType matrixCompMult( + matType const & x, + matType const & y); + + //! Treats the first parameter c as a column vector + //! and the second parameter r as a row vector + //! and does a linear algebraic matrix multiply c * r. + //! (From GLM_GTX_simd_mat4 extension). + template + matType outerProduct( + vecType const & c, + vecType const & r); + + //! Returns the transposed matrix of x + //! (From GLM_GTX_simd_mat4 extension). + template + typename matType::transpose_type transpose( + matType const & x); + + //! Return the determinant of a mat4 matrix. + //! (From GLM_GTX_simd_mat4 extension). + template + typename detail::tmat4x4::value_type determinant( + detail::tmat4x4 const & m); + + //! Return the inverse of a mat4 matrix. + //! (From GLM_GTX_simd_mat4 extension). + template + detail::tmat4x4 inverse( + detail::tmat4x4 const & m); + }//namespace simd_mat4 }//namespace gtx }//namespace glm diff --git a/glm/gtx/simd_vec4.hpp b/glm/gtx/simd_vec4.hpp index f1c363a6..a13221c7 100644 --- a/glm/gtx/simd_vec4.hpp +++ b/glm/gtx/simd_vec4.hpp @@ -125,6 +125,60 @@ namespace glm detail::fvec4SIMD const & b); }//namespace simd_vec4 + + namespace simd_vec4 + { + //! Returns the length of x, i.e., sqrt(x * x). + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + float simdLength( + 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 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 cross product of x and y. + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdCross( + detail::fvec4SIMD const & x, + detail::fvec4SIMD const & y); + + //! Returns a vector in the same direction as x but with length of 1. + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdNormalize( + detail::fvec4SIMD const & x); + + //! If dot(Nref, I) < 0.0, return N, otherwise, return -N. + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdFaceforward( + detail::fvec4SIMD const & N, + detail::fvec4SIMD const & I, + detail::fvec4SIMD const & Nref); + + //! For the incident vector I and surface orientation N, + //! returns the reflection direction : result = I - 2.0 * dot(N, I) * N. + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdReflect( + detail::fvec4SIMD const & I, + detail::fvec4SIMD const & N); + + //! For the incident vector I and surface normal N, + //! and the ratio of indices of refraction eta, + //! return the refraction vector. + //! (From GLM_GTX_simd_vec4 extension, geometry functions) + detail::fvec4SIMD simdRefract( + detail::fvec4SIMD const & I, + detail::fvec4SIMD const & N, + float const & eta); + }//namespace simd_vec4 }//namespace gtx }//namespace glm diff --git a/glm/gtx/simd_vec4.inl b/glm/gtx/simd_vec4.inl index a5244d33..9efb68f1 100644 --- a/glm/gtx/simd_vec4.inl +++ b/glm/gtx/simd_vec4.inl @@ -286,5 +286,87 @@ namespace glm } # endif }//namespace simd_vec4 + + namespace simd_vec4 + { + inline float simdLength + ( + detail::fvec4SIMD const & x + ) + { + float Result = 0; + _mm_store_ss(sse_len_ps(x.data), &Result); + return Result; + } + + inline float simdDistance + ( + detail::fvec4SIMD const & p0, + detail::fvec4SIMD const & p1 + ) + { + float Result = 0; + _mm_store_ss(sse_dst_ps(p0.data, p1.data), &Result); + return Result; + } + + inline float simdDot + ( + detail::fvec4SIMD const & x, + detail::fvec4SIMD const & y + ) + { + float Result = 0; + _mm_store_ss(sse_dot_ss(x.data, y.data), &Result); + return Result; + } + + inline detail::fvec4SIMD simdCross + ( + detail::fvec4SIMD const & x, + detail::fvec4SIMD const & y + ) + { + return sse_xpd_ps(x.data, y.data); + } + + inline detail::fvec4SIMD simdNormalize + ( + detail::fvec4SIMD const & x + ) + { + return _mm_nrm_ps(x.data); + } + + inline detail::fvec4SIMD simdFaceforward + ( + detail::fvec4SIMD const & N, + detail::fvec4SIMD const & I, + detail::fvec4SIMD const & Nref + ) + { + return _mm_ffd_ps(N.data, I.data, Nref.data); + } + + inline detail::fvec4SIMD simdReflect + ( + detail::fvec4SIMD const & I, + detail::fvec4SIMD const & N + ) + { + return detail::fvec4SIMD(_mm_rfe_ps(I.data, N.data)); + } + + inline detail::fvec4SIMD simdRefract + ( + detail::fvec4SIMD const & I, + detail::fvec4SIMD const & N, + float const & eta + ) + { + return detail::fvec4SIMD(_mm_rfa_ps(I.data, N.data, _mm_set1_ps(eta))); + } + + }//namespace simd_vec4 }//namespace gtx }//namespace glm