From 5ced0c083f33ba798e9b2174b76e80fc972b005d Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 5 Apr 2014 01:18:15 +0300 Subject: [PATCH] Optimize linear interpolation function --- include/interpolation.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/interpolation.h b/include/interpolation.h index 4ff582775..8b8fe91ea 100644 --- a/include/interpolation.h +++ b/include/interpolation.h @@ -23,8 +23,8 @@ */ -#ifndef _INTERPOLATION_H -#define _INTERPOLATION_H +#ifndef INTERPOLATION_H +#define INTERPOLATION_H #ifndef __USE_XOPEN #define __USE_XOPEN @@ -87,7 +87,13 @@ inline float cosinusInterpolate( float v0, float v1, float x ) inline float linearInterpolate( float v0, float v1, float x ) { - return( v0*( 1.0f-x ) + v1*x ); +// take advantage of fma function if present in hardware + +#ifdef FP_FAST_FMAF + return fmaf( x, v1-v0, v0 ); +#else + return x * (v1-v0) + v0; +#endif }