Im doing the optimization in the C code running in the Cortex-R4. first of all I haven't seen any change in the assembly code output when I indicated the "__builtin_expect" in condition check. It seem like the compiler generate the unnecessary Jump.
My C code:
bit ++; (Likely)
if(__builtin_expect(bit >= 32),0)
{
bit -=32; // unlikely code
xxxxxx; // unlikely code
xxxxxx; // unlikely code
xxxxxx; // unlikely code
}
bit = bit*2 // something (Likely)
return bit;
---- Generated ASM code -------- (bit => r0)
ADD r2,r2,#1
CMP r0,#0x20
BCC NoDecrement
SUB r0,r0,#0x20
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
NoDecrement LSL r0,r0,#1
BX lr
---- My expected ASM Code --------
ADD r2,r2,#1
CMP r0,#0x20
BHE Decrement
JumbBack LSL r0,r0,#1
BX lr
Decrement SUB r0,r0,#0x20
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
B JumbBack
suppose if this piece of C code runs in a loop, then each time it has to jump (because the if condition is passed only once). Is there any other compiler setting which actually, generates the code as expected..??