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.

Compiler/MSP430FR5969: How to ensure loop unrolling with a loop of compile-time constant number of iterations?

Part Number: MSP430FR5969

Tool/software: TI C/C++ Compiler

I have several loops in my code that iterate based on the value of a #define constant (number of ADC channels in use). The same base code will be applied to several different boards which will have a different value for this constant. I need the performance improvement from loop unrolling, but would like to simply change the value of this constant and not manually write out the loops for each variation. I'm not worried about code size in this application.

From searching around the forum I found the UNROLL and MUST_ITERATE pragmas, but these seem to be only for TMS devices, since they were not recognized when I tried to use them and are not in the MSP430 Compiler User Guide (slau132v).

My optimization settings have been --opt_level = 3 and --opt_for_speed = 5. I also have the --gen_opt_info flag set to level 2, will loop unrolling be documented in the output file? I observe the code size and performance increase when I manually unroll the loops so I know the compiler is not currently unrolling the loops.

How can I tell the compiler that it is okay to unroll these loops?

Thanks.

  • Nathan Graves said:
    How can I tell the compiler that it is okay to unroll these loops?

    Whenever it is practical, write the loop so the number of iterations is a constant, and not a variable.

    in addition, I filed the entry EXT_EP-9858 to request that the pragmas MUST_ITERATE and UNROLL be added to the MSP430 compiler.  You are welcome to follow it with the link below in my signature.

    Thanks and regards,

    -George