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/TMS320F28379D: GPIO pin control - code optimization

Part Number: TMS320F28379D

Tool/software: TI C/C++ Compiler

I have a routine running at 400 kHz that toggles several IOs.

I have learned that interrupt entry and exit consume 10+ cycles and so I need to optimize the actual code within the interrupt.

The following code requires a number of cycles.  What could be done to reduce the number of cycles?  Each instruction/cycle is 5 ns but at 400 kHz it is 0.2% of the overall CPU time.

#define Z_WRITE     GpioDataRegs.GPADAT.bit.GPIO11

430         Z_WRITE = enc_emu.z_vec[enc_emu.which_vector][enc_emu.counter_10kHz][1]

        C$L23:

0085a9:   761F0445    MOVW         DP, #0x445

0085ab:   2D03        MOV          T, @0x3

0085ac:   8F4110A3    MOVL         XAR5, #0x0110a3

0085ae:   3550        MPYB         ACC, T, #80

0085af:   560100A5    ADDL         @XAR5, ACC

0085b1:   3B01        SETC         SXM

0085b2:   761F0442    MOVW         DP, #0x442

0085b4:   56030120    MOV          ACC, @0x20 << 1

0085b6:   07A5        ADDL         ACC, @XAR5

0085b7:   8AA9        MOVL         XAR4, @ACC

0085b8:   761F01FC    MOVW         DP, #0x1fc

0085ba:   CD00F7FF    AND          AH, @0x0, #0xf7ff

0085bc:   92CC        MOV          AL, *+XAR4[1]

0085bd:   9001        ANDB         AL, #0x1

0085be:   FF8A        LSL          AL, 11

0085bf:   CAA8        OR           AL, @AH

0085c0:   9600        MOV          @0x0, AL

  • Anytime performance is not good enough, it is time to be sure optimization is enabled.  The compiler build option is --opt_level=number, where number can be 0 through 4.  Higher numbers mean more optimization.

    Thanks and regards,

    -George

  • Thank you for your help.

    Enabling the -o2 optimization did little to the output assembly in terms of number of cycles.

    Let me rephrase my question: is this the most efficient way to write the statement? e.g., would a simple 1-d array be faster than my 2-array (although the array size is [2][40]). Is there a cycle penalty associated with accessing structure elements?

  • Considering the original source code ...

    Tomas Sadilek1 said:

    #define Z_WRITE     GpioDataRegs.GPADAT.bit.GPIO11

    430         Z_WRITE = enc_emu.z_vec[enc_emu.which_vector][enc_emu.counter_10kHz][1]

    A good way to make things faster is for variables to reside in registers rather than memory.  While the compiler may put a structure member in a register, it is even more likely to put a local variable in a register.  So, try rewriting this code to use as many local variables (or even function parameters) as possible.  I cannot guarantee this will improve things.  But it is worth the attempt.

    Thanks and regards,

    -George