Quantcast
Channel: KVR Audio
Viewing all articles
Browse latest Browse all 4847

DSP and Plugin Development • Re: little questions from old dev about C++ today style/portability

$
0
0
Checking godbolt, at least clang inlines std::pow(x, 11.f) into a series of multiplies if (and only if) you specify -ffast-math so whether you want to rely on that is kinda up to you.
Thanks, I used to write a series of multiplies for some pow(float, int) , but I wondered if it's still necessary, since I saw some new DSP code always using pow(). Now, I mostly use MSVC with 'precise' flag, so with your example I see that a series of multiplies is still good to go.
The rationale for min/max clipping the argument and then processing the result is that this compiles into branchless code. On x86-64 clang always compiles these to MINPS/MAXPS where as on aarch64 for some reason you need -ffast-math to get fminnm/fmaxnm (without -ffast-math you get fcmp+fsel, no idea what's the deal with that). With other compilers you can probably expect the same. Branching on audio samples is generally really bad, because it's essentially unpredictable (where as the min/max is something like 2-3 cycles of extra latency per op) and you don't need to take all that many branch prediction misses before it's basically the bulk of your processing cost.
OK, I see. I thought also min/max would produce a conditional move in assembly, but, having read many of you other posts here on KVR, if you say it's branchless I'm going to trust you. Thx again.

Statistics: Posted by liqih — Sun Sep 15, 2024 9:55 pm



Viewing all articles
Browse latest Browse all 4847

Trending Articles