Tool/software: TI C/C++ Compiler
I am having some C compiler optimization issues.
I am using Code Composer Studio Version: 7.0.0.00022
ARM Compiler Tools 16.9.0.LTS com.ti.cgt.tms470.15.win32.feature.group Texas Instruments
Here is the source code:
typedef uint64_t RF_EventMask;
#define RF_EventLastCmdDone (1<<1)
#define RF_EventRxEntryDone (1<<23)
#pragma FUNCTION_OPTIONS(ull_scanDoneCb, "--opt_level=1")
void ull_scanDoneCb(RF_Handle rfHandle, RF_CmdHandle cmdHandle, RF_EventMask events)
{
if (events & RF_EventRxEntryDone)
{
/* Radio has received a packet */
uble_buildAndPostEvt(UB_EVTDST_LL, ULL_EVT_SCAN_RX_SUCCESS, NULL, 0);
}
else if (events & RF_EventLastCmdDone)
{
...
The "events" should be either "RF_EventRxEntryDone" (0x00800000) or "RF_EventLastCmdDone | RF_EventRxEntryDone" (0x00800002) when the callback is called from SWI.
Here is the assembly for opt_level=0:
519 {
ull_scanDoneCb():
00006f6c: B580 push {r7, lr}
00006f6e: 4618 mov r0, r3
524 if (events & RF_EventRxEntryDone)
00006f70: F44F0100 mov.w r1, #0x800000
00006f74: 2300 movs r3, #0
00006f76: 4011 ands r1, r2
00006f78: EA030700 and.w r7, r3, r0
00006f7c: 2F00 cmp r7, #0
00006f7e: D100 bne $C$L7
00006f80: 2900 cmp r1, #0
$C$L7:
00006f82: D123 bne $C$L10
532 else if (events & RF_EventLastCmdDone)
When "opt_level=0", the code branches to $C$L10 as expected. R2 is either 0x00800000 or 0x00800002 before ull_scanDoneCb() is called.
Here is the assembly for opt_level=1:
519 {
ull_scanDoneCb():
00006d84: 4618 mov r0, r3
524 if (events & RF_EventRxEntryDone)
00006d86: F44F0100 mov.w r1, #0x800000
00006d8a: B580 push {r7, lr}
00006d8c: 2300 movs r3, #0
00006d8e: 4011 ands r1, r2
00006d90: EA030700 and.w r7, r3, r0
00006d94: 2F00 cmp r7, #0
00006d96: D100 bne $C$L7
00006d98: 2900 cmp r1, #0
$C$L7:
00006d9a: D123 bne $C$L10
532 else if (events & RF_EventLastCmdDone)
When "opt_level=1", it is not branched to $C$L10. Strangely, R2 is always 0x00000002 before ull_scanDoneCb() is called.
Setting the function level optimization seems to populate R2 differently before the function is called. Note that the same code without the #pragma works well in IAR (also in highest optimization setting). Let me know if you need any more info on this. Please advise ASAP.