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.

TMS320F28069: CGT C2000 does not replace sqrt of literal at compile time

Part Number: TMS320F28069

Hello CGT C2000 support team,

I noticed that the compiler does not optimize the following at compile time:

sqrt(2)

Instead, the generated assembly shows that an actual runtime call to sqrt is made.

I guess that this behavior fundamentally makes sense, as sqrt() is just a function call, and the compiler cannot really be expected to know what a function will return.

However, it seems that it would make sense for the compiler to recognize certain standard math functions, and to evaluate constant expressions.

After all, it does recognize sqrt, sin, cos, atan and atan2 in the context of utilizing the TMU.

Are there any configurations that can be made to also enable the compiler to optimize constant expressions using those functions?

Thank you in advance,

Beat

  • Beat, the F28069 doesn't have a TMU, which could have helped with the sqrt calculation in fp_mode=relaxed, so that isn't applicable here. So I'll pass along your question to the compiler experts to see if they have any comments.

    Thanks,

    Sira

  • Hi Sira - I understand that the F28069 does not have a TMU.

    This question is in regard to the C2000 CGT, not a particular C2000 device.

  • Are there any configurations that can be made to also enable the compiler to optimize constant expressions using those functions?

    Yes.  If you build with options similar to ...

    --fp_mode=relaxed --tmu_support=tmu0 --opt_level=2

    ... then sqrt(2) is replaced with a constant.  To learn about these options, please search for them in the C28x compiler manual.

    Please understand that if the data sheet for your C28x device does not specify that a TMU is available, then you cannot use the option --tmu_support.

    Thanks and regards,

    -George