Grouping Related Routines [ HP FORTRAN 77/iX Programmer's Guide ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Programmer's Guide
Grouping Related Routines
To understand how a program uses memory, you need to know how these areas
are mapped into the physical segments of the 900 Series HP 3000 computer.
The main memory is divided into page frames of a fixed size, each of
which can contain one virtual page. Data flow between main memory and
external storage occurs in units of pages; the page size is 4K bytes.
The stack and data areas belong to a separate virtual space from the code
area. The maximum size of each virtual space is 232 bytes, but the code,
data, and stack areas only use one-fourth of the space. Therefore, the
maximum size of the code area is 230 bytes and the maximum size of the
stack and data area combined is 230 bytes.
You can make programs more efficient by grouping routines that frequently
call each other. Fitting routines into a page boundary eliminates page
faults that might otherwise occur. (Grouping data that is frequently
used also lessens the possibility of a page fault.) Group routines using
the LOCALITY compiler directive (refer to the HP FORTRAN 77/iX Reference
for more information about this directive). When you use the LOCALITY
directive in routines with the same locality name, the compiler arranges
the routines next to each other in the code space. Specifying a locality
name for block data subprograms that contain common blocks also causes
the compiler to place common blocks having the same locality name next to
each other. Therefore, if the common blocks fit into one page, all page
faults are eliminated when accessing data within the blocks.
Besides limiting page size, the following are additional reasons to group
related routines:
1. On the 900 Series HP 3000 computer, which is equipped with a cache
memory, careful segmentation of code and data eliminates
unnecessary cache misses. Because one cache miss is equivalent to
at least two instruction cycles, a significant improvement is
achieved by rearranging code and data. * Grouping related
routines or data avoids long branching. On the 900 Series HP 3000
computer, the maximum distance of a branch is 64K instructions.
If a routine calls another routine that is further than 64K
instructions away, a long branch stub is generated within the 64K
limit. The long branch stub serves as a transit routine, which in
turn calls the target routine.
If subroutines or functions are randomly scattered in a large
program, long branch stubs are likely to be generated. However,
by grouping related routines with the LOCALITY directive, you can
eliminate most long branchings. * The 900 Series HP 3000 computer
references data through the dp (data pointer) and sp (stack
pointer) base registers. The range that the computer can reach is
from dp-8K to dp+8K and from sp-8K to sp+8K, respectively. If the
data used by the current program is larger than 16K, the compiler
has to switch the dp or sp base registers to access data in
different 16K segments. For example, if a is in location 0 while
b is in location 16K+1 and the code states
DO i = 1,10
a(i) = b(i)
the compiler must switch dp to point to 16K to load the value of
b. The compiler then must switch back to 0 to store to a(i).
Grouping a and b could place b within the 16K range and eliminate
the base register switching.
MPE/iX 5.0 Documentation