OK, I'm really hoping someone can see why the TI MSP430 C compiler is producing such terrible code, even with full optimizations and speed tradeoffs turned all the way up.
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).
The code above just seems so obviously bad that I'm hoping I'm missing something...