This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280049: fmodf function equivalant for CLA

Part Number: TMS320F280049


Hy,

Would it be possible to have an equivalant of the (float32_t)fmodf(float32_t a, float32_t b) function (int math.h library) for the CLA?

As an example, fmodf(10.5f,3.2f) = 0.9f with math.h function on the CPU.

Best regards.

  • Hello,

    Due to US holiday, please expect a response by 20th February.

    Thanks & Regards,

    Sinchita

  • Frank,

    An efficient way of implementing fmodf(a,b) is a - (int)(a/b) x b

    This has been implemented on the C2000 side, where in fp_mode=relaxed, it uses TMU division instructions and thereby speeds up the computation.

    A similar approach can be followed on the CLA as well. You can replace the division / with CLAdiv_inline() in CLAmath.h for efficient implementation.

    You can create an inline function like CLAfmodf_inline() and put it in CLAmath.h

    Thanks,

    Sira

  • Hy Sira,

    I've already tried this solution but, for time efficiency purpose, I have to keep fp_mode=strict and :

     - First, int32 max (idem for negatives) is much less that float32 max, so this doesn't work when a is much higher than b,

     - Secondly, even if a/b is lower than int32 max, it quickly lose precision (try fmodf(25000.0f,2.0*M_PI) both with math.h function and a - (int)(a/b) x b and you will see the difference...)

    I need a function that is as efficient as fmodf what ever a and b values are... and believe me, this is not so simple...

    Best regards

  • Frank,

    You raise some interesting points, let me dig into this a bit more and get back to you.

    Thanks,

    Sira

  • Frank,

    Apologies for the delay on this. I have reached out to some subject matter experts for advice on this.

    I suppose a/b can exceed int32_t range is what you're saying.

    And even if we replace int32_t with a long long type (OR a/b is within the int32_t range), we don't get the necessary precision?

    Could you provide the results you are getting for your specific test case above?

    Thanks,

    Sira

  • Here is what our architect suggested:

    // Function returns F32 remainder of a/b

    float return_float_remainder ( float a, float b) {

     

        float value;

        float i, f, retval;

     

        /* Assign the value we will calculate the modf of */

        value = a/b; // Do a floating point division. On the newer C28 parts, we have a HW accelerator to do this. On older ones, we can use TMU

     

        /* Calculate the modf of the value returning the fractional and integral parts */

        f = modf(value, &i);

        // We have a FRACF32 instruction in C28 FPU to get the fractional part. So, we don’t have to use the library function modf, but can use the FRACF32 to get the fractional part.

    // CLA also has a mfracf32 intrinsic

     

       retval = f*b;

       return retval;

    }

    All options have some form of range and accuracy trade-off.