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.
I posted this over on the msp430 forum ( here ) and no one seemed to see that I was missing anything on the MSP430 side, so I'm hoping someone can figure out why the TI C-compiler can't figure this out:
The function is this:
inline void msp430_softuart_tx(uint8_t txc) { softuart_tx_process_buffer[softuart_tx_process_buffer_write_ptr++] = txc; softuart_tx_process_buffer_write_ptr = softuart_tx_process_buffer_write_ptr % MSP430_SOFTUART_TX_PROCESS_BUFFER_SIZE; }
and MSP430_SOFTUART_TX_PROCESS_BUFFER_SIZE is 128. When this is called with msp430_softuart_tx(0x48), I get the bizarre:
MOV.B &softuart_tx_process_buffer_write_ptr,R15 MOV.B #0x0048,0x0200(R15) MOV.W #1,R15 ADD.B &softuart_tx_process_buffer_write_ptr,R15 AND.B #0x007f,R15 MOV.B R15,&softuart_tx_process_buffer_write_ptr
???? As far as I can see MOV.W #1, R15 and the ADD.B lines are entirely pointless. It could've just done
MOV.B &softuart_tx_process_buffer_write_ptr,R15 MOV.B #0x0048,0x0200(R15) INC.B R15 AND.B #0x007F, R15 MOV.B R15,&softuart_tx_process_buffer_write_ptr
which is both 2 words shorter and 3 cycles faster.
Is there something I'm missing here? I would love to just write the code in assembly straight off, but I've never been able to find a way to make the TI C-compiler inline an assembly function (removing the call/ret and optimizing the parameter load).
GCC doesn't do this: it generates the second code. The write ptr (softuart_tx_process_buffer_write_ptr) isn't declared volatile, or anything weird - it's just a normal uint8_t.
Honestly I have no idea why the compiler isn't optimizing this. Any ideas?
Thank you for submitting a test case. I can reproduce these results. I filed SDSCM00051208 in the SDOWP system to have this performance inefficiency investigated. Feel free to follow it with the SDOWP link below in my signature.
Thanks and regards,
-George