Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual
Product codes
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 268
2012 Microchip Technology Inc.
6.5
ASSEMBLY-LEVEL OPTIMIZATIONS
The assembler performs optimizations on assembly code in addition to those
optimizations performed by the code generator directly on the C code, see
Section 5.13 “Optimizations”.
optimizations performed by the code generator directly on the C code, see
Section 5.13 “Optimizations”.
The xc8 driver by default instructs the assembler to optimizer assembly code that is
generated from C code, but to not perform optimizations on hand-written assembly
source modules. The latter code can be optimized if required, see
Section 4.8.42 “--OPT: Invoke Compiler Optimizations”. Assembly which is added
in-line (see Section 5.12.2 “#asm, #endasm and asm()”) with C code is never
optimized.
generated from C code, but to not perform optimizations on hand-written assembly
source modules. The latter code can be optimized if required, see
Section 4.8.42 “--OPT: Invoke Compiler Optimizations”. Assembly which is added
in-line (see Section 5.12.2 “#asm, #endasm and asm()”) with C code is never
optimized.
The optimizations that can be performed by the assembler include the following.
In-lining of small routines so that a call to that routine is not required. Only very
small routines (typically a few instructions) will be changed so that code size
is not impacted. This will speed code execution, without a significant
increase in code size.
is not impacted. This will speed code execution, without a significant
increase in code size.
Procedural abstraction is performed on assembly code sequences that appear
more than once. This is essentially a reverse in-lining process. The code se-
quence is abstracted into a callable routines will use a label, PLx, where x is
a number, and a call to this routine will replace every instance of the original
code sequence. This will reduce code size considerable, which a small
impact on code speed.
quence is abstracted into a callable routines will use a label, PLx, where x is
a number, and a call to this routine will replace every instance of the original
code sequence. This will reduce code size considerable, which a small
impact on code speed.
Jump-to-jump type optimizations are made, primarily to tidy the output related to
conditional code sequences that follow a generic template and which can
leave jump instructions that jump to other jump instructions.
leave jump instructions that jump to other jump instructions.
Unreachable code is removed. Code may become orphaned by other optimizations
and cannot be reached during normal execution, e.g., instructions after a re-
turn instruction. The presence of any label is considered a possible entry
point and code following a label is always considered reachable.
turn instruction. The presence of any label is considered a possible entry
point and code following a label is always considered reachable.
Peephole optimizations are performed on every instruction. These optimizations
consider the state of execution at, and immediately around, each instruction
– hence the name. They either alter or delete one or more instructions at
each step. For example, if W is known to contain the value 0, and an instruc-
tion moves W to an address (MOVWF), this might be replaceable with a CLRF
instruction.
– hence the name. They either alter or delete one or more instructions at
each step. For example, if W is known to contain the value 0, and an instruc-
tion moves W to an address (MOVWF), this might be replaceable with a CLRF
instruction.
Psect merging may be performed to allow other optimizations to take place. Code
within the same psect is guaranteed to be located in the same program
memory page, and so calls and jumps within the psect do not need to have
the page selection bits set before executing. Code using the LJMP and
FCALL
memory page, and so calls and jumps within the psect do not need to have
the page selection bits set before executing. Code using the LJMP and
FCALL
instructions will benefit from this optimization, see
Assembly optimizations can often interfere with debugging in tools such as MPLAB IDE
and it may be necessary to disable them when debugging code, if possible, see
Section 4.8.42 “--OPT: Invoke Compiler Optimizations”. The assembler optimiza-
tions can drastically reduce code size, although typically have little effect on RAM
usage.
and it may be necessary to disable them when debugging code, if possible, see
Section 4.8.42 “--OPT: Invoke Compiler Optimizations”. The assembler optimiza-
tions can drastically reduce code size, although typically have little effect on RAM
usage.