My target is an MC9S08QG8 an I'm wondering why incrementing a 32 bit integer is so expensive.
All measurements were done in the simulator.
Counter++; // this line will take about 156 CPU cycles!
So incrementing Counter will take about 156 CPU cycles which is MUCH more than incrementing a 16 bit integer. It's clear that incrementing a 32 bit integer is more effort than a 16 bit integer but the following is still much faster:
// this function takes 37 CPU cycles
void IncUINT32(UINT32 * li)
if (!((UINT16 *)li))
// This macro takes only 18 CPU cycles but it does not fit in every situation, e.g. for loops
#define INC2_LI(li) ((UINT16 *)&li)++; if (!((UINT16 *)&li)) ((UINT16 *)&li)++;
So, any idea why the compiler produces so slow code with the ++ operator? In the debugger I see that the function "_LINC" is called in RTSHC08.c.