Skip to content

Commit

Permalink
Remove fastFma
Browse files Browse the repository at this point in the history
  • Loading branch information
messmerd committed Sep 25, 2024
1 parent 47c8295 commit e82932a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 47 deletions.
18 changes: 9 additions & 9 deletions include/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ inline float cubicInterpolate( float v0, float v1, float v2, float v3, float x )
{
float frsq = x * x;
float frcu = frsq * v0;
float t1 = fastFma(v1, 3.f, v3);
float t1 = v1 * 3.f + v3;

return (v1 + fastFma(0.5f, frcu, x) * (v2 - frcu * (1.0f / 6.0f) -
fastFma(t1, (1.0f / 6.0f), -v0) * (1.0f / 3.0f)) + frsq * x * (t1 *
(1.0f / 6.0f) - 0.5f * v2) + frsq * fastFma(0.5f, v2, -v1));
return v1 + (0.5f * frcu + x) * (v2 - frcu * (1.0f / 6.0f) -
(t1 * (1.0f / 6.0f) - v0) * (1.0f / 3.0f)) + frsq * x * (t1 *
(1.0f / 6.0f) - 0.5f * v2) + frsq * (0.5f * v2 - v1);
}



inline float cosinusInterpolate( float v0, float v1, float x )
{
const float f = ( 1.0f - cosf( x * F_PI ) ) * 0.5f;
return fastFma(f, v1 - v0, v0);
return f * (v1 - v0) + v0;
}


inline float linearInterpolate( float v0, float v1, float x )
{
return fastFma(x, v1 - v0, v0);
return x * (v1 - v0) + v0;
}


Expand All @@ -104,7 +104,7 @@ inline float optimalInterpolate( float v0, float v1, float x )
const float c2 = even * -0.004541102062639801;
const float c3 = odd * -1.57015627178718420;

return fastFma(fastFma(fastFma(c3, z, c2), z, c1), z, c0);
return ((c3 * z + c2) * z + c1) * z + c0;
}


Expand All @@ -121,7 +121,7 @@ inline float optimal4pInterpolate( float v0, float v1, float v2, float v3, float
const float c2 = even1 * -0.246185007019907091 + even2 * 0.24614027139700284;
const float c3 = odd1 * -0.36030925263849456 + odd2 * 0.10174985775982505;

return fastFma(fastFma(fastFma(c3, z, c2), z, c1), z, c0);
return ((c3 * z + c2) * z + c1) * z + c0;
}


Expand All @@ -132,7 +132,7 @@ inline float lagrangeInterpolate( float v0, float v1, float v2, float v3, float
const float c1 = v2 - v0 * ( 1.0f / 3.0f ) - v1 * 0.5f - v3 * ( 1.0f / 6.0f );
const float c2 = 0.5f * (v0 + v2) - v1;
const float c3 = ( 1.0f/6.0f ) * ( v3 - v0 ) + 0.5f * ( v1 - v2 );
return fastFma(fastFma(fastFma(c3, x, c2), x, c1), x, c0);
return ((c3 * x + c2) * x + c1) * x + c0;
}


Expand Down
38 changes: 0 additions & 38 deletions include/lmms_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,6 @@ static void roundAt(T& value, const T& where, const T& stepSize)
}
}

//! Uses `x * y + z` or `std::fma` - whichever is faster
template<typename T>
inline T fastFma(T x, T y, T z);

//! Uses `x * y + z` or `std::fma` - whichever is faster
template<>
inline float fastFma(float x, float y, float z)
{
#ifdef FP_FAST_FMAF
return std::fma(x, y, z);
#else
return x * y + z;
#endif // FP_FAST_FMAF
}

//! Uses `x * y + z` or `std::fma` - whichever is faster
template<>
inline double fastFma(double x, double y, double z)
{
#ifdef FP_FAST_FMA
return std::fma(x, y, z);
#else
return x * y + z;
#endif // FP_FAST_FMA
}

//! Uses `x * y + z` or `std::fma` - whichever is faster
template<>
inline long double fastFma(long double x, long double y, long double z)
{
#ifdef FP_FAST_FMAL
return std::fma(x, y, z);
#else
return x * y + z;
#endif // FP_FAST_FMAL
}


//! Source: http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
inline double fastPow(double a, double b)
{
Expand Down

0 comments on commit e82932a

Please sign in to comment.