FloatVectorOperations Divide

Can divide operations be added to this library?  I use these quite a bit and it would be nice if it were built in.

//in BasicOps32

static forcedinline ParallelType div (ParallelType a, ParallelType b) noexcept  { return _mm_div_ps (a, b); }

 

//in BasicOps64

static forcedinline ParallelType div (ParallelType a, ParallelType b) noexcept  { return _mm_div_pd (a, b); }

 

void JUCE_CALLTYPE FloatVectorOperations::copyWithDividend(float* dest, const float* src, float dividend, int num) noexcept 

    {

#if JUCE_USE_VDSP_FRAMEWORK

        vDSP_svdiv(&dividend, src, 1, dest, 1,  (vDSP_Length)num);
   
#else

        JUCE_PERFORM_VEC_OP_SRC_DEST(dest[i] = dividend / src[i], Mode::div(divsd,s),

        JUCE_LOAD_SRC, JUCE_INCREMENT_SRC_DEST,

        const Mode::ParallelType divsd = Mode::load1(dividend);)

#endif

    }

 

void JUCE_CALLTYPE FloatVectorOperations::copyWithDivide (float* dest, const float* src, float divisor, int num) noexcept 

    {

#if JUCE_USE_VDSP_FRAMEWORK

        vDSP_vsdiv(src, 1, &divisor, dest, 1, (vDSP_Length)num);

#else

        JUCE_PERFORM_VEC_OP_SRC_DEST(dest[i] = src[i] / divisor, Mode::div( s,divs),

        JUCE_LOAD_SRC, JUCE_INCREMENT_SRC_DEST,

        const Mode::ParallelType divs = Mode::load1(divisor);)

#endif

}

 

void JUCE_CALLTYPE FloatVectorOperations::divide(float* dest, const float* src1, const float* src2, int num) noexcept 

    {

#if JUCE_USE_VDSP_FRAMEWORK

        vDSP_vdiv(src2,1,src1,1,dest,1, (vDSP_Length) num);

#else

        JUCE_PERFORM_VEC_OP_SRC1_SRC2_DEST(dest[i] = src2[i] / src1[i], Mode::div(s1, s2), JUCE_LOAD_SRC1_SRC2, JUCE_INCREMENT_SRC1_SRC2_DEST, )

#endif

    }

Thanks,

Darren

 

 

Thanks - yes, we're planning on adding a lot more DSP functionality soon!

bump… would really love to have an optimized buffer division in floatVectorOperations.

1 Like

+1
And optimized buffer trunc, modf please:
my post

+1!

Should be moved into the new category Feature Requests, so people can vote for it…

Please vote for my feature request :slight_smile:

but why? can’t you basically do

auto numInv = 1.f / num;
FloatVectorOperations::multiply(data, numInv, numSamples);

i would also like there to be more floatvectoroperations tho. for example modulo and maybe one or some for dry wet operations like a + m * (b - a), where a, b and m are all buffers of blockSize, because of parameter smoothing etc

That’s not realy the same. In your example the divider is constant, which allows the alternative version. But the feature request is about getting the inverse of each value in the array, like this pseudo code:

for (size_t i=0; i < vector.size(); ++i)
    vector [i] = 1.0 / vector [i];

(at least that’s the interesting one. The FR mentions different formulas)

oh oops. didn’t think of that. you’re absolutely right! that reminds me. a floatVectorOp of sqrt buffers would be cool too. (used for instance in equal loudness curve dry/wet).

also one for 1 - x, with x being the buffer

This is possible in two passes:

multiply (ptr, -1.0f, numValues);
add (ptr, 1.0f, numValues);

not sure it helps, not knowing the use case…

1 Like