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: Built-In functions for complex numbers

Part Number: TMS320F280049

Hello,

for some calculations in my project I need to work with complex numbers. I am working in CCS Version: 11.0.0.00012 with the compiler TI v21.6.0.LTS1. The microcontroller F280049 has a CPU-Clock of 96 MHz.

Using the header <complex.h>, there are built-in functions to calculate e.g. the argument, the absolute value or the square root of a complex number. But those functions seem to be highly inefficient.

For example:

When I use cargf(x) to calculate the argument of x, I need around 13 µs. But when I use atan2f(cimagf(x), crealf(x)) instead, it takes less than 1 µs.

I get similar results when using cabsf etc.

So now I am wondering, why there is such a difference in the time.
Is it wrong to use these functions?
Do I maybe need to set something in the project properties, such that the compiler translates the function calls to the correct instructions?


Kind regards,
Michael
  • Hello Michael,

    When I use cargf(x) to calculate the argument of x, I need around 13 µs. But when I use atan2f(cimagf(x), crealf(x)) instead, it takes less than 1 µs.

    I'm not very familiar with these compiler intrinsics, but based on what I've researched it may be because the atan2f function which is being used, as the cimagf and crealf are themselves not a very complex function. You can look at the disassembly that is executed while debugging your code to verify this (assembly step-into the functions as needed).

    Is it wrong to use these functions?

    This is more for you to decide, if it works but it takes longer than you need to decide whether the efficiency matters.

    Do I maybe need to set something in the project properties, such that the compiler translates the function calls to the correct instructions?

    Are they not calling the correct instructions? Or are you trying to use some library and instead it's calling the compiler intrinsics?

  • Hello Omer,

    Thanks for your reply.

    I did look at the code and the disassembly while debugging. But strangely the cargf function does exactly what I did to replace it (see the screenshot).

    But it shouldn't take 10 µs (and more) to execute the same code just because it is separated in its own function. Right?

  • Hello Michael,

    But it shouldn't take 10 µs (and more) to execute the same code just because it is separated in its own function. Right?

    This depends on the way the compiler generates the assembly code, you will need to do a comparison of all the code executed as part of the cargf (including both the function call and the function itself) and the atan2f code (function call plus the function itself). While I don't know if it would produce a 10us difference, calling a function within a function will inherently require more execution time than just calling the function directly, especially because the functions here don't seem to be inline functions.

    If you thoroughly compare the assembly directly though, it should explain the execution time difference since the number/type of instructions is what's leading to the difference.