From f6810a9c0e6f463e4afa2a9d53b41d4559584a82 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 28 May 2016 21:51:38 +0200 Subject: [PATCH] Added SIMD optimization for geometric functions --- glm/detail/func_geometric.inl | 15 +++++++++++++-- glm/detail/func_geometric_simd.inl | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/glm/detail/func_geometric.inl b/glm/detail/func_geometric.inl index 317b2879..90d3741b 100644 --- a/glm/detail/func_geometric.inl +++ b/glm/detail/func_geometric.inl @@ -76,6 +76,17 @@ namespace detail return v * inversesqrt(dot(v, v)); } }; + + template class vecType> + struct compute_faceforward + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & N, vecType const & I, vecType const & Nref) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); + + return dot(Nref, I) < static_cast(0) ? N : -N; + } + }; }//namespace detail // length @@ -146,7 +157,7 @@ namespace detail { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); - return x * inversesqrt(dot(x, x)); + return detail::compute_normalize::call(x); } // faceforward @@ -159,7 +170,7 @@ namespace detail template class vecType> GLM_FUNC_QUALIFIER vecType faceforward(vecType const & N, vecType const & I, vecType const & Nref) { - return dot(Nref, I) < static_cast(0) ? N : -N; + return detail::compute_faceforward::call(N, I, Nref); } // reflect diff --git a/glm/detail/func_geometric_simd.inl b/glm/detail/func_geometric_simd.inl index 99d60eb1..8bab4c69 100644 --- a/glm/detail/func_geometric_simd.inl +++ b/glm/detail/func_geometric_simd.inl @@ -42,6 +42,18 @@ namespace detail return result; } }; + + template + struct compute_faceforward + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const & N, tvec4 const & I, tvec4 const & Nref) + { + __m128 const ffd0 = glm_f32v4_ffd(v.data); + tvec4 result(uninitialize); + result.data = ffd0; + return result; + } + }; }//namespace detail }//namespace glm