Skip to content

Commit

Permalink
Cleanup lmms_math.h (#7382)
Browse files Browse the repository at this point in the history
* simplified fraction and absfraction functions

* removed unused fastSqrt() and fastPow()  
functions

* unused absMin() and absMax()

* move roundAt to math header

* Code review from saker

Co-authored-by: saker <sakertooth@gmail.com>

* use std::trunc()

* fixup after fixing merge conflicts

* remove unused fastFma and fastFmal functions.

* remove lmms_basics include, not needed

* use signedPowf from lmms_math in NES

* removed fastRand function, unused

* remove unused sinc function

* cleanup signedPowf

* code review

* further simplify random number math

* removed static from lmms_math file

---------

Co-authored-by: saker <sakertooth@gmail.com>
  • Loading branch information
Rossmaxx and sakertooth committed Aug 28, 2024
1 parent ff8c470 commit a992019
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 225 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 = v3 + 3*v1;
float t1 = std::fma(v1, 3, v3);

return( v1 + fastFmaf( 0.5f, frcu, x ) * ( v2 - frcu * ( 1.0f/6.0f ) -
fastFmaf( t1, ( 1.0f/6.0f ), -v0 ) * ( 1.0f/3.0f ) ) + frsq * x * ( t1 *
( 1.0f/6.0f ) - 0.5f * v2 ) + frsq * fastFmaf( 0.5f, v2, -v1 ) );
return (v1 + std::fma(0.5f, frcu, x) * (v2 - frcu * (1.0f / 6.0f) -
std::fma(t1, (1.0f / 6.0f), -v0) * (1.0f / 3.0f)) + frsq * x * (t1 *
(1.0f / 6.0f) - 0.5f * v2) + frsq * std::fma(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 fastFmaf( f, v1-v0, v0 );
return std::fma(f, v1 - v0, v0);
}


inline float linearInterpolate( float v0, float v1, float x )
{
return fastFmaf( x, v1-v0, v0 );
return std::fma(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 fastFmaf( fastFmaf( fastFmaf( c3, z, c2 ), z, c1 ), z, c0 );
return std::fma(std::fma(std::fma(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 fastFmaf( fastFmaf( fastFmaf( c3, z, c2 ), z, c1 ), z, c0 );
return std::fma(std::fma(std::fma(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 fastFmaf( fastFmaf( fastFmaf( c3, x, c2 ), x, c1 ), x, c0 );
return std::fma(std::fma(std::fma(c3, x, c2), x, c1), x, c0);
}


Expand Down
Loading

0 comments on commit a992019

Please sign in to comment.