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.

Optimization level 2+ breaks my CLA code

Is there a way to turn off or have a different level of optimization for CLA code and leave it at a different level for all other code?

My algorithm used to be completely on the C28x core (on F28069) and I used to be able to run the code fine with --opt_level=4, then I moved the algorithm to the CLA (coded in C).

After that change, my code runs fine with --opt_level=1 but when I go to level 2, something gets broken.

I tried making all my variables in the CLA volatile, but that didn't seem to help.

  • In SPRU514G, it lists that level 2 is level 1 plus:

    • –  Performs loop optimizations

    • –  Eliminates global common subexpressions

    • –  Eliminates global unused assignments

    • –  Performs loop unrolling 

    Something in here must be breaking the code.  Are there any tips to find out which is causing the code to break?

  • OK, I found what was doing it.  I think in level 2 it was the loop optimization ... or was it the loop unrolling?

    I have the following global variable in my header file

    extern Uint16 ADC_SAMPLES_READY;

    and initialized in my main.c

    #pragma DATA_SECTION(ADC_SAMPLES_READY, "CpuToClaMsgRAM");
    Uint16 ADC_SAMPLES_READY = 0;
    

    Now, in my CLA task I have a loop that wait's until the ADC_SAMPLES_READY flag is set by the CPU

    while(!ADC_SAMPLES_READY);

    My guess is that the optimization simplifies the loop and assumes ADC_SAMPLES_READY doesn't get modified and then just gets stuck in that loop.

    Making ADC_SAMPLES_READY volatile seems to fix this and tells the compiler not to optimize statements using this variable.

    Can anyone provide any insights or more details on what is going on here and how to carefully avoid optimization pitfalls?

  • Fulano de Tal,

    What you describe is very probable.  ADC_SAMPLES_READY was most likely seen as a constant and therefore your while loop was seen as unnecessary during compile-time.

    There is a short list of potential gotchas while using the optimizer in the C2000 wiki.
    http://processors.wiki.ti.com/index.php/C28x_Code_Generation_Tips_and_Tricks#Optimization
    Perhaps it and the 'TMS320C28x Optimizing C/C++ Compiler User's Guide' will add some insight


    Thank you,
    Brett