This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Optimization behavour: C51, uVision4

Hi all,

I tried compiling some sanity-checking example code on an evaluation copy I installed today and got some unexpected results; seemingly no matter what I set the code optimization level to (using the C51 tab in the Options for Target dialog) I get very little optimization in the object code - less than I'd expect, anyhow.

The code I've been testing with is as follows:

static res;

void unused()
{
        res = 2 * 2;
}

int main()
{
        int i =2 , j=3, k=4;

        i *=i * i;

        k = (j * j) * (j * j) * i;

        res = k;

        return k;
}

I expected this to basically optimize away to simply MOV a constant into place. Also, I expected the unused function to be eliminated. I'm not generally seeing this - the unused function is present when I view the assembly output in the debugger. There are multiplies still in the code, although it might have elimated one or two of them.

Am I missing something here? Changing the optimization level does seem to have some effect on the size of the binary produced, so it's doing something. Are there more switches somewhere I need to flip?

0