19.2 How to Enable Optimization

MPLAB XC-DSC is derived from the GCC source-base which provides many different individual switches for controlling optimizations.

It is recommended that you use the 'big O' optimization switches. The more common variants of GCC (Arm, MIPS, ix86, etc.) may update optimization switches more quickly than the dsPIC port, so consequently there may be individual switches that appear and disappear. Sticking with the big O optimizations is a good way to remove surprises.

The big O optimizations are organized into four categories, declared using the -On option, where n is a numerical value in the range of 0 to 3. Additionally, there is the -Os option, which falls somewhere between -O2 and -O3. For optimizations supported in Free (unlicensed) compilers and additional options supported in PRO (licensed) compiler, see 19 Optimizations.

In general, the larger the value of n, the more optimizations are performed. Some techniques are designed to reduce code size, some are designed to increase the performance of the generated code, and some do both. You will need to determine what is most important for you (speed vs. size trade-offs) and choose the option appropriate for your application.

MPLAB XC-DSC also supports procedural abstraction, sometimes called function-outlining, via the -mpa option. This optimization intends to reduce the code size by abstracting common generated code into individual functions (i.e., the opposite of function inlining). This can reduce code size and is performed on assembly code, post compilation.

Additionally MPLAB XC-DSC supports -moptimize-page-setting which attempts to minimize the effect of DSRPAG swapping with the named address space qualifiers.