add faster implementation to clip float to [0;65535] and round

This commit is contained in:
heckflosse 2016-09-21 00:22:42 +02:00
parent 298e91b1a0
commit c67b986744

View File

@ -80,7 +80,7 @@ inline _Tp intp(_Tp a, _Tp b, _Tp c)
// following is valid:
// intp(a, b+x, c+x) = intp(a, b, c) + x
// intp(a, b*x, c*x) = intp(a, b, c) * x
return a * (b-c) + c;
return a * (b - c) + c;
}
template<typename T>
@ -101,5 +101,17 @@ inline T norminf(const T& x, const T& y)
return std::max(std::abs(x), std::abs(y));
}
}
inline int float2uint16range(float d) // clips input to [0;65535] and rounds
{
d = CLIP(d); // clip to [0;65535]
#ifdef __SSE2__ // this only works in IEEE 754 maths. For simplicity I restricted it to SSE2. We can enhance it later, but we have to take care of endianness then.
d += 12582912.f;
return reinterpret_cast<int&>(d);
#else // fall back to slow std::round()
return std::round(d);
#endif
}
}
#endif