
111
Chapter 2 Applications Programming
The compiler typically allocates about 12 registers for use by each new
procedure. However, a very large procedure could be allocated up to 128 registers.
This requires the register–stack cache be assigned the maximum window size of 128
registers. The “l(fā)regs=n” compiler switch (minimum n=36) enables the maximum
number of registers allocated to a procedure to be limited to less than 128. If the
“l(fā)regs” switch is used, it is possible to operate with a reduced window size. This
would increase the frequency of stack spilling and filling (and hence reduce effective
execution speeds) but would enable a faster task context switch time (see section
8.1.4). The maximum number of local registers which would require saving or
restoring would be limited to the reduced window size (window size =
rfb
–
rab
).
A number of the example code sequences shown in this book, and provided by
AMD, are configured to operate with a fixed window size of 512 bytes; in particular,
repair_R_stack
in file signal.s and
signal_associate
in file sig_code.s. These files
should be modified to reflect the reduced window size. Ideally a Supervisor mode
accessible memory location, say
WindowSize
, should be initialized by the operating
system to the chosen window size, and all subsequent code should access
WindowSize
to determine the window size in use. Additionally, the spill handler
routine must be replace with the code shown below. The replacement handler
requires three additional instructions. But, unlike the more frequently used spill
handler (section 4.4.4), it is not restricted to operating with a fixed window size of
512 bytes.
spill_handler:
sub
srl
sub
mtsr
sub
const
or
mtsr
add
storem
jmpi
add
tav,rab,rsp
gr96,tav,0x2
gr96,gr96,0x1
cr,gr96
tav,rfb,tav
gr96,0x200
gr96,tav,gr96
ipa,gr96
rab,rsp,0x0
0,0x0,gr0,tav
tpc
rfb,tav,0x0
;calculate size of spill
;number of words
;determine new rfb position
;point into register file
;adjust rab position
;move data
;adjust rfb position
The above spill handler code may fail if there is a procedure which does not use
the
gr96
register. The compiler may hold a value in
gr96
and expect it to survive the
function call; and the function call may result in spill handler execution. This is not
likely, but the use of
gr96
above must be done with care.
A number of non–standard C features have been added to the compiler. These
features are often useful, but their use reduces the portability of code between
different C compilers. For example, the High C 29K compiler does not normally pack
data structures. The type modifier
_Packed
can be used to specify packing on a
per–structure bases. If structure packing is selected on the compiler command line,