stepcompress: Optimize safe_sqrt() code

Optimize the code by putting the uncommon case out-of-line.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-11-14 15:12:53 -05:00
parent 5a1ec817d4
commit fd7cb99f47
1 changed files with 8 additions and 3 deletions

View File

@ -256,16 +256,21 @@ check_line(struct stepcompress *sc, struct step_move move)
* Step compress interface
****************************************************************/
#define likely(x) __builtin_expect(!!(x), 1)
// Wrapper around sqrt() to handle small negative numbers
static inline double
safe_sqrt(double v)
static double
_safe_sqrt(double v)
{
if (v < 0. && v > -0.001)
if (v > -0.001)
// Due to floating point truncation, it's possible to get a
// small negative number - treat it as zero.
return 0.;
return sqrt(v);
}
static inline double safe_sqrt(double v) {
return likely(v >= 0.) ? sqrt(v) : _safe_sqrt(v);
}
// Allocate a new 'stepcompress' object
struct stepcompress *