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

Selectively disable optimization on macro?

I have a macro:

#define EnterCritical()
  do {     SP++;     *(unsigned char idata *)(SP-1) = IE;     EA = 0;   } while (0);

that I call multiple times (along with its complement, ExitCritical()) in a particular function. With C51's optimization level set at 9, the optimizer is turning these in-line macros into a function and calling them -- this obviously won't work, due to the operations on SP.

Is there a way for me to maintain the OPTIMIZE(9,SIZE) settings for the module but ensure that the macro is left in its original in-line state whenever I invoke it?

Thanks,

Parents
  • Hi Andrew.

    Well, the problem is that I really need the SIZE optimization for the rest of the code, and I just need the SPEED optimization around this macro.

    Unfortunately, I don't think I can combine the two, since I can't automatically place the SAVE and RESTORE pragmas "inside" the EnterCritical() macro.

    Placing the pragmas directly inside my source code (e.g. in the affected function) is not an option. Since pragmas are compiler-specific, one can't pepper one's code with, say, Keil C51 pragmas and expect it to compile under, say, CodeWarrior, too (I'm talking cross-platform testing, etc.). And you can't put a pragma inside a macro ...

    Andrew

Reply
  • Hi Andrew.

    Well, the problem is that I really need the SIZE optimization for the rest of the code, and I just need the SPEED optimization around this macro.

    Unfortunately, I don't think I can combine the two, since I can't automatically place the SAVE and RESTORE pragmas "inside" the EnterCritical() macro.

    Placing the pragmas directly inside my source code (e.g. in the affected function) is not an option. Since pragmas are compiler-specific, one can't pepper one's code with, say, Keil C51 pragmas and expect it to compile under, say, CodeWarrior, too (I'm talking cross-platform testing, etc.). And you can't put a pragma inside a macro ...

    Andrew

Children
No data