There was a SIMD talk I saw I’ll have to dig up which talked about avoiding vector sizes that are exact
powers of 2 for best performance.
I tried 511 items here instead of 512 and it seems to put vDSP_vsmsma back on top on my machine:
benchmark name samples iterations estimated
mean low mean high mean
std dev low std dev high std dev
-------------------------------------------------------------------------------
loop 100 401 2.2456 ms
56.2942 ns 56.2568 ns 56.3472 ns
0.225151 ns 0.172133 ns 0.331674 ns
FloatVectorOperations copy then add 100 279 2.2599 ms
83.288 ns 81.6942 ns 85.7759 ns
10.0145 ns 7.1822 ns 14.0543 ns
vDSP_vsmsma 100 472 2.2656 ms
47.617 ns 47.361 ns 48.3056 ns
1.96311 ns 0.832855 ns 3.89036 ns
code
SECTION ("nerd sniped")
{
// use audio blocks to ensure alignment
juce::HeapBlock<char> aData;
juce::dsp::AudioBlock<float> a = { aData, 1, 511 };
juce::HeapBlock<char> bData;
juce::dsp::AudioBlock<float> b = { bData, 1, 511 };
juce::HeapBlock<char> resultData;
juce::dsp::AudioBlock<float> result = { resultData, 1, 511 };
float alpha = 3.5f;
float beta = 1.2f;
BENCHMARK ("loop")
{
for (int i = 0; i < (int) result.getNumSamples(); ++i)
{
result.setSample(0, i, alpha * a.getSample(0, i) + beta * b.getSample(0, i));
}
return result.getChannelPointer(0);
};
BENCHMARK ("FloatVectorOperations copy then add")
{
juce::FloatVectorOperations::copyWithMultiply (result.getChannelPointer(0), a.getChannelPointer(0), alpha, result.getNumSamples());
juce::FloatVectorOperations::addWithMultiply (result.getChannelPointer(0), b.getChannelPointer(0), beta, result.getNumSamples());
return result.getChannelPointer(0);
};
BENCHMARK ("vDSP_vsmsma")
{
vDSP_vsmsma (a.getChannelPointer(0), 1, &alpha, b.getChannelPointer(0), 1, &beta, result.getChannelPointer(0), 1, result.getNumSamples());
return result.getChannelPointer(0);
};