Hi Everyone,
I'm using C251 compiler with optimization level 9 with 'size' emphasis. I've a function similar to one given below.
int * fun(short* param1, Boolean param2){
//..........code goes here } This function is being called as fun(someValue,TRUE) or fun(someValue, FALSE) across the souce code. I tried to replace these calls with the help of two new functions that knows beforehand second argument. This change was based on calling convention used by C251. I assumed that C251 passes parameters similarly as C51,i.e. by using registers and memory locations (hence boolean parameter need not be passed at all).
Warpper functions are given below. int * funTRUE(short* param){
return fun(param,TRUE); }
int * funFALSE(short* param){
return fun(param,FALSE); } After this change code size has increased by around 3K rather than went down. Replacement are around 20 so we can not say that code of wrapper functions have added to increase in the code size more than reduction due to call replacements with calls to wrapper functions. How can I've more insight in this phenomenon?
It is generally the case that the effect of optimisers does depend on the nature of the code being optimised.
You appear to have found one of those cases where the difference is significant!
It might even be a direct bug in the optimizer, making it skipping an important optimization because your code no longer matches existing optimization rules and the rule list is missing some reasonable rules.
It might be an idea to try to create as small program as possible that gives this problem and then contact Keil.
I've implemented a small project keeping identical project settings e.g. Memory Model, optimization level etc and I can see wrapping methods, as I explained in opening of thread, gives code size benefits so we can not directly blame the optimizer.