diff --git a/glm/detail/func_geometric.inl b/glm/detail/func_geometric.inl index d83a965c..317b2879 100644 --- a/glm/detail/func_geometric.inl +++ b/glm/detail/func_geometric.inl @@ -51,6 +51,31 @@ namespace detail return (tmp.x + tmp.y) + (tmp.z + tmp.w); } }; + + template + struct compute_cross + { + GLM_FUNC_QUALIFIER static tvec3 call(tvec3 const & x, tvec3 const & y) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'cross' accepts only floating-point inputs"); + + return tvec3( + x.y * y.z - y.y * x.z, + x.z * y.x - y.z * x.x, + x.x * y.y - y.x * x.y); + } + }; + + template class vecType> + struct compute_normalize + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); + + return v * inversesqrt(dot(v, v)); + } + }; }//namespace detail // length @@ -104,12 +129,7 @@ namespace detail template GLM_FUNC_QUALIFIER tvec3 cross(tvec3 const & x, tvec3 const & y) { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'cross' accepts only floating-point inputs"); - - return tvec3( - x.y * y.z - y.y * x.z, - x.z * y.x - y.z * x.x, - x.x * y.y - y.x * x.y); + return detail::compute_cross::call(x, y); } // normalize diff --git a/glm/detail/func_geometric_simd.inl b/glm/detail/func_geometric_simd.inl index c02b6499..99d60eb1 100644 --- a/glm/detail/func_geometric_simd.inl +++ b/glm/detail/func_geometric_simd.inl @@ -14,6 +14,34 @@ namespace detail return _mm_cvtss_f32(dot0); } }; + + template + struct compute_cross + { + GLM_FUNC_QUALIFIER static tvec3 call(tvec3 const & a, tvec3 const & b) + { + __m128 const set0 = _mm_set_ps(0.0f, a.z, a.y, a.x); + __m128 const set1 = _mm_set_ps(0.0f, b.z, b.y, b.x); + __m128 const xpd0 = glm_f32v4_xpd(set0, set1); + + tvec4 result(uninitialize); + result.data = xpd0; + + return tvec3(result); + } + }; + + template + struct compute_normalize + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const & v) + { + __m128 const nrm0 = glm_f32v4_nrm(v.data); + tvec4 result(uninitialize); + result.data = nrm0; + return result; + } + }; }//namespace detail }//namespace glm