Hardware Reference
In-Depth Information
FIGURE A.17 Frequency of different types of compares in conditional branches . Less
than (or equal) branches dominate this combination of compiler and architecture. These
measurements include both the integer and floating-point compares in branches. The pro-
grams and computer used to collect these statistics are the same as those in Figure A.8 .
Procedure Invocation Options
Procedure calls and returns include control transfer and possibly some state saving; at a min-
imum the return address must be saved somewhere, sometimes in a special link register or
just a GPR. Some older architectures provide a mechanism to save many registers, while new-
er architectures require the compiler to generate stores and loads for each register saved and
restored.
There are two basic conventions in use to save registers: either at the call site or inside the
procedure being called. Caller saving means that the calling procedure must save the registers
that it wants preserved for access after the call, and thus the called procedure need not worry
about registers. Callee saving is the opposite: the called procedure must save the registers it
wants to use, leaving the caller unrestrained. There are times when caller save must be used
because of access paterns to globally visible variables in two diferent procedures. For ex-
ample, suppose we have a procedure P1 that calls procedure P2, and both procedures manip-
ulate the global variable x . If P1 had allocated x to a register, it must be sure to save x to a
location known by P2 before the call to P2. A compiler's ability to discover when a called pro-
cedure may access register-allocated quantities is complicated by the possibility of separate
compilation. Suppose P2 may not touch x but can call another procedure, P3, that may access
x , yet P2 and P3 are compiled separately. Because of these complications, most compilers will
conservatively caller save any variable that may be accessed during a call.
In the cases where either convention could be used, some programs will be more optimal
with callee save and some will be more optimal with caller save. As a result, most real systems
 
Search WWH ::




Custom Search