Is there a power of function that works with SIMDRegister class?

I have a compressor and to calc the attach and release time I do this

a = pow( 0.01, 1.0 / ( attackMs * sampleRate * 0.001 ) );
r = pow( 0.01, 1.0 / ( releaseMs * sampleRate * 0.001 ) );

where a, r, attackMs and releaseMs are templated so SIMDRegister types. This worked with xsimd and I have a hacky solution but I don’t want to break my template to do it by casting.

For something like this, because the first argument is fixed, you could approximate the function by taking the Taylor series expansion about x=0 and clamp it to the first few terms. What’s nice is that for realistic values of attackMs and releaseMs you really only need the approximation to be close for x in the range (0, 0.2) or so.

Then your pow function reduces to a few multiplies & adds which are already overloaded operators for the SIMDRegister class.


I haven’t done this yet but I’m using the same eqn for calculating my attack/release times in my envelope follower, and I’d like to use the SIMDRegister class as well.

I was thinking of going down the LUT and interpolate route just feels hacky… Your right that I don’t need that part of the code to be performant as it only gets called occasionally. Checking out that series now. cheers

I do feel the SIMDRegister classes need a little more padding out. I have noticed a couple of instances were I have had to modify algo’s because the left hand and right hand sides aren’t operator reversible. hence playing with xsimd lib which I do like but would rather keep all juce if possible.

I’d be curious to see; I suspect this kind of pow approximation would actually be faster than the native pow call. For accuracy on the range (0, 0.2) given an expansion about x=0 you probably only need like 3 terms, so this would then reduce to something like 4 multiplies, 2 adds.

Anyway, again I haven’t done this myself, so let me know what you find :slight_smile:

You could probably do this by bit twiddling the exponents.