3-28
C Cross Compiler
3.9.6 Optimization of Inline Assembly
For purposes of optimization, the compiler assumes that inline assembly
has no effect except to modify the output variables. Thus inline assembly
can be removed by optimization if none of the output variables is
subsequently used. Inline assembly that must not be deleted or
significantly moved should contain the keyword
volatile
following the
asm
directive, as shown below.
asm volatile(“bits %smode, 7”);
The
volatile
keyword is implicit for inline assembly with no output
variables. Thus, the use of
volatile
in the above example is redundant.
3.10 Assembly Optimizer and Handwritten Assembly
The assembly optimizers can be used to automatically generate the
prologue and epilogue for an assembly function and then to schedule the
entire function.
sdopt -asm
assemblyfile
The output will be placed in standard output. The assembly optimizers
expect input of the following format:
!PROLOGUE(<
function name
>)
<
function body
>
!EPILOGUE
This will be transformed by the assembly optimizer to:
.set
<
function name
>:
__FUNC_START_<
function name
>:
<
optimized assembly code with prologue/epilogue
>
__FUNC_END_<
function name
>:
ret
REGSAVE_SIZE_<
function name
> <
stack space used
>
All registers that must be preserved according to the C calling convention
will be preserved. Note that the name
REGSAVE_SIZE_<
function
name
>
can be used if the size of the stack space used by the
prologue/epilogue is needed. Any input in the assembly file outside of the