Added multiple 'sign' implementations for integers, unit tests and performancetests.

This commit is contained in:
Christophe Riccio
2014-10-29 00:18:41 +01:00
parent 378074ee66
commit dced21e745
5 changed files with 248 additions and 19 deletions

View File

@@ -43,11 +43,12 @@ namespace detail
template <typename genFIType>
struct compute_abs<genFIType, true>
{
GLM_FUNC_QUALIFIER static genFIType call(genFIType const & x)
GLM_FUNC_QUALIFIER static genFIType call(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_iec559 || std::numeric_limits<genFIType>::is_signed,
"'abs' only accept floating-point and integer scalar or vector inputs");
return x >= genFIType(0) ? x : -x;
// TODO, perf comp with: *(((int *) &x) + 1) &= 0x7fffffff;
}
@@ -56,7 +57,7 @@ namespace detail
template <typename genFIType>
struct compute_abs<genFIType, false>
{
GLM_FUNC_QUALIFIER static genFIType call(genFIType const & x)
GLM_FUNC_QUALIFIER static genFIType call(genFIType x)
{
GLM_STATIC_ASSERT(
!std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
@@ -130,6 +131,13 @@ namespace detail
}//namespace detail
// abs
template <>
GLM_FUNC_QUALIFIER int32 abs(int32 x)
{
int32 const y = x >> 31;
return (x ^ y) - y;
}
template <typename genFIType>
GLM_FUNC_QUALIFIER genFIType abs(genFIType x)
{