Keil Logo

C51: Preventing Common Block Optimization


Information in this article applies to:

  • C51 Version 6 and later

QUESTION

We have written a custom implementation of the setjmp function to solve some problems in our application. We are also using the highest optimization level with Linker Code Packing and we have a problem. The compiler and linker optimize the setjmp function calls and this causes problems for our application.

Is there a way to exclude a part of our code from optimization?

ANSWER

Yes. You may specify a different optimization level for the routine that contains the setjmp call. For example:

#pragma SAVE           // save current optimization level
#pragma OPTIMIZE(7)    // disable function block optimization
void func (void)  {

}
#pragma RESTORE        // restore original optimization level

The SAVE and OPTIMIZE pragmas save the current configuration and change the optimizer level to 7. The RESTORE pragma restores the previous optimizer level. Use these around your functions that use setjmp and common block subroutine optimization will be disabled (for these functions).

Note: It is not enough to reduce the optimization level to 8, since the compiler (or linker) would still combine code sections with other functions that are translated with optimize level 9 or higher.

MORE INFORMATION

  • Refer to SAVE in the Cx51 User's Guide.
  • Refer to RESTORE in the Cx51 User's Guide.
  • Refer to OPTIMIZE in the Cx51 User's Guide.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.