Updated SIMD implementation

This commit is contained in:
Christophe Riccio 2011-01-29 17:51:44 +00:00
parent 8f700a05ef
commit 2173dba0fd
3 changed files with 174 additions and 0 deletions

View File

@ -146,6 +146,44 @@ namespace glm
//! (From GLM_GTX_simd_mat4 extension). //! (From GLM_GTX_simd_mat4 extension).
detail::fmat4x4SIMD simd_inverse(detail::fmat4x4SIMD const & m); 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 <typename matType>
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 <typename vecType, typename matType>
matType outerProduct(
vecType const & c,
vecType const & r);
//! Returns the transposed matrix of x
//! (From GLM_GTX_simd_mat4 extension).
template <typename matType>
typename matType::transpose_type transpose(
matType const & x);
//! Return the determinant of a mat4 matrix.
//! (From GLM_GTX_simd_mat4 extension).
template <typename T>
typename detail::tmat4x4<T>::value_type determinant(
detail::tmat4x4<T> const & m);
//! Return the inverse of a mat4 matrix.
//! (From GLM_GTX_simd_mat4 extension).
template <typename T>
detail::tmat4x4<T> inverse(
detail::tmat4x4<T> const & m);
}//namespace simd_mat4 }//namespace simd_mat4
}//namespace gtx }//namespace gtx
}//namespace glm }//namespace glm

View File

@ -125,6 +125,60 @@ namespace glm
detail::fvec4SIMD const & b); detail::fvec4SIMD const & b);
}//namespace simd_vec4 }//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 gtx
}//namespace glm }//namespace glm

View File

@ -286,5 +286,87 @@ namespace glm
} }
# endif # endif
}//namespace simd_vec4 }//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 gtx
}//namespace glm }//namespace glm