I am currently developing on the TMS320F28377DPTPT Rev C processor. I have recently updated to the 15.12.3 LTS compiler. I am using CSS v6.1.3.
I have been struggling with some strange behaviour of the compiler optimiser. I am using level 0 register level optimisation.
My original code was:
1:if(a < 0)
2:{
3: /*Do nothing*/
4:}
5:else
6:{
7: a = -a;
8:{
I originally wrote the code in this way as I planned to fill the /*do nothing*/ condition at a later date and it would be executed more often so I placed it first.
The problem is that when I have optimisation turned on, the assembly is not generated correctly.
Line 7 becomes:
MOVB XAR0,#22 ; [CPU_] |964|
MOVB XAR1,#22 ; [CPU_] |964|
MOV32 R0H,*+XAR2[AR0] ; [CPU_] |964|
MAXF32 R0H,#0 ; [CPU_] |964|
MOV32 *+XAR2[AR1],R0H ; [CPU_] |964|
I don't know why the MAXF32 function is being used in this instance. It does not negate my value but simply sets it to 0.
In order to fix the problem I used the following code instead:
1:if(a > 0)
2:{
3: a = -a;
4:}
The assembly of line 3 now becomes:
MOVB XAR0,#22 ; [CPU_] |960|
MOVB XAR1,#22 ; [CPU_] |960|
MOV32 R0H,*+XAR2[AR0] ; [CPU_] |960|
NEGF32 R0H,R0H ; [CPU_] |960|
MOV32 *+XAR2[AR1],R0H ; [CPU_] |960|
The NEGF32 instruction now performs the negation as expected.
Do you know what might be wrong with the original code that confused the compiler? As far as I can see, even if the code is inefficient it should not change the result of the operation on line 7/3.