Reintroduce fast math functions (#7495)

* Add fast fma functions

* Use fast fma functions

* Add fast pow function

* Use fast pow function

* Fix build

* Remove fastFma

* Avoid UB in fastPow

On GCC with -O1 or -O2 optimizations, this new implementation generates
identical assembly to the old union-based implementation
This commit is contained in:
Dalton Messmer
2024-10-01 14:35:15 -04:00
committed by GitHub
parent 860749a8a1
commit 121d608c3a
4 changed files with 30 additions and 15 deletions

View File

@@ -64,7 +64,7 @@ public:
{
for( fpp_t frame = 0; frame < frames; ++frame )
{
const double gain = 1 - std::pow((m_counter < m_length) ? m_counter / m_length : 1, m_env);
const double gain = 1 - fastPow((m_counter < m_length) ? m_counter / m_length : 1, m_env);
const sample_t s = ( Oscillator::sinSample( m_phase ) * ( 1 - m_noise ) ) + ( Oscillator::noiseSample( 0 ) * gain * gain * m_noise );
buf[frame][0] = s * gain;
buf[frame][1] = s * gain;
@@ -80,7 +80,7 @@ public:
m_FX.nextSample( buf[frame][0], buf[frame][1] );
m_phase += m_freq / sampleRate;
const double change = (m_counter < m_length) ? ((m_startFreq - m_endFreq) * (1 - std::pow(m_counter / m_length, m_slope))) : 0;
const double change = (m_counter < m_length) ? ((m_startFreq - m_endFreq) * (1 - fastPow(m_counter / m_length, m_slope))) : 0;
m_freq = m_endFreq + change;
++m_counter;
}

View File

@@ -858,7 +858,7 @@ inline sample_t MonstroSynth::calcSlope( int slope, sample_t s )
{
if( m_parent->m_slope[slope] == 1.0f ) return s;
if( s == 0.0f ) return s;
return std::pow(s, m_parent->m_slope[slope]);
return fastPow(s, m_parent->m_slope[slope]);
}