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.

Opportunity for another msp430 optimization

Dear Compiler Wizards,

   Using CCS Version: 5.1.0.09000 I wrote the following C++ code:


#include <stdint.h>
static inline void delay (void)

{
uint16_t Count = 28;
while (Count--) {
asm (" nop");
}
}


extern void DemoFunc (uint16_t spectrum_count, uint32_t * detector_Data)
{
uint32_t * pAccum;
uint16_t Index;
uint16_t Datum;

while (spectrum_count--) {
pAccum = detector_Data;
Index = 220u;
while (P2IN & 0x02u) ; /* Wait for start conversion */
while ((P2IN & 0x02u)== 0) ; /* Wait for conversion complete */
while (Index--) {
Datum = _swap_bytes(P4IN) + static_cast<uint16_t>(P5IN);
*pAccum++ += static_cast<uint32_t>(Datum);
}
delay ();
}
}

and then compiled it with MSP430 C/C++ Codegen  PC v4.0.0, with optimization set to 4,
and got the following code for the line: *pAccum++ += static_cast<uint32_t>(Datum);

 ;** 518 ----------------------- *pAccum++ += Datum;
.dwpsn file "../CmdProcess.cpp",line 518,column 4,is_stmt
000024 522A ADD.W #4,r10 ; [] |518|
000026 0ACF MOVA r10,r15 ; [] |518|
000028 822F SUB.W #4,r15 ; [] |518|
00002a 5E8F ADD.W r14,0(r15) ; [] |518|
00002c 0000
00002e 638F ADDC.W #0,2(r15) ; [] |518|
000030 0002
I would have expected either this code:

         MOVA   r10,r15     ; tmp <- pAccum
    ADD.W  #4,r10      ; pAccum++
    ADD.W  r14,0(r15)  ; *tmp += Datum
    ADDC.W #0,2(r15) 

or, even better:

    ADD.W  r14,0(r10) ; *pAccum += Datum
    ADDC.W #0,2(r10)
    ADD.W  #4,r10       ; pAccum++

Curiously, the same code is generated if I write:

    *pAccum += Datum;
    pAccum++; 

Regards,

Fred