XGATE compiler from CW for S12(X) V5 with 5.01 patch seems being fine with this
char cc;
ring_buffer.data[ring_buffer.in] = cc;
or
cc = ring_buffer.data[ring_buffer.in];
If upgrading is not an option for now, then try playing with compiler settings. Disabling all or some optimizations may help.
You say
- but since timing is critical i cant afford the extra operation.
At least latest XGATE compiler is able to keep local variables in registers and eliminate some intermediate operations.
If you are worrying about timing, then you should reference your data (data structure) via pointer that could be passed as a XGATE thread argument, which is passed in R1 register. I mean doing it the same like it is done in CW wizard generated project, see how MyData struct is passed to SoftwareTrigger0_Handler(). In your case if would like as this
1) data structure is passed in R1 register to XGATE
interrupt void thr(rBuffer * __restrict rb) {
cc = rb->data[rb->in];
}
2) R1 register is initialized in XGATE vector table like this:
{ErrorHandler, 0x36}, // Channel 36 - XGATE Software Trigger 3
{ErrorHandler, 0x37}, // Channel 37 - XGATE Software Trigger 2
.....
{(XGATE_Function)thr, (int)&ring_buffer}, // <----- pointer to ring_buffer will be loaded to R1 before thr thread call