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.

TMS320F28375S: C compiler

Part Number: TMS320F28375S


Hello, I am writing for a question regarding the C2000 DSP C compiler
(Code Composer Studio 8.0.0.00016, Compiler version 21.6.0.LTS, DSP TMS320F28375S).
Here are two examples of translation, in which:

acc         32 bit unsigned (DSP accumulator)
res         16 bit unsigned local variable

1)  C code              acc += (((Uint16)(acc >> 16)) << 4);
                        res = acc + 1;

    ASM code            ADD     ACC,AH<<#4      ; SXM = 0
    expected            ADD     ACC,#1
                        MOV     PL,AL

    ASM code            MOVL    P,ACC
    from compiler       MOV     ACC,PH << #4
                        MOVZ    AR7,AL
                        MOVL    ACC,P
                        ADDU    ACC,AR7
                        MOVL    P,ACC
                        MOV     AL,PL
                        ADDB    AL,#1
                        MOV     PL,AL

2)  C code              res = acc + (((Uint16)(acc >> 16)) << 4) +1;

    ASM code            ADD     ACC,AH<<#4      ; SXM = 0
    expected            ADD     ACC,#1
                        MOV     PL,AL

    ASM code            MOVZ    AR4,AL
    from compiler       MOV     ACC,AH << #4
                        ADD     AR4,AL
                        ADDB    XAR4,#1
                

The ASM code from compiler of example 2 is not the expected code (ie what I would have written), but it is still acceptable.
In example 1, however, the compiler produces three times the number of assembly instructions compared to the expected code.
Am I doing something wrong ?
Are there any guidelines for writing C code so that the assembly code produced by the compiler is efficient?

Thank you!
Good afternoon