Merge pull request #1425 from tresf/stable-1.1

Cleanup fmaf() usage, move to lmms_math.h
This commit is contained in:
Vesa V
2014-12-09 17:27:07 +02:00
2 changed files with 36 additions and 21 deletions

View File

@@ -32,6 +32,7 @@
#include <math.h>
#include "lmms_constants.h"
#include "lmms_math.h"
inline float hermiteInterpolate( float x0, float x1, float x2, float x3,
float frac_pos )
@@ -80,32 +81,13 @@ inline float cubicInterpolate( float v0, float v1, float v2, float v3, float x )
inline float cosinusInterpolate( float v0, float v1, float x )
{
const float f = ( 1.0f - cosf( x * F_PI ) ) * 0.5f;
#ifdef FP_FAST_FMAF
#ifndef __clang__
return fmaf( f, v1-v0, v0 );
#else
return fma( f, v1-v0, v0 );
#endif
#else
return f * (v1-v0) + v0;
#endif
// return( v0*f + v1*( 1.0f-f ) );
return fastFmaf( f, v1-v0, v0 );
}
inline float linearInterpolate( float v0, float v1, float x )
{
// take advantage of fma function if present in hardware
#ifdef FP_FAST_FMAF
#ifndef __clang__
return fmaf( x, v1-v0, v0 );
#else
return fma( x, v1-v0, v0 );
#endif
#else
return x * (v1-v0) + v0;
#endif
return fastFmaf( x, v1-v0, v0 );
}

View File

@@ -130,7 +130,40 @@ static inline int fast_rand()
return( (unsigned)( next / 65536 ) % 32768 );
}
//! @brief Takes advantage of fmal() function if present in hardware
static inline long double fastFmal( long double a, long double b, long double c ) {
#ifdef FP_FAST_FMAL
#ifdef __clang__
return fma( a, b, c );
#else
return fmal( a, b, c );
#endif
#else
return a * b + c;
#endif
}
//! @brief Takes advantage of fmaf() function if present in hardware
static inline float fastFmaf( float a, float b, float c ) {
#ifdef FP_FAST_FMAF
#ifdef __clang__
return fma( a, b, c );
#else
return fmaf( a, b, c );
#endif
#else
return a * b + c;
#endif
}
//! @brief Takes advantage of fma() function if present in hardware
static inline double fastFma( double a, double b, double c ) {
#ifdef FP_FAST_FMA
return fma( a, b, c );
#else
return a * b + c;
#endif
}
// source: http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
static inline double fastPow( double a, double b )