Chapter 4 Optimization

Optimization of function calls

This section describes the optimization of function calls by the linker.

The assembler provides advanced processing for function calls. This processing uses a combination of the call and ret instructions and the global and funcinfo directives. The following is an example.

 

global

_0func

 

_TEXT

section

CODE, PUBLIC, 1

 

 

:

 

 

 

call

_0func

(1)

 

:

 

 

 

global

_0func, _func

 

_TEXT

section

CODE, PUBLIC, 1

 

_func

movm

[D2], (SP)

(2)

 

 

add

-4, SP

 

_0func

funcinfo

_func, 8, [D2]

 

 

:

 

 

 

:

 

(3)

 

ret

 

 

(1)gives the call to the function _0func. (3) is the body of the function. (2) the section between the labels _func and _0func, saves a register and sets up the stack frame.

When this source file is assembled and linked, the linker eliminates section (2). This section is preserved when the symbol _func is referred.

For further details on machine instructions and directives, see the Instruction Manual and Section 9.4 "Writing Directives."

NOTE:

This optimization of function calls is always carried out regardless of the state of

 

 

the optimization option (-O). It is suppressed throughout if even one of the source

 

 

files to be linked contains a calls instruction with the operand (An).

 

 

 

Usage Example 51

Page 63
Image 63
Panasonic MN1030 user manual Optimization of function calls