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.

F28M35H52C: Execution time of a mathematical expression in C.

Part Number: F28M35H52C

Hello, I am trying to embeed a synchronous machine simulator in a F28M35H52C1 Concerto Microcontroller using C language. It is supposed to be a real time simulator so execution time is important. Regarding this, I have some doubts about how mathematical expressions are "translated" into assembler. For example, this is an actual sentence of my code:

*(*(A + k1) + k2) = (-(b + i)->p_coef[0] * sq_module_u + ((b + i)->p_coef[0] * (b + i)->u_i - (b + i)->q_coef[0] * (b + i)->u_r) * 2 * (b + i)->u_i) / sq_sq_module_u + (-(b + i)->p_coef[1] * module_u + ((b + i)->p_coef[1] * (b + i)->u_i - (b + i)->q_coef[1] * (b + i)->u_r) * (b + i)->u_i / module_u) / sq_module_u - (b + i)->p_coef[2];

It does not annoy me such a long expression but, could it decrease the program performance somehow? Should I split the line into other shorter ones? I do not know if it is useful to say so but I am using 32 bits floats and the FPU.

Thanks in advance.

  • Hello,

    Ideally, the compiler should be able to parse this line of code and produce the most optimal set of assembly instructions to execute the intended outcome. The entirety of this work is done during compile time, so in theory, performance should not be affected. While unlikely, have you noticed any cases where different assembly routines are produced based on how you arrange this line of code?

    Thanks,
    Taumer
  • Ok, thanks for the answer. I have not noticed anything yet but I will try to do some tests.
    Román.