Added SIMD optimization for geometric functions

This commit is contained in:
Christophe Riccio 2016-05-28 21:51:38 +02:00
parent fb66c79ca4
commit f6810a9c0e
2 changed files with 25 additions and 2 deletions

View file

@ -76,6 +76,17 @@ namespace detail
return v * inversesqrt(dot(v, v));
}
};
template <typename T, precision P, template <typename, precision> class vecType>
struct compute_faceforward
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & N, vecType<T, P> const & I, vecType<T, P> const & Nref)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'normalize' accepts only floating-point inputs");
return dot(Nref, I) < static_cast<T>(0) ? N : -N;
}
};
}//namespace detail
// length
@ -146,7 +157,7 @@ namespace detail
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'normalize' accepts only floating-point inputs");
return x * inversesqrt(dot(x, x));
return detail::compute_normalize<T, P, vecType>::call(x);
}
// faceforward
@ -159,7 +170,7 @@ namespace detail
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> faceforward(vecType<T, P> const & N, vecType<T, P> const & I, vecType<T, P> const & Nref)
{
return dot(Nref, I) < static_cast<T>(0) ? N : -N;
return detail::compute_faceforward<T, P, vecType>::call(N, I, Nref);
}
// reflect

View file

@ -42,6 +42,18 @@ namespace detail
return result;
}
};
template <precision P>
struct compute_faceforward<float, P, tvec4>
{
GLM_FUNC_QUALIFIER static tvec4<float, P> call(tvec4<float, P> const & N, tvec4<float, P> const & I, tvec4<float, P> const & Nref)
{
__m128 const ffd0 = glm_f32v4_ffd(v.data);
tvec4<float, P> result(uninitialize);
result.data = ffd0;
return result;
}
};
}//namespace detail
}//namespace glm