Here is the code snippet -
container.slice++
if(container.slice == NR_SLICE_INSLOT)
{
container.slice = 0;
container.slot++;
if(container.slot == NR_SLOT_INFRAME)
{
container.slot = 0;
container.box++; // Line1
if(container.box == NR_FRAME_OF_BOX) // Line2
{
container.box=0;
}
}
}
Its corresponding (code after "container.slot = 0;") assembly generated -
STB .D1T1 A6,*A3 ; |2072|
LDHU .D1T1 *A4,A3 ; |2073|
NOP 4
ADD .D1 1,A3,A3 ; |2073|
STH .D1T1 A3,*A5 ; |2073|
LDHU .D2T2 *B4,B5 ; |2074|
MVKL .S2 _container,B4 ; |2076|
MVKH .S2 _container,B4 ; |2076|
NOP 2
ZERO .D2 B5
|| CMPEQ .L2 B5,B6,B0 ; |2074|
[ B0] STH .D2T2 B5,*B4 ; |2076|
Same variable is being used in Line1 and Line2. Due to pipeline when Line1 is still executing, Line2 code will do fetch and hence will load previous value.
Am I correct here?
Hence some kind of memory barrier is required between these two lines so that barrier makes sure that all instructions completes all the pipeline stages before next instruction starts executing.
As C code is compiled with o3 optimization for speed so fix in assembly is not the solution.
I guess this is a very basic kind of problem and will have a well defined solution but I am unaware of it.
Please help or give some clue or pointer to lookupon.
Regards,
Shreshtha